2017-05-23 19:15:33 +02:00
|
|
|
/* PipeWire
|
2015-04-16 16:58:33 +02:00
|
|
|
*
|
2018-11-05 17:48:52 +01:00
|
|
|
* Copyright © 2018 Wim Taymans
|
2015-04-16 16:58:33 +02:00
|
|
|
*
|
2018-11-05 17:48:52 +01:00
|
|
|
* 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:
|
2015-04-16 16:58:33 +02:00
|
|
|
*
|
2018-11-05 17:48:52 +01:00
|
|
|
* 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.
|
2015-04-16 16:58:33 +02:00
|
|
|
*/
|
|
|
|
|
|
2017-08-22 18:30:10 +02:00
|
|
|
#include <signal.h>
|
2018-08-16 18:25:30 +02:00
|
|
|
#include <getopt.h>
|
2017-08-22 18:30:10 +02:00
|
|
|
|
2017-07-11 15:57:20 +02:00
|
|
|
#include <pipewire/pipewire.h>
|
|
|
|
|
#include <pipewire/core.h>
|
|
|
|
|
#include <pipewire/module.h>
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2018-08-16 18:25:30 +02:00
|
|
|
#include "config.h"
|
2016-08-29 18:29:07 +02:00
|
|
|
#include "daemon-config.h"
|
|
|
|
|
|
2018-08-16 18:25:30 +02:00
|
|
|
static const char *daemon_name = "pipewire-0";
|
|
|
|
|
|
2017-08-22 18:30:10 +02:00
|
|
|
static void do_quit(void *data, int signal_number)
|
|
|
|
|
{
|
|
|
|
|
struct pw_main_loop *loop = data;
|
|
|
|
|
pw_main_loop_quit(loop);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-16 18:25:30 +02:00
|
|
|
static void show_help(const char *name)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stdout, "%s [options]\n"
|
|
|
|
|
" -h, --help Show this help\n"
|
|
|
|
|
" -v, --version Show version\n"
|
|
|
|
|
" -n, --name Daemon name (Default %s)\n",
|
|
|
|
|
name,
|
|
|
|
|
daemon_name);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
int main(int argc, char *argv[])
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2017-05-26 08:05:01 +02:00
|
|
|
struct pw_core *core;
|
|
|
|
|
struct pw_main_loop *loop;
|
|
|
|
|
struct pw_daemon_config *config;
|
|
|
|
|
char *err = NULL;
|
2017-07-11 20:38:48 +02:00
|
|
|
struct pw_properties *props;
|
2018-08-16 18:25:30 +02:00
|
|
|
static const struct option long_options[] = {
|
|
|
|
|
{"help", 0, NULL, 'h'},
|
|
|
|
|
{"version", 0, NULL, 'v'},
|
|
|
|
|
{"name", 1, NULL, 'n'},
|
|
|
|
|
{NULL, 0, NULL, 0}
|
|
|
|
|
};
|
|
|
|
|
char c;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
|
|
|
|
pw_init(&argc, &argv);
|
|
|
|
|
|
2018-08-16 18:25:30 +02:00
|
|
|
while ((c = getopt_long(argc, argv, "hvn:", 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 'n' :
|
|
|
|
|
daemon_name = optarg;
|
|
|
|
|
fprintf(stdout, "set name %s\n", daemon_name);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
/* parse configuration */
|
|
|
|
|
config = pw_daemon_config_new();
|
2017-12-18 11:38:30 +01:00
|
|
|
if (pw_daemon_config_load(config, &err) < 0) {
|
2017-05-26 08:05:01 +02:00
|
|
|
pw_log_error("failed to parse config: %s", err);
|
|
|
|
|
free(err);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-16 18:25:30 +02:00
|
|
|
props = pw_properties_new(PW_CORE_PROP_NAME, daemon_name,
|
2017-09-18 20:37:00 +02:00
|
|
|
PW_CORE_PROP_DAEMON, "1", NULL);
|
2017-07-11 20:38:48 +02:00
|
|
|
|
2017-08-08 18:22:44 +02:00
|
|
|
loop = pw_main_loop_new(props);
|
2017-08-22 18:30:10 +02: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
|
|
|
|
2017-08-04 10:18:54 +02:00
|
|
|
core = pw_core_new(pw_main_loop_get_loop(loop), props);
|
2016-06-23 19:22:44 +02:00
|
|
|
|
2017-12-18 11:38:30 +01:00
|
|
|
if (pw_daemon_config_run_commands(config, core) < 0) {
|
2017-09-07 10:22:32 +02:00
|
|
|
pw_log_error("failed to run config commands");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2017-08-22 18:30:10 +02:00
|
|
|
pw_log_info("start main loop");
|
2017-05-26 08:05:01 +02: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
|
|
|
|
2017-08-22 18:30:10 +02:00
|
|
|
pw_daemon_config_free(config);
|
2017-05-26 08:05:01 +02:00
|
|
|
pw_core_destroy(core);
|
2017-08-22 18:30:10 +02:00
|
|
|
pw_main_loop_destroy(loop);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
return 0;
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|