spa: add Capability and PeerCapability

Add a new SPA_TYPE_OBJECT_ParamDict object that contains a struct with
key/value pairs. We're using something similar for Tags but this is a
more generic version.

Make a new Capability param that uses the ParamDict object. This is
meant to be used to describe capabilities with the generic key/value
struct.

Make a new PeerParam object where the keys are generic ids of the peer
objects and the values any Pod. The idea is to use this object to store
a peer objects. Make some helpers to iterate the peers and their
objects.

Add a new PeerCapability param that uses the PeerParam object with
Capability objects. This can be used to send the collection of
Capabilities from all peers to a port. This is a bit like the tags but
in a more generic way. The tags could also be implemented in this new
generic way later.

Make the PeerFormats use the same PeerParam of Format objects.

The Capability param is set on ports. impl-link will collect all
Capability objects into a PeerCapability object and send this to the
peer. The difference with the Tag param is that these Capability params
are not in any way forwared on the node automatically (like what is done
in the loopback module) because they represent the capabilities of the
ports betweem the link.
This commit is contained in:
Wim Taymans 2025-11-14 10:34:49 +01:00
parent 8d59ad2713
commit 941fc5f51c
22 changed files with 635 additions and 47 deletions

View file

@ -15,6 +15,8 @@
#include <spa/utils/result.h>
#include <spa/param/video/format-utils.h>
#include <spa/param/tag-utils.h>
#include <spa/param/dict-utils.h>
#include <spa/param/peer-utils.h>
#include <spa/param/props.h>
#include <spa/param/latency-utils.h>
#include <spa/debug/format.h>
@ -270,6 +272,33 @@ on_stream_io_changed(void *_data, uint32_t id, void *area, uint32_t size)
}
}
static void parse_peer_capability(struct data *data, const struct spa_pod *param)
{
struct spa_peer_param_info info;
void *state = NULL;
while (spa_peer_param_parse(param, &info, sizeof(info), &state) == 1) {
struct spa_param_dict_info di;
if (spa_param_dict_parse(info.param, &di, sizeof(di)) > 0) {
struct spa_dict dict;
struct spa_dict_item *items;
const struct spa_dict_item *it;
if (spa_param_dict_info_parse(&di, sizeof(di), &dict, NULL) < 0)
return;
items = alloca(sizeof(struct spa_dict_item) * dict.n_items);
if (spa_param_dict_info_parse(&di, sizeof(di), &dict, items) < 0)
return;
spa_dict_for_each(it, &dict)
fprintf(stderr, "peer:%u %s: %s\n", info.peer_id, it->key, it->value);
}
}
}
/* Be notified when the stream param changes. We're only looking at the
* format changes.
*
@ -294,8 +323,11 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param)
void *d;
int32_t mult, size, blocks;
if (param != NULL && id == SPA_PARAM_Tag) {
spa_debug_pod(0, NULL, param);
if (param != NULL && (id == SPA_PARAM_Tag || id == SPA_PARAM_PeerCapability)) {
if (id == SPA_PARAM_PeerCapability)
parse_peer_capability(data, param);
else
spa_debug_pod(0, NULL, param);
return;
}
if (param != NULL && id == SPA_PARAM_Latency) {

View file

@ -15,6 +15,7 @@
#include <spa/param/video/format-utils.h>
#include <spa/param/tag-utils.h>
#include <spa/param/dict-utils.h>
#include <spa/debug/pod.h>
#include <spa/debug/format.h>
@ -219,7 +220,7 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param)
const struct spa_pod *params[5];
uint32_t n_params = 0;
if (param != NULL && id == SPA_PARAM_Tag) {
if (param != NULL && (id == SPA_PARAM_Tag || id == SPA_PARAM_PeerCapability)) {
spa_debug_pod(0, NULL, param);
return;
}
@ -290,7 +291,8 @@ static void do_quit(void *userdata, int signal_number)
int main(int argc, char *argv[])
{
struct data data = { 0, };
const struct spa_pod *params[2];
const struct spa_pod *params[3];
uint32_t n_params = 0;
uint8_t buffer[1024];
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer));
@ -318,7 +320,7 @@ int main(int argc, char *argv[])
PW_KEY_NODE_SUPPORTS_REQUEST, "1",
NULL));
params[0] = spa_pod_builder_add_object(&b,
params[n_params++] = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_video),
SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw),
@ -336,7 +338,13 @@ int main(int argc, char *argv[])
spa_tag_build_add_dict(&b,
&SPA_DICT_ITEMS(
SPA_DICT_ITEM("my-tag-key", "my-special-tag-value")));
params[1] = spa_tag_build_end(&b, &f);
params[n_params++] = spa_tag_build_end(&b, &f);
}
{
params[n_params++] = spa_param_dict_build_dict(&b, SPA_PARAM_Capability,
&SPA_DICT_ITEMS(
SPA_DICT_ITEM("my-capability-key", "my-capability-value")));
}
pw_stream_add_listener(data.stream,
@ -349,7 +357,7 @@ int main(int argc, char *argv[])
PW_ID_ANY,
PW_STREAM_FLAG_DRIVER |
PW_STREAM_FLAG_MAP_BUFFERS,
params, 2);
params, n_params);
pw_main_loop_run(data.loop);