mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-25 06:59:57 -05:00
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:
parent
8d59ad2713
commit
941fc5f51c
22 changed files with 635 additions and 47 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -924,6 +924,7 @@ static void input_remove(struct pw_impl_link *this)
|
|||
spa_list_remove(&this->input_link);
|
||||
pw_impl_port_emit_link_removed(port, this);
|
||||
|
||||
pw_impl_port_recalc_capability(port);
|
||||
pw_impl_port_recalc_latency(port);
|
||||
pw_impl_port_recalc_tag(port);
|
||||
|
||||
|
|
@ -956,6 +957,7 @@ static void output_remove(struct pw_impl_link *this)
|
|||
spa_list_remove(&this->output_link);
|
||||
pw_impl_port_emit_link_removed(port, this);
|
||||
|
||||
pw_impl_port_recalc_capability(port);
|
||||
pw_impl_port_recalc_latency(port);
|
||||
pw_impl_port_recalc_tag(port);
|
||||
|
||||
|
|
@ -1138,6 +1140,14 @@ static void input_port_tag_changed(void *data)
|
|||
pw_impl_port_recalc_tag(this->output);
|
||||
}
|
||||
|
||||
static void input_port_capability_changed(void *data)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
struct pw_impl_link *this = &impl->this;
|
||||
if (!this->feedback)
|
||||
pw_impl_port_recalc_capability(this->output);
|
||||
}
|
||||
|
||||
static void output_port_latency_changed(void *data)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
|
|
@ -1154,12 +1164,21 @@ static void output_port_tag_changed(void *data)
|
|||
pw_impl_port_recalc_tag(this->input);
|
||||
}
|
||||
|
||||
static void output_port_capability_changed(void *data)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
struct pw_impl_link *this = &impl->this;
|
||||
if (!this->feedback)
|
||||
pw_impl_port_recalc_capability(this->input);
|
||||
}
|
||||
|
||||
static const struct pw_impl_port_events input_port_events = {
|
||||
PW_VERSION_IMPL_PORT_EVENTS,
|
||||
.param_changed = input_port_param_changed,
|
||||
.state_changed = input_port_state_changed,
|
||||
.latency_changed = input_port_latency_changed,
|
||||
.tag_changed = input_port_tag_changed,
|
||||
.capability_changed = input_port_capability_changed,
|
||||
};
|
||||
|
||||
static const struct pw_impl_port_events output_port_events = {
|
||||
|
|
@ -1168,6 +1187,7 @@ static const struct pw_impl_port_events output_port_events = {
|
|||
.state_changed = output_port_state_changed,
|
||||
.latency_changed = output_port_latency_changed,
|
||||
.tag_changed = output_port_tag_changed,
|
||||
.capability_changed = output_port_capability_changed,
|
||||
};
|
||||
|
||||
static void node_result(struct impl *impl, void *obj,
|
||||
|
|
@ -1576,6 +1596,8 @@ struct pw_impl_link *pw_context_create_link(struct pw_context *context,
|
|||
|
||||
try_link_controls(impl, output, input);
|
||||
|
||||
pw_impl_port_recalc_capability(output);
|
||||
pw_impl_port_recalc_capability(input);
|
||||
pw_impl_port_recalc_latency(output);
|
||||
pw_impl_port_recalc_latency(input);
|
||||
pw_impl_port_recalc_tag(output);
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@
|
|||
#include <spa/pod/parser.h>
|
||||
#include <spa/param/audio/format-utils.h>
|
||||
#include <spa/param/tag-utils.h>
|
||||
#include <spa/param/dict-utils.h>
|
||||
#include <spa/param/peer-utils.h>
|
||||
#include <spa/node/utils.h>
|
||||
#include <spa/utils/names.h>
|
||||
#include <spa/utils/string.h>
|
||||
|
|
@ -762,6 +764,35 @@ static int check_param_io(void *data, int seq, uint32_t id,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int process_capability_param(void *data, int seq,
|
||||
uint32_t id, uint32_t index, uint32_t next, struct spa_pod *param)
|
||||
{
|
||||
struct pw_impl_port *this = data;
|
||||
struct spa_param_dict_info info;
|
||||
struct spa_pod *old;
|
||||
|
||||
if (id != SPA_PARAM_Capability || param == NULL)
|
||||
return -EINVAL;
|
||||
if (spa_param_dict_parse(param, &info, sizeof(info)) < 0)
|
||||
return 0;
|
||||
|
||||
old = this->cap[this->direction];
|
||||
if (spa_param_dict_compare(old, param) == 0)
|
||||
return 0;
|
||||
|
||||
pw_log_debug("port %p: got %s capabilty %p", this,
|
||||
pw_direction_as_string(this->direction), param);
|
||||
if (param)
|
||||
pw_log_pod(SPA_LOG_LEVEL_DEBUG, param);
|
||||
|
||||
free(old);
|
||||
this->cap[this->direction] = spa_pod_copy(param);
|
||||
|
||||
pw_impl_port_emit_capability_changed(this);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int process_latency_param(void *data, int seq,
|
||||
uint32_t id, uint32_t index, uint32_t next, struct spa_pod *param)
|
||||
{
|
||||
|
|
@ -831,6 +862,7 @@ static void check_params(struct pw_impl_port *port)
|
|||
PW_IMPL_PORT_FLAG_BUFFERS);
|
||||
|
||||
pw_impl_port_for_each_param(port, 0, SPA_PARAM_IO, 0, 0, NULL, check_param_io, port);
|
||||
pw_impl_port_for_each_param(port, 0, SPA_PARAM_Capability, 0, 0, NULL, process_capability_param, port);
|
||||
pw_impl_port_for_each_param(port, 0, SPA_PARAM_Latency, 0, 0, NULL, process_latency_param, port);
|
||||
pw_impl_port_for_each_param(port, 0, SPA_PARAM_Tag, 0, 0, NULL, process_tag_param, port);
|
||||
}
|
||||
|
|
@ -877,6 +909,15 @@ static void update_info(struct pw_impl_port *port, const struct spa_port_info *i
|
|||
changed_ids[n_changed_ids++] = id;
|
||||
|
||||
switch (id) {
|
||||
case SPA_PARAM_PeerCapability:
|
||||
port->have_peer_capability_param =
|
||||
SPA_FLAG_IS_SET(info->params[i].flags, SPA_PARAM_INFO_WRITE);
|
||||
break;
|
||||
case SPA_PARAM_Capability:
|
||||
if (port->node != NULL)
|
||||
pw_impl_port_for_each_param(port, 0, id, 0, UINT32_MAX,
|
||||
NULL, process_capability_param, port);
|
||||
break;
|
||||
case SPA_PARAM_Latency:
|
||||
port->have_latency_param =
|
||||
SPA_FLAG_IS_SET(info->params[i].flags, SPA_PARAM_INFO_WRITE);
|
||||
|
|
@ -1918,6 +1959,66 @@ int pw_impl_port_recalc_tag(struct pw_impl_port *port)
|
|||
return pw_impl_port_set_param(port, SPA_PARAM_Tag, 0, port->tag[direction]);
|
||||
}
|
||||
|
||||
int pw_impl_port_recalc_capability(struct pw_impl_port *port)
|
||||
{
|
||||
struct pw_impl_link *l;
|
||||
struct pw_impl_port *other;
|
||||
struct spa_pod *param, *old;
|
||||
struct spa_pod_dynamic_builder b = { 0 };
|
||||
struct spa_pod_frame f;
|
||||
enum spa_direction direction;
|
||||
uint8_t buffer[1024];
|
||||
int count = 0;
|
||||
bool changed;
|
||||
|
||||
if (port->destroying)
|
||||
return 0;
|
||||
|
||||
direction = SPA_DIRECTION_REVERSE(port->direction);
|
||||
|
||||
spa_pod_dynamic_builder_init(&b, buffer, sizeof(buffer), 4096);
|
||||
spa_peer_param_build_start(&b.b, &f, SPA_PARAM_PeerCapability);
|
||||
|
||||
if (port->direction == PW_DIRECTION_OUTPUT) {
|
||||
spa_list_for_each(l, &port->links, output_link) {
|
||||
other = l->input;
|
||||
spa_peer_param_build_add_param(&b.b, other->info.id, other->cap[other->direction]);
|
||||
count++;
|
||||
}
|
||||
} else {
|
||||
spa_list_for_each(l, &port->links, input_link) {
|
||||
other = l->output;
|
||||
spa_peer_param_build_add_param(&b.b, other->info.id, other->cap[other->direction]);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
param = count == 0 ? NULL : spa_peer_param_build_end(&b.b, &f);
|
||||
|
||||
old = port->cap[direction];
|
||||
|
||||
changed = spa_pod_memcmp(old, param);
|
||||
|
||||
pw_log_info("port %d: %p %s %s cap %p %d",
|
||||
port->info.id, port, changed ? "set" : "keep",
|
||||
pw_direction_as_string(direction), param, port->have_peer_capability_param);
|
||||
|
||||
if (changed) {
|
||||
free(old);
|
||||
port->cap[direction] = param ? spa_pod_copy(param) : NULL;
|
||||
if (param)
|
||||
pw_log_pod(SPA_LOG_LEVEL_INFO, param);
|
||||
}
|
||||
spa_pod_dynamic_builder_clean(&b);
|
||||
|
||||
if (!changed)
|
||||
return 0;
|
||||
|
||||
if (!port->have_peer_capability_param)
|
||||
return 0;
|
||||
|
||||
return pw_impl_port_set_param(port, SPA_PARAM_PeerCapability, 0, port->cap[direction]);
|
||||
}
|
||||
|
||||
SPA_EXPORT
|
||||
int pw_impl_port_is_linked(struct pw_impl_port *port)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ enum pw_impl_port_state {
|
|||
|
||||
/** Port events, use \ref pw_impl_port_add_listener */
|
||||
struct pw_impl_port_events {
|
||||
#define PW_VERSION_IMPL_PORT_EVENTS 3
|
||||
#define PW_VERSION_IMPL_PORT_EVENTS 4
|
||||
uint32_t version;
|
||||
|
||||
/** The port is destroyed */
|
||||
|
|
@ -74,6 +74,8 @@ struct pw_impl_port_events {
|
|||
void (*latency_changed) (void *data);
|
||||
/** tag changed. Since version 3 */
|
||||
void (*tag_changed) (void *data);
|
||||
/** capability changed. Since version 4 */
|
||||
void (*capability_changed) (void *data);
|
||||
};
|
||||
|
||||
/** Create a new port
|
||||
|
|
|
|||
|
|
@ -902,6 +902,7 @@ struct pw_impl_port_implementation {
|
|||
#define pw_impl_port_emit_param_changed(p,i) pw_impl_port_emit(p, param_changed, 1, i)
|
||||
#define pw_impl_port_emit_latency_changed(p) pw_impl_port_emit(p, latency_changed, 2)
|
||||
#define pw_impl_port_emit_tag_changed(p) pw_impl_port_emit(p, tag_changed, 3)
|
||||
#define pw_impl_port_emit_capability_changed(p) pw_impl_port_emit(p, capability_changed, 4)
|
||||
|
||||
#define PW_IMPL_PORT_IS_CONTROL(port) SPA_FLAG_MASK((port)->flags, \
|
||||
PW_IMPL_PORT_FLAG_BUFFERS|PW_IMPL_PORT_FLAG_CONTROL,\
|
||||
|
|
@ -977,6 +978,9 @@ struct pw_impl_port {
|
|||
unsigned int have_tag_param:1;
|
||||
struct spa_pod *tag[2]; /**< tags */
|
||||
|
||||
unsigned int have_peer_capability_param:1;
|
||||
struct spa_pod *cap[2]; /**< capabilities */
|
||||
|
||||
void *owner_data; /**< extra owner data */
|
||||
void *user_data; /**< extra user data */
|
||||
};
|
||||
|
|
@ -1332,6 +1336,7 @@ int pw_impl_port_set_param(struct pw_impl_port *port,
|
|||
int pw_impl_port_use_buffers(struct pw_impl_port *port, struct pw_impl_port_mix *mix, uint32_t flags,
|
||||
struct spa_buffer **buffers, uint32_t n_buffers);
|
||||
|
||||
int pw_impl_port_recalc_capability(struct pw_impl_port *port);
|
||||
int pw_impl_port_recalc_latency(struct pw_impl_port *port);
|
||||
int pw_impl_port_recalc_tag(struct pw_impl_port *port);
|
||||
|
||||
|
|
|
|||
|
|
@ -103,14 +103,16 @@ struct stream {
|
|||
uint64_t port_change_mask_all;
|
||||
struct spa_port_info port_info;
|
||||
struct pw_properties *port_props;
|
||||
#define PORT_EnumFormat 0
|
||||
#define PORT_Meta 1
|
||||
#define PORT_IO 2
|
||||
#define PORT_Format 3
|
||||
#define PORT_Buffers 4
|
||||
#define PORT_Latency 5
|
||||
#define PORT_Tag 6
|
||||
#define N_PORT_PARAMS 7
|
||||
#define PORT_EnumFormat 0
|
||||
#define PORT_Meta 1
|
||||
#define PORT_IO 2
|
||||
#define PORT_Format 3
|
||||
#define PORT_Buffers 4
|
||||
#define PORT_Latency 5
|
||||
#define PORT_Tag 6
|
||||
#define PORT_Capability 7
|
||||
#define PORT_PeerCapability 8
|
||||
#define N_PORT_PARAMS 9
|
||||
struct spa_param_info port_params[N_PORT_PARAMS];
|
||||
|
||||
struct spa_list param_list;
|
||||
|
|
@ -196,6 +198,10 @@ static int get_port_param_index(uint32_t id)
|
|||
return PORT_Latency;
|
||||
case SPA_PARAM_Tag:
|
||||
return PORT_Tag;
|
||||
case SPA_PARAM_Capability:
|
||||
return PORT_Capability;
|
||||
case SPA_PARAM_PeerCapability:
|
||||
return PORT_PeerCapability;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -2015,6 +2021,8 @@ pw_stream_connect(struct pw_stream *stream,
|
|||
impl->port_params[PORT_Buffers] = SPA_PARAM_INFO(SPA_PARAM_Buffers, 0);
|
||||
impl->port_params[PORT_Latency] = SPA_PARAM_INFO(SPA_PARAM_Latency, SPA_PARAM_INFO_WRITE);
|
||||
impl->port_params[PORT_Tag] = SPA_PARAM_INFO(SPA_PARAM_Tag, SPA_PARAM_INFO_WRITE);
|
||||
impl->port_params[PORT_Capability] = SPA_PARAM_INFO(SPA_PARAM_Capability, 0);
|
||||
impl->port_params[PORT_PeerCapability] = SPA_PARAM_INFO(SPA_PARAM_PeerCapability, SPA_PARAM_INFO_WRITE);
|
||||
impl->port_info.props = &impl->port_props->dict;
|
||||
impl->port_info.params = impl->port_params;
|
||||
impl->port_info.n_params = N_PORT_PARAMS;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue