mirror of
https://gitlab.freedesktop.org/pipewire/pipewire
synced 2024-10-06 16:09:43 +00:00
pipewire: add a -P option to set context properties
Add a -P (--properties) option to create the context with custom properties. This can be used to control the modules that are loaded, for example when they have conditions.
This commit is contained in:
parent
18ce166735
commit
6aa690fa8d
|
@ -9,6 +9,9 @@
|
|||
#include <locale.h>
|
||||
|
||||
#include <spa/utils/result.h>
|
||||
#include <spa/utils/cleanup.h>
|
||||
#include <spa/debug/file.h>
|
||||
|
||||
#include <pipewire/pipewire.h>
|
||||
|
||||
#include <pipewire/i18n.h>
|
||||
|
@ -26,7 +29,8 @@ static void show_help(const char *name, const char *config_name)
|
|||
fprintf(stdout, _("%s [options]\n"
|
||||
" -h, --help Show this help\n"
|
||||
" --version Show version\n"
|
||||
" -c, --config Load config (Default %s)\n"),
|
||||
" -c, --config Load config (Default %s)\n"
|
||||
" -P --properties Set context properties\n"),
|
||||
name,
|
||||
config_name);
|
||||
}
|
||||
|
@ -41,6 +45,7 @@ int main(int argc, char *argv[])
|
|||
{ "version", no_argument, NULL, 'V' },
|
||||
{ "config", required_argument, NULL, 'c' },
|
||||
{ "verbose", no_argument, NULL, 'v' },
|
||||
{ "properties", required_argument, NULL, 'P' },
|
||||
|
||||
{ NULL, 0, NULL, 0}
|
||||
};
|
||||
|
@ -48,6 +53,7 @@ int main(int argc, char *argv[])
|
|||
char path[PATH_MAX];
|
||||
const char *config_name;
|
||||
enum spa_log_level level = pw_log_level;
|
||||
struct spa_error_location loc;
|
||||
|
||||
if (setenv("PIPEWIRE_INTERNAL", "1", 1) < 0)
|
||||
fprintf(stderr, "can't set PIPEWIRE_INTERNAL env: %m");
|
||||
|
@ -58,7 +64,11 @@ int main(int argc, char *argv[])
|
|||
setlocale(LC_ALL, "");
|
||||
pw_init(&argc, &argv);
|
||||
|
||||
while ((c = getopt_long(argc, argv, "hVc:v", long_options, NULL)) != -1) {
|
||||
properties = pw_properties_new(
|
||||
PW_KEY_CONFIG_NAME, config_name,
|
||||
NULL);
|
||||
|
||||
while ((c = getopt_long(argc, argv, "hVc:vP:", long_options, NULL)) != -1) {
|
||||
switch (c) {
|
||||
case 'v':
|
||||
if (level < SPA_LOG_LEVEL_TRACE)
|
||||
|
@ -77,17 +87,24 @@ int main(int argc, char *argv[])
|
|||
return 0;
|
||||
case 'c':
|
||||
config_name = optarg;
|
||||
pw_properties_set(properties, PW_KEY_CONFIG_NAME, config_name);
|
||||
break;
|
||||
|
||||
case 'P':
|
||||
if (pw_properties_update_string_checked(properties, optarg, strlen(optarg), &loc) < 0) {
|
||||
spa_debug_file_error_location(stderr, &loc,
|
||||
"error: syntax error in --properties: %s",
|
||||
loc.reason);
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
res = -EINVAL;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
properties = pw_properties_new(
|
||||
PW_KEY_CONFIG_NAME, config_name,
|
||||
NULL);
|
||||
|
||||
loop = pw_main_loop_new(&properties->dict);
|
||||
if (loop == NULL) {
|
||||
pw_log_error("failed to create main-loop: %m");
|
||||
|
@ -98,8 +115,7 @@ int main(int argc, char *argv[])
|
|||
pw_loop_add_signal(pw_main_loop_get_loop(loop), SIGINT, do_quit, loop);
|
||||
pw_loop_add_signal(pw_main_loop_get_loop(loop), SIGTERM, do_quit, loop);
|
||||
|
||||
context = pw_context_new(pw_main_loop_get_loop(loop), properties, 0);
|
||||
properties = NULL;
|
||||
context = pw_context_new(pw_main_loop_get_loop(loop), spa_steal_ptr(properties), 0);
|
||||
|
||||
if (context == NULL) {
|
||||
pw_log_error("failed to create context: %m");
|
||||
|
|
Loading…
Reference in a new issue