mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
pulse-server: add a pulse.cmd section
Add a new config section that can contain a set of commands to run after starting. There is only load-module available now but it can be used to remove the dependency on pactl when starting the server.
This commit is contained in:
parent
87d2719148
commit
b29200ee82
5 changed files with 185 additions and 3 deletions
|
|
@ -46,13 +46,24 @@ context.modules = [
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
# Extra modules can be loaded here. Setup in default.pa can be moved here
|
# Extra scripts can be started here. Setup in default.pa can be moved in
|
||||||
|
# a script or in pulse.cmd below
|
||||||
context.exec = [
|
context.exec = [
|
||||||
{ path = "pactl" args = "load-module module-always-sink" }
|
#{ path = "pactl" args = "load-module module-always-sink" }
|
||||||
#{ path = "pactl" args = "load-module module-switch-on-connect" }
|
#{ path = "pactl" args = "upload-sample my-sample.wav my-sample" }
|
||||||
#{ path = "/usr/bin/sh" args = "~/.config/pipewire/default.pw" }
|
#{ path = "/usr/bin/sh" args = "~/.config/pipewire/default.pw" }
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Extra commands can be executed here.
|
||||||
|
# load-module : loads a module with args and flags
|
||||||
|
# args = "<module-name> <module-args>"
|
||||||
|
# flags = [ "no-fail" ]
|
||||||
|
pulse.cmd = [
|
||||||
|
{ cmd = "load-module" args = "module-always-sink" flags = [ ] }
|
||||||
|
#{ cmd = "load-module" args = "module-switch-on-connect" }
|
||||||
|
#{ cmd = "load-module" args = "module-gsettings" flags = [ "nofail" ] }
|
||||||
|
]
|
||||||
|
|
||||||
stream.properties = {
|
stream.properties = {
|
||||||
#node.latency = 1024/48000
|
#node.latency = 1024/48000
|
||||||
#node.autoconnect = true
|
#node.autoconnect = true
|
||||||
|
|
|
||||||
|
|
@ -226,6 +226,7 @@ pipewire_module_protocol_pulse_sources = [
|
||||||
'module-protocol-pulse.c',
|
'module-protocol-pulse.c',
|
||||||
'module-protocol-pulse/client.c',
|
'module-protocol-pulse/client.c',
|
||||||
'module-protocol-pulse/collect.c',
|
'module-protocol-pulse/collect.c',
|
||||||
|
'module-protocol-pulse/cmd.c',
|
||||||
'module-protocol-pulse/extension.c',
|
'module-protocol-pulse/extension.c',
|
||||||
'module-protocol-pulse/extensions/ext-device-manager.c',
|
'module-protocol-pulse/extensions/ext-device-manager.c',
|
||||||
'module-protocol-pulse/extensions/ext-device-restore.c',
|
'module-protocol-pulse/extensions/ext-device-restore.c',
|
||||||
|
|
|
||||||
136
src/modules/module-protocol-pulse/cmd.c
Normal file
136
src/modules/module-protocol-pulse/cmd.c
Normal file
|
|
@ -0,0 +1,136 @@
|
||||||
|
/* PipeWire
|
||||||
|
*
|
||||||
|
* Copyright © 2022 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <spa/utils/json.h>
|
||||||
|
|
||||||
|
#include <pipewire/utils.h>
|
||||||
|
|
||||||
|
#include "module.h"
|
||||||
|
#include "cmd.h"
|
||||||
|
|
||||||
|
static const char WHITESPACE[] = " \t\n\r";
|
||||||
|
|
||||||
|
static int do_load_module(struct impl *impl, char *args, const char *flags)
|
||||||
|
{
|
||||||
|
int res, n;
|
||||||
|
struct module *module;
|
||||||
|
char *a[2] = { NULL };
|
||||||
|
|
||||||
|
n = pw_split_ip(args, WHITESPACE, 2, a);
|
||||||
|
if (n < 1) {
|
||||||
|
pw_log_info("load-module expects module name");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
module = module_create(impl, a[0], a[1]);
|
||||||
|
if (module == NULL)
|
||||||
|
return -errno;
|
||||||
|
if ((res = module_load(module)) < 0)
|
||||||
|
return res;
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int do_cmd(struct impl *impl, const char *cmd, char *args, const char *flags)
|
||||||
|
{
|
||||||
|
int res = 0;
|
||||||
|
if (spa_streq(cmd, "load-module")) {
|
||||||
|
res = do_load_module(impl, args, flags);
|
||||||
|
} else {
|
||||||
|
pw_log_warn("ignoring unknown command `%s` with args `%s`",
|
||||||
|
cmd, args);
|
||||||
|
}
|
||||||
|
if (res < 0) {
|
||||||
|
if (flags && strstr(flags, "nofail")) {
|
||||||
|
pw_log_info("nofail command %s %s: %s",
|
||||||
|
cmd, args, spa_strerror(res));
|
||||||
|
res = 0;
|
||||||
|
} else {
|
||||||
|
pw_log_error("can't run command %s %s: %s",
|
||||||
|
cmd, args, spa_strerror(res));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* pulse.cmd = [
|
||||||
|
* { cmd = <command> [ args = "<arguments>" ] }
|
||||||
|
* ...
|
||||||
|
* ]
|
||||||
|
*/
|
||||||
|
static int parse_cmd(void *user_data, const char *location,
|
||||||
|
const char *section, const char *str, size_t len)
|
||||||
|
{
|
||||||
|
struct impl *impl = user_data;
|
||||||
|
struct spa_json it[3];
|
||||||
|
char key[512], *s;
|
||||||
|
int res = 0;
|
||||||
|
|
||||||
|
s = strndup(str, len);
|
||||||
|
spa_json_init(&it[0], s, len);
|
||||||
|
if (spa_json_enter_array(&it[0], &it[1]) < 0) {
|
||||||
|
pw_log_error("config file error: pulse.cmd is not an array");
|
||||||
|
res = -EINVAL;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (spa_json_enter_object(&it[1], &it[2]) > 0) {
|
||||||
|
char *cmd = NULL, *args = NULL, *flags = NULL;
|
||||||
|
|
||||||
|
while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) {
|
||||||
|
const char *val;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
if ((len = spa_json_next(&it[2], &val)) <= 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (spa_streq(key, "cmd")) {
|
||||||
|
cmd = (char*)val;
|
||||||
|
spa_json_parse_stringn(val, len, cmd, len+1);
|
||||||
|
} else if (spa_streq(key, "args")) {
|
||||||
|
args = (char*)val;
|
||||||
|
spa_json_parse_stringn(val, len, args, len+1);
|
||||||
|
} else if (spa_streq(key, "flags")) {
|
||||||
|
if (spa_json_is_container(val, len))
|
||||||
|
len = spa_json_container_len(&it[2], val, len);
|
||||||
|
flags = (char*)val;
|
||||||
|
spa_json_parse_stringn(val, len, flags, len+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cmd != NULL)
|
||||||
|
res = do_cmd(impl, cmd, args, flags);
|
||||||
|
if (res < 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
exit:
|
||||||
|
free(s);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cmd_run(struct impl *impl)
|
||||||
|
{
|
||||||
|
return pw_context_conf_section_for_each(impl->context, "pulse.cmd",
|
||||||
|
parse_cmd, impl);
|
||||||
|
}
|
||||||
32
src/modules/module-protocol-pulse/cmd.h
Normal file
32
src/modules/module-protocol-pulse/cmd.h
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
/* PipeWire
|
||||||
|
*
|
||||||
|
* Copyright © 2022 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 PULSER_SERVER_CMD_H
|
||||||
|
#define PULSER_SERVER_CMD_H
|
||||||
|
|
||||||
|
#include "internal.h"
|
||||||
|
|
||||||
|
int cmd_run(struct impl *impl);
|
||||||
|
|
||||||
|
#endif /* PULSER_SERVER_CMD_H */
|
||||||
|
|
@ -57,6 +57,7 @@
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "collect.h"
|
#include "collect.h"
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
|
#include "cmd.h"
|
||||||
#include "dbus-name.h"
|
#include "dbus-name.h"
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
#include "extension.h"
|
#include "extension.h"
|
||||||
|
|
@ -5670,6 +5671,7 @@ struct pw_protocol_pulse *pw_protocol_pulse_new(struct pw_context *context,
|
||||||
#ifdef HAVE_DBUS
|
#ifdef HAVE_DBUS
|
||||||
impl->dbus_name = dbus_request_name(context, "org.pulseaudio.Server");
|
impl->dbus_name = dbus_request_name(context, "org.pulseaudio.Server");
|
||||||
#endif
|
#endif
|
||||||
|
cmd_run(impl);
|
||||||
|
|
||||||
return (struct pw_protocol_pulse *) impl;
|
return (struct pw_protocol_pulse *) impl;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue