2023-02-08 18:12:00 +01:00
|
|
|
/* PipeWire */
|
|
|
|
|
/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
|
|
|
|
|
/* SPDX-License-Identifier: MIT */
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2021-02-25 13:35:04 +01:00
|
|
|
#include <limits.h>
|
2017-08-22 18:30:10 +02:00
|
|
|
#include <signal.h>
|
2018-08-16 18:25:30 +02:00
|
|
|
#include <getopt.h>
|
2021-03-19 22:48:08 +03:00
|
|
|
#include <libgen.h>
|
2022-03-22 20:31:07 +02:00
|
|
|
#include <locale.h>
|
2017-08-22 18:30:10 +02:00
|
|
|
|
2019-10-25 15:01:02 +02:00
|
|
|
#include <spa/utils/result.h>
|
2024-04-10 18:13:01 +02:00
|
|
|
#include <spa/utils/cleanup.h>
|
|
|
|
|
#include <spa/debug/file.h>
|
|
|
|
|
|
2021-02-11 21:01:58 +01:00
|
|
|
#include <pipewire/pipewire.h>
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2021-04-30 09:57:30 +02:00
|
|
|
#include <pipewire/i18n.h>
|
|
|
|
|
|
2018-08-16 18:25:30 +02:00
|
|
|
#include "config.h"
|
2016-08-29 18:29:07 +02:00
|
|
|
|
2017-08-22 18:30:10 +02:00
|
|
|
static void do_quit(void *data, int signal_number)
|
|
|
|
|
{
|
2021-02-11 21:01:58 +01:00
|
|
|
struct pw_main_loop *loop = data;
|
|
|
|
|
pw_main_loop_quit(loop);
|
2017-08-22 18:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-25 13:35:04 +01:00
|
|
|
static void show_help(const char *name, const char *config_name)
|
2018-08-16 18:25:30 +02:00
|
|
|
{
|
2021-04-15 17:42:02 +02:00
|
|
|
fprintf(stdout, _("%s [options]\n"
|
2020-04-02 14:34:02 +02:00
|
|
|
" -h, --help Show this help\n"
|
2024-04-15 15:39:50 +02:00
|
|
|
" -v, --verbose Increase verbosity by one level\n"
|
2020-04-02 14:34:02 +02:00
|
|
|
" --version Show version\n"
|
2024-04-10 18:13:01 +02:00
|
|
|
" -c, --config Load config (Default %s)\n"
|
|
|
|
|
" -P --properties Set context properties\n"),
|
2020-04-02 14:34:02 +02:00
|
|
|
name,
|
2021-02-11 21:01:58 +01:00
|
|
|
config_name);
|
2018-08-16 18:25:30 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
int main(int argc, char *argv[])
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2021-06-08 14:57:07 +02:00
|
|
|
struct pw_context *context = NULL;
|
|
|
|
|
struct pw_main_loop *loop = NULL;
|
|
|
|
|
struct pw_properties *properties = NULL;
|
2018-08-16 18:25:30 +02:00
|
|
|
static const struct option long_options[] = {
|
2020-04-02 14:34:02 +02:00
|
|
|
{ "help", no_argument, NULL, 'h' },
|
|
|
|
|
{ "version", no_argument, NULL, 'V' },
|
2021-02-11 21:01:58 +01:00
|
|
|
{ "config", required_argument, NULL, 'c' },
|
2021-09-24 08:51:28 +10:00
|
|
|
{ "verbose", no_argument, NULL, 'v' },
|
2024-04-10 18:13:01 +02:00
|
|
|
{ "properties", required_argument, NULL, 'P' },
|
2020-04-02 14:34:02 +02:00
|
|
|
|
|
|
|
|
{ NULL, 0, NULL, 0}
|
2018-08-16 18:25:30 +02:00
|
|
|
};
|
2021-06-08 14:57:07 +02:00
|
|
|
int c, res = 0;
|
2021-02-25 13:35:04 +01:00
|
|
|
char path[PATH_MAX];
|
|
|
|
|
const char *config_name;
|
2024-04-15 15:39:50 +02:00
|
|
|
enum spa_log_level level;
|
2024-04-10 18:13:01 +02:00
|
|
|
struct spa_error_location loc;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2020-12-31 16:42:41 +01:00
|
|
|
if (setenv("PIPEWIRE_INTERNAL", "1", 1) < 0)
|
|
|
|
|
fprintf(stderr, "can't set PIPEWIRE_INTERNAL env: %m");
|
|
|
|
|
|
2021-02-25 13:35:04 +01:00
|
|
|
snprintf(path, sizeof(path), "%s.conf", argv[0]);
|
|
|
|
|
config_name = basename(path);
|
|
|
|
|
|
2022-03-22 20:31:07 +02:00
|
|
|
setlocale(LC_ALL, "");
|
2017-05-26 08:05:01 +02:00
|
|
|
pw_init(&argc, &argv);
|
|
|
|
|
|
2024-04-15 15:39:50 +02:00
|
|
|
level = pw_log_level;
|
|
|
|
|
|
2024-04-10 18:13:01 +02:00
|
|
|
properties = pw_properties_new(
|
|
|
|
|
PW_KEY_CONFIG_NAME, config_name,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
while ((c = getopt_long(argc, argv, "hVc:vP:", long_options, NULL)) != -1) {
|
2018-08-16 18:25:30 +02:00
|
|
|
switch (c) {
|
2021-09-24 08:51:28 +10:00
|
|
|
case 'v':
|
|
|
|
|
if (level < SPA_LOG_LEVEL_TRACE)
|
2021-09-25 07:21:01 +10:00
|
|
|
pw_log_set_level(++level);
|
2021-09-24 08:51:28 +10:00
|
|
|
break;
|
2021-02-11 21:01:58 +01:00
|
|
|
case 'h':
|
2021-02-25 13:35:04 +01:00
|
|
|
show_help(argv[0], config_name);
|
2018-08-16 18:25:30 +02:00
|
|
|
return 0;
|
2021-02-11 21:01:58 +01:00
|
|
|
case 'V':
|
2018-08-16 18:25:30 +02:00
|
|
|
fprintf(stdout, "%s\n"
|
|
|
|
|
"Compiled with libpipewire %s\n"
|
|
|
|
|
"Linked with libpipewire %s\n",
|
|
|
|
|
argv[0],
|
|
|
|
|
pw_get_headers_version(),
|
|
|
|
|
pw_get_library_version());
|
|
|
|
|
return 0;
|
2021-02-11 21:01:58 +01:00
|
|
|
case 'c':
|
|
|
|
|
config_name = optarg;
|
2024-04-10 18:13:01 +02:00
|
|
|
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;
|
|
|
|
|
}
|
2018-08-16 18:25:30 +02:00
|
|
|
break;
|
2024-04-10 18:13:01 +02:00
|
|
|
|
2018-08-16 18:25:30 +02:00
|
|
|
default:
|
2021-06-08 14:57:07 +02:00
|
|
|
res = -EINVAL;
|
|
|
|
|
goto done;
|
2018-08-16 18:25:30 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-11 21:01:58 +01:00
|
|
|
loop = pw_main_loop_new(&properties->dict);
|
|
|
|
|
if (loop == NULL) {
|
2019-06-20 15:19:28 +02:00
|
|
|
pw_log_error("failed to create main-loop: %m");
|
2021-06-08 14:57:07 +02:00
|
|
|
res = -errno;
|
|
|
|
|
goto done;
|
2019-06-20 15:19:28 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-11 21:01:58 +01:00
|
|
|
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);
|
2017-08-08 18:22:44 +02:00
|
|
|
|
2024-04-10 18:13:01 +02:00
|
|
|
context = pw_context_new(pw_main_loop_get_loop(loop), spa_steal_ptr(properties), 0);
|
2021-06-08 14:57:07 +02:00
|
|
|
|
2021-02-11 21:01:58 +01:00
|
|
|
if (context == NULL) {
|
2019-12-10 18:19:56 +01:00
|
|
|
pw_log_error("failed to create context: %m");
|
2021-06-08 14:57:07 +02:00
|
|
|
res = -errno;
|
|
|
|
|
goto done;
|
2019-06-18 10:47:12 -04:00
|
|
|
}
|
|
|
|
|
|
2017-08-22 18:30:10 +02:00
|
|
|
pw_log_info("start main loop");
|
2021-02-11 21:01:58 +01:00
|
|
|
pw_main_loop_run(loop);
|
2017-08-22 18:30:10 +02:00
|
|
|
pw_log_info("leave main loop");
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2021-06-08 14:57:07 +02:00
|
|
|
done:
|
|
|
|
|
pw_properties_free(properties);
|
|
|
|
|
if (context)
|
|
|
|
|
pw_context_destroy(context);
|
|
|
|
|
if (loop)
|
|
|
|
|
pw_main_loop_destroy(loop);
|
2020-06-02 17:16:46 +02:00
|
|
|
pw_deinit();
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2021-06-08 14:57:07 +02:00
|
|
|
return res;
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|