From 6d0613bc9a45cedca4d23b063a1a6ae3b1c32f09 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 11 Oct 2023 15:17:13 +0200 Subject: [PATCH] pulse-server: place stream media.* keys as Tag --- .../module-protocol-pulse/pulse-server.c | 5 ++- src/modules/module-protocol-pulse/stream.c | 36 +++++++++++++++++++ src/modules/module-protocol-pulse/stream.h | 1 + 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/modules/module-protocol-pulse/pulse-server.c b/src/modules/module-protocol-pulse/pulse-server.c index 3711717a5..34efa9c50 100644 --- a/src/modules/module-protocol-pulse/pulse-server.c +++ b/src/modules/module-protocol-pulse/pulse-server.c @@ -1820,6 +1820,8 @@ static int do_create_playback_stream(struct client *client, uint32_t command, ui PW_STREAM_FLAG_MAP_BUFFERS, params, n_params); + stream_update_tag_param(stream); + return 0; error_errno: @@ -3215,7 +3217,8 @@ static int do_update_proplist(struct client *client, uint32_t command, uint32_t if (stream == NULL || stream->type == STREAM_TYPE_UPLOAD) return -ENOENT; - pw_stream_update_properties(stream->stream, &props->dict); + if (pw_stream_update_properties(stream->stream, &props->dict) > 0) + stream_update_tag_param(stream); } else { if (pw_properties_update(client->props, &props->dict) > 0) { client_update_quirks(client); diff --git a/src/modules/module-protocol-pulse/stream.c b/src/modules/module-protocol-pulse/stream.c index c216f6ec0..94d1fdd9d 100644 --- a/src/modules/module-protocol-pulse/stream.c +++ b/src/modules/module-protocol-pulse/stream.c @@ -8,6 +8,9 @@ #include #include +#include +#include + #include #include #include @@ -412,3 +415,36 @@ int stream_send_moved(struct stream *stream, uint32_t peer_index, const char *pe } return client_queue_message(client, reply); } + +int stream_update_tag_param(struct stream *stream) +{ + struct spa_pod_dynamic_builder b; + const struct pw_properties *props = pw_stream_get_properties(stream->stream); + const struct spa_pod *param[1]; + struct spa_dict_item items[64]; + uint32_t i, n_items = 0; + uint8_t buffer[4096]; + + if (props == NULL) + return -EIO; + + spa_pod_dynamic_builder_init(&b, buffer, sizeof(buffer), 4096); + + for (i = 0; i < props->dict.n_items; i++) { + if (n_items < SPA_N_ELEMENTS(items) && + spa_strstartswith(props->dict.items[i].key, "media.")) + items[n_items++] = props->dict.items[i]; + } + if (n_items > 0) { + struct spa_pod_frame f; + spa_tag_build_start(&b.b, &f, SPA_PARAM_Tag, SPA_DIRECTION_OUTPUT); + spa_tag_build_add_dict(&b.b, &SPA_DICT_INIT(items, n_items)); + param[0] = spa_tag_build_end(&b.b, &f); + } else { + param[0] = NULL; + } + if (param[0] != NULL) + pw_stream_update_params(stream->stream, param, 1); + spa_pod_dynamic_builder_clean(&b); + return 0; +} diff --git a/src/modules/module-protocol-pulse/stream.h b/src/modules/module-protocol-pulse/stream.h index 570661276..b0522ea49 100644 --- a/src/modules/module-protocol-pulse/stream.h +++ b/src/modules/module-protocol-pulse/stream.h @@ -116,5 +116,6 @@ int stream_send_started(struct stream *stream); int stream_send_request(struct stream *stream); int stream_update_minreq(struct stream *stream, uint32_t minreq); int stream_send_moved(struct stream *stream, uint32_t peer_index, const char *peer_name); +int stream_update_tag_param(struct stream *stream); #endif /* PULSER_SERVER_STREAM_H */