diff --git a/src/modules/meson.build b/src/modules/meson.build index 00d358bc0..ccb0dd57c 100644 --- a/src/modules/meson.build +++ b/src/modules/meson.build @@ -136,6 +136,7 @@ pipewire_module_protocol_pulse_sources = [ 'module-protocol-pulse/client.c', 'module-protocol-pulse/collect.c', 'module-protocol-pulse/dbus-name.c', + 'module-protocol-pulse/extension.c', 'module-protocol-pulse/format.c', 'module-protocol-pulse/manager.c', 'module-protocol-pulse/media-roles.c', diff --git a/src/modules/module-protocol-pulse/extension.c b/src/modules/module-protocol-pulse/extension.c index fdcbad081..2bfb564d0 100644 --- a/src/modules/module-protocol-pulse/extension.c +++ b/src/modules/module-protocol-pulse/extension.c @@ -22,21 +22,10 @@ * DEALINGS IN THE SOFTWARE. */ +#include #include -struct extension_sub { - const char *name; - uint32_t command; - int (*process)(struct client *client, uint32_t command, uint32_t tag, struct message *m); -}; - -struct extension { - const char *name; - uint32_t idx; - int (*process)(struct client *client, uint32_t tag, struct message *m); -}; - -#include "ext-stream-restore.c" +#include "extension.h" static int do_extension_device_restore(struct client *client, uint32_t tag, struct message *m) { @@ -48,13 +37,15 @@ static int do_extension_device_manager(struct client *client, uint32_t tag, stru return -ENOTSUP; } -struct extension extensions[] = { +#include "extensions/ext-stream-restore.c" + +static const struct extension extensions[] = { { "module-stream-restore", 0 | EXTENSION_FLAG, do_extension_stream_restore, }, { "module-device-restore", 1 | EXTENSION_FLAG, do_extension_device_restore, }, { "module-device-manager", 2 | EXTENSION_FLAG, do_extension_device_manager, }, }; -static struct extension *find_extension(uint32_t idx, const char *name) +const struct extension *extension_find(uint32_t idx, const char *name) { uint32_t i; for (i = 0; i < SPA_N_ELEMENTS(extensions); i++) { diff --git a/src/modules/module-protocol-pulse/extension.h b/src/modules/module-protocol-pulse/extension.h new file mode 100644 index 000000000..6cef21139 --- /dev/null +++ b/src/modules/module-protocol-pulse/extension.h @@ -0,0 +1,47 @@ +/* PipeWire + * + * Copyright © 2020 Wim Taymans + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef PULSE_SERVER_EXTENSION_H +#define PULSE_SERVER_EXTENSION_H + +#include + +struct client; +struct message; + +struct extension_sub { + const char *name; + uint32_t command; + int (*process)(struct client *client, uint32_t command, uint32_t tag, struct message *m); +}; + +struct extension { + const char *name; + uint32_t idx; + int (*process)(struct client *client, uint32_t tag, struct message *m); +}; + +const struct extension *extension_find(uint32_t idx, const char *name); + +#endif /* PULSE_SERVER_EXTENSION_H */ diff --git a/src/modules/module-protocol-pulse/ext-stream-restore.c b/src/modules/module-protocol-pulse/extensions/ext-stream-restore.c similarity index 92% rename from src/modules/module-protocol-pulse/ext-stream-restore.c rename to src/modules/module-protocol-pulse/extensions/ext-stream-restore.c index f960ff526..072a3e1cf 100644 --- a/src/modules/module-protocol-pulse/ext-stream-restore.c +++ b/src/modules/module-protocol-pulse/extensions/ext-stream-restore.c @@ -24,11 +24,28 @@ #define EXT_STREAM_RESTORE_VERSION 1 +#include +#include +#include +#include +#include + +#include +#include #include +#include +#include +#include -#include "media-roles.h" - -static const struct extension_sub ext_stream_restore[]; +#include "../client.h" +#include "../defs.h" +#include "../extension.h" +#include "../format.h" +#include "../manager.h" +#include "../media-roles.h" +#include "../message.h" +#include "../reply.h" +#include "../volume.h" static int do_extension_stream_restore_test(struct client *client, uint32_t command, uint32_t tag, struct message *m) { @@ -38,6 +55,7 @@ static int do_extension_stream_restore_test(struct client *client, uint32_t comm message_put(reply, TAG_U32, EXT_STREAM_RESTORE_VERSION, TAG_INVALID); + return client_queue_message(client, reply); } @@ -167,7 +185,7 @@ static int do_extension_stream_restore_read(struct client *client, uint32_t comm for (map.channels = 0; map.channels < CHANNELS_MAX; map.channels++) { char chname[16]; - if (spa_json_get_string(&it[2], chname, sizeof(chname)) <= 0) + if (spa_json_get_string(&it[2], chname, sizeof(chname)) <= 0) break; map.map[map.channels] = channel_name2id(chname); } @@ -187,6 +205,7 @@ static int do_extension_stream_restore_read(struct client *client, uint32_t comm TAG_BOOLEAN, mute, TAG_INVALID); } + return client_queue_message(client, reply); } @@ -249,13 +268,12 @@ static int do_extension_stream_restore_write(struct client *client, uint32_t com fprintf(f, ", \"target-node\": \"%s\"", device_name); fprintf(f, " }"); fclose(f); - if (key_from_name(name, key, sizeof(key)) >= 0) { pw_log_debug("%s -> %s: %s", name, key, ptr); if (pw_manager_set_metadata(client->manager, client->metadata_routes, PW_ID_CORE, key, "Spa:String:JSON", "%s", ptr) < 0) - pw_log_warn(NAME ": failed to set metadata %s = %s", key, ptr); + pw_log_warn("failed to set metadata %s = %s", key, ptr); } free(ptr); } @@ -284,7 +302,6 @@ static const struct extension_sub ext_stream_restore[] = { static int do_extension_stream_restore(struct client *client, uint32_t tag, struct message *m) { - struct impl *impl = client->impl; uint32_t command; int res; @@ -298,8 +315,8 @@ static int do_extension_stream_restore(struct client *client, uint32_t tag, stru if (ext_stream_restore[command].process == NULL) return -EPROTO; - pw_log_info(NAME" %p: [%s] EXT_STREAM_RESTORE_%s tag:%u", impl, - client->name, ext_stream_restore[command].name, tag); + pw_log_info("client %p [%s]: EXT_STREAM_RESTORE_%s tag:%u", + client, client->name, ext_stream_restore[command].name, tag); return ext_stream_restore[command].process(client, command, tag, m); } diff --git a/src/modules/module-protocol-pulse/pulse-server.c b/src/modules/module-protocol-pulse/pulse-server.c index 5f5da69e9..2991f9925 100644 --- a/src/modules/module-protocol-pulse/pulse-server.c +++ b/src/modules/module-protocol-pulse/pulse-server.c @@ -63,6 +63,7 @@ #include "commands.h" #include "dbus-name.h" #include "defs.h" +#include "extension.h" #include "format.h" #include "internal.h" #include "message.h" @@ -121,8 +122,6 @@ static struct sample *find_sample(struct impl *impl, uint32_t idx, const char *n return NULL; } -#include "extension.c" - static void broadcast_subscribe_event(struct impl *impl, uint32_t mask, uint32_t event, uint32_t id) { struct server *s; @@ -4225,7 +4224,7 @@ static int do_extension(struct client *client, uint32_t command, uint32_t tag, s struct impl *impl = client->impl; uint32_t idx; const char *name; - struct extension *ext; + const struct extension *ext; if (message_get(m, TAG_U32, &idx, @@ -4240,7 +4239,7 @@ static int do_extension(struct client *client, uint32_t command, uint32_t tag, s (idx != SPA_ID_INVALID && name != NULL)) return -EINVAL; - ext = find_extension(idx, name); + ext = extension_find(idx, name); if (ext == NULL) return -ENOENT;