From cab87b6d3e156a0e7c49a0df2f6de623425ac4c3 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 25 Feb 2021 13:35:04 +0100 Subject: [PATCH] pipewire: make pipewire a generic launcher It uses the basename as the config file so you can symlink to it and make new custom servers. --- src/daemon/meson.build | 4 +- src/daemon/pipewire-pulse.c | 117 ------------------------------ src/daemon/{main.c => pipewire.c} | 12 ++- 3 files changed, 10 insertions(+), 123 deletions(-) delete mode 100644 src/daemon/pipewire-pulse.c rename src/daemon/{main.c => pipewire.c} (92%) diff --git a/src/daemon/meson.build b/src/daemon/meson.build index b4abd00e2..d9966b850 100644 --- a/src/daemon/meson.build +++ b/src/daemon/meson.build @@ -1,5 +1,5 @@ pipewire_daemon_sources = [ - 'main.c', + 'pipewire.c', ] pipewire_c_args = [ @@ -54,7 +54,7 @@ executable('pipewire', ) executable('pipewire-pulse', - 'pipewire-pulse.c', + pipewire_daemon_sources, install: true, c_args : pipewire_c_args, include_directories : [configinc, spa_inc], diff --git a/src/daemon/pipewire-pulse.c b/src/daemon/pipewire-pulse.c deleted file mode 100644 index 18601c71e..000000000 --- a/src/daemon/pipewire-pulse.c +++ /dev/null @@ -1,117 +0,0 @@ -/* 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. - */ - -#include -#include - -#include - -#include - -#include "config.h" - -static const char *config_name = "pipewire-pulse.conf"; - -static void do_quit(void *data, int signal_number) -{ - struct pw_main_loop *loop = data; - pw_main_loop_quit(loop); -} - -static void show_help(const char *name) -{ - fprintf(stdout, "%s [options]\n\n" - "Start a pulseaudio compatible daemon.\n\n" - " -h, --help Show this help\n" - " --version Show version\n" - " -c, --config Load config (Default %s)\n", - name, - config_name); -} - -int main(int argc, char *argv[]) -{ - struct pw_context *context; - struct pw_main_loop *loop; - struct pw_properties *properties; - static const struct option long_options[] = { - { "help", no_argument, NULL, 'h' }, - { "version", no_argument, NULL, 'V' }, - { "config", required_argument, NULL, 'c' }, - { NULL, 0, NULL, 0} - }; - int c; - - pw_init(&argc, &argv); - - while ((c = getopt_long(argc, argv, "hVc:", long_options, NULL)) != -1) { - switch (c) { - case 'h': - show_help(argv[0]); - return 0; - case 'V': - 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; - case 'c': - config_name = optarg; - break; - default: - return -1; - } - } - - 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"); - return -1; - } - - 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); - if (context == NULL) { - pw_log_error("failed to create context: %m"); - return -1; - } - - pw_log_info("start main loop"); - pw_main_loop_run(loop); - pw_log_info("leave main loop"); - - pw_context_destroy(context); - pw_main_loop_destroy(loop); - pw_deinit(); - - return 0; -} diff --git a/src/daemon/main.c b/src/daemon/pipewire.c similarity index 92% rename from src/daemon/main.c rename to src/daemon/pipewire.c index 579345901..fc68fca2d 100644 --- a/src/daemon/main.c +++ b/src/daemon/pipewire.c @@ -22,6 +22,7 @@ * DEALINGS IN THE SOFTWARE. */ +#include #include #include @@ -30,15 +31,13 @@ #include "config.h" -static const char *config_name = "pipewire.conf"; - static void do_quit(void *data, int signal_number) { struct pw_main_loop *loop = data; pw_main_loop_quit(loop); } -static void show_help(const char *name) +static void show_help(const char *name, const char *config_name) { fprintf(stdout, "%s [options]\n" " -h, --help Show this help\n" @@ -61,16 +60,21 @@ int main(int argc, char *argv[]) { NULL, 0, NULL, 0} }; int c; + char path[PATH_MAX]; + const char *config_name; if (setenv("PIPEWIRE_INTERNAL", "1", 1) < 0) fprintf(stderr, "can't set PIPEWIRE_INTERNAL env: %m"); + snprintf(path, sizeof(path), "%s.conf", argv[0]); + config_name = basename(path); + pw_init(&argc, &argv); while ((c = getopt_long(argc, argv, "hVc:", long_options, NULL)) != -1) { switch (c) { case 'h': - show_help(argv[0]); + show_help(argv[0], config_name); return 0; case 'V': fprintf(stdout, "%s\n"