mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-07 13:30:09 -05: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
1 changed files with 24 additions and 8 deletions
|
|
@ -9,6 +9,9 @@
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
|
||||||
#include <spa/utils/result.h>
|
#include <spa/utils/result.h>
|
||||||
|
#include <spa/utils/cleanup.h>
|
||||||
|
#include <spa/debug/file.h>
|
||||||
|
|
||||||
#include <pipewire/pipewire.h>
|
#include <pipewire/pipewire.h>
|
||||||
|
|
||||||
#include <pipewire/i18n.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"
|
fprintf(stdout, _("%s [options]\n"
|
||||||
" -h, --help Show this help\n"
|
" -h, --help Show this help\n"
|
||||||
" --version Show version\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,
|
name,
|
||||||
config_name);
|
config_name);
|
||||||
}
|
}
|
||||||
|
|
@ -41,6 +45,7 @@ int main(int argc, char *argv[])
|
||||||
{ "version", no_argument, NULL, 'V' },
|
{ "version", no_argument, NULL, 'V' },
|
||||||
{ "config", required_argument, NULL, 'c' },
|
{ "config", required_argument, NULL, 'c' },
|
||||||
{ "verbose", no_argument, NULL, 'v' },
|
{ "verbose", no_argument, NULL, 'v' },
|
||||||
|
{ "properties", required_argument, NULL, 'P' },
|
||||||
|
|
||||||
{ NULL, 0, NULL, 0}
|
{ NULL, 0, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
@ -48,6 +53,7 @@ int main(int argc, char *argv[])
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
const char *config_name;
|
const char *config_name;
|
||||||
enum spa_log_level level = pw_log_level;
|
enum spa_log_level level = pw_log_level;
|
||||||
|
struct spa_error_location loc;
|
||||||
|
|
||||||
if (setenv("PIPEWIRE_INTERNAL", "1", 1) < 0)
|
if (setenv("PIPEWIRE_INTERNAL", "1", 1) < 0)
|
||||||
fprintf(stderr, "can't set PIPEWIRE_INTERNAL env: %m");
|
fprintf(stderr, "can't set PIPEWIRE_INTERNAL env: %m");
|
||||||
|
|
@ -58,7 +64,11 @@ int main(int argc, char *argv[])
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
pw_init(&argc, &argv);
|
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) {
|
switch (c) {
|
||||||
case 'v':
|
case 'v':
|
||||||
if (level < SPA_LOG_LEVEL_TRACE)
|
if (level < SPA_LOG_LEVEL_TRACE)
|
||||||
|
|
@ -77,17 +87,24 @@ int main(int argc, char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
case 'c':
|
case 'c':
|
||||||
config_name = optarg;
|
config_name = optarg;
|
||||||
|
pw_properties_set(properties, PW_KEY_CONFIG_NAME, config_name);
|
||||||
break;
|
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:
|
default:
|
||||||
res = -EINVAL;
|
res = -EINVAL;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
properties = pw_properties_new(
|
|
||||||
PW_KEY_CONFIG_NAME, config_name,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
loop = pw_main_loop_new(&properties->dict);
|
loop = pw_main_loop_new(&properties->dict);
|
||||||
if (loop == NULL) {
|
if (loop == NULL) {
|
||||||
pw_log_error("failed to create main-loop: %m");
|
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), SIGINT, do_quit, loop);
|
||||||
pw_loop_add_signal(pw_main_loop_get_loop(loop), SIGTERM, 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);
|
context = pw_context_new(pw_main_loop_get_loop(loop), spa_steal_ptr(properties), 0);
|
||||||
properties = NULL;
|
|
||||||
|
|
||||||
if (context == NULL) {
|
if (context == NULL) {
|
||||||
pw_log_error("failed to create context: %m");
|
pw_log_error("failed to create context: %m");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue