mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-22 08:56:59 -05:00
move things around
This commit is contained in:
parent
847cef83b6
commit
d1655196c3
130 changed files with 363 additions and 335 deletions
1
src/daemon/.gitignore
vendored
Normal file
1
src/daemon/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
pipewire.desktop
|
||||
200
src/daemon/daemon-config.c
Normal file
200
src/daemon/daemon-config.c
Normal file
|
|
@ -0,0 +1,200 @@
|
|||
/* PipeWire
|
||||
* Copyright (C) 2016 Axis Communications <dev-gstreamer@axis.com>
|
||||
* @author Linus Svensson <linus.svensson@axis.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <pipewire/pipewire.h>
|
||||
#include <pipewire/command.h>
|
||||
|
||||
#include "daemon/daemon-config.h"
|
||||
|
||||
#define DEFAULT_CONFIG_FILE PIPEWIRE_CONFIG_DIR "/pipewire.conf"
|
||||
|
||||
static bool
|
||||
parse_line(struct pw_daemon_config *config,
|
||||
const char *filename, char *line, unsigned int lineno, char **err)
|
||||
{
|
||||
struct pw_command *command = NULL;
|
||||
char *p;
|
||||
bool ret = true;
|
||||
char *local_err = NULL;
|
||||
|
||||
/* search for comments */
|
||||
if ((p = strchr(line, '#')))
|
||||
*p = '\0';
|
||||
|
||||
/* remove whitespaces */
|
||||
pw_strip(line, "\n\r \t");
|
||||
|
||||
if (*line == '\0') /* empty line */
|
||||
return true;
|
||||
|
||||
if ((command = pw_command_parse(line, &local_err)) == NULL) {
|
||||
asprintf(err, "%s:%u: %s", filename, lineno, local_err);
|
||||
free(local_err);
|
||||
ret = false;
|
||||
} else {
|
||||
spa_list_insert(config->commands.prev, &command->link);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* pw_daemon_config_new:
|
||||
*
|
||||
* Returns a new empty #struct pw_daemon_config.
|
||||
*/
|
||||
struct pw_daemon_config *pw_daemon_config_new(void)
|
||||
{
|
||||
struct pw_daemon_config *config;
|
||||
|
||||
config = calloc(1, sizeof(struct pw_daemon_config));
|
||||
spa_list_init(&config->commands);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* pw_daemon_config_free:
|
||||
* @config: A #struct pw_daemon_config
|
||||
*
|
||||
* Free all resources associated to @config.
|
||||
*/
|
||||
void pw_daemon_config_free(struct pw_daemon_config *config)
|
||||
{
|
||||
struct pw_command *cmd, *tmp;
|
||||
|
||||
spa_list_for_each_safe(cmd, tmp, &config->commands, link)
|
||||
pw_command_free(cmd);
|
||||
|
||||
free(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* pw_daemon_config_load_file:
|
||||
* @config: A #struct pw_daemon_config
|
||||
* @filename: A filename
|
||||
* @err: Return location for an error string
|
||||
*
|
||||
* Loads PipeWire config from @filename.
|
||||
*
|
||||
* Returns: %true on success, otherwise %false and @err is set.
|
||||
*/
|
||||
bool pw_daemon_config_load_file(struct pw_daemon_config *config, const char *filename, char **err)
|
||||
{
|
||||
unsigned int line;
|
||||
FILE *f;
|
||||
char buf[4096];
|
||||
|
||||
pw_log_debug("deamon-config %p: loading configuration file '%s'", config, filename);
|
||||
|
||||
if ((f = fopen(filename, "r")) == NULL) {
|
||||
asprintf(err, "failed to open configuration file '%s': %s", filename,
|
||||
strerror(errno));
|
||||
goto open_error;
|
||||
}
|
||||
|
||||
line = 0;
|
||||
|
||||
while (!feof(f)) {
|
||||
if (!fgets(buf, sizeof(buf), f)) {
|
||||
if (feof(f))
|
||||
break;
|
||||
|
||||
asprintf(err, "failed to read configuration file '%s': %s",
|
||||
filename, strerror(errno));
|
||||
goto read_error;
|
||||
}
|
||||
|
||||
line++;
|
||||
|
||||
if (!parse_line(config, filename, buf, line, err))
|
||||
goto parse_failed;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
return true;
|
||||
|
||||
parse_failed:
|
||||
read_error:
|
||||
fclose(f);
|
||||
open_error:
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* pw_daemon_config_load:
|
||||
* @config: A #struct pw_daemon_config
|
||||
* @err: Return location for a #GError, or %NULL
|
||||
*
|
||||
* Loads the default config file for PipeWire. The filename can be overridden with
|
||||
* an evironment variable PIPEWIRE_CONFIG_FILE.
|
||||
*
|
||||
* Return: %true on success, otherwise %false and @err is set.
|
||||
*/
|
||||
bool pw_daemon_config_load(struct pw_daemon_config *config, char **err)
|
||||
{
|
||||
const char *filename;
|
||||
|
||||
filename = getenv("PIPEWIRE_CONFIG_FILE");
|
||||
if (filename != NULL && *filename != '\0') {
|
||||
pw_log_debug("PIPEWIRE_CONFIG_FILE set to: %s", filename);
|
||||
} else {
|
||||
filename = DEFAULT_CONFIG_FILE;
|
||||
}
|
||||
return pw_daemon_config_load_file(config, filename, err);
|
||||
}
|
||||
|
||||
/**
|
||||
* pw_daemon_config_run_commands:
|
||||
* @config: A #struct pw_daemon_config
|
||||
* @core: A #struct pw_core
|
||||
*
|
||||
* Run all commands that have been parsed. The list of commands will be cleared
|
||||
* when this function has been called.
|
||||
*
|
||||
* Returns: %true if all commands where executed with success, otherwise %false.
|
||||
*/
|
||||
bool pw_daemon_config_run_commands(struct pw_daemon_config *config, struct pw_core *core)
|
||||
{
|
||||
char *err = NULL;
|
||||
bool ret = true;
|
||||
struct pw_command *command, *tmp;
|
||||
|
||||
spa_list_for_each(command, &config->commands, link) {
|
||||
if (!pw_command_run(command, core, &err)) {
|
||||
pw_log_warn("could not run command %s: %s", command->name, err);
|
||||
free(err);
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
|
||||
spa_list_for_each_safe(command, tmp, &config->commands, link) {
|
||||
pw_command_free(command);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
53
src/daemon/daemon-config.h
Normal file
53
src/daemon/daemon-config.h
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/* PipeWire
|
||||
* Copyright (C) 2016 Axis Communications <dev-gstreamer@axis.com>
|
||||
* @author Linus Svensson <linus.svensson@axis.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __PIPEWIRE_DAEMON_CONFIG_H__
|
||||
#define __PIPEWIRE_DAEMON_CONFIG_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <pipewire/core.h>
|
||||
|
||||
struct pw_daemon_config {
|
||||
struct spa_list commands;
|
||||
};
|
||||
|
||||
struct pw_daemon_config *
|
||||
pw_daemon_config_new(void);
|
||||
|
||||
void
|
||||
pw_daemon_config_free(struct pw_daemon_config *config);
|
||||
|
||||
bool
|
||||
pw_daemon_config_load_file(struct pw_daemon_config *config, const char *filename, char **err);
|
||||
|
||||
bool
|
||||
pw_daemon_config_load(struct pw_daemon_config *config, char **err);
|
||||
|
||||
bool
|
||||
pw_daemon_config_run_commands(struct pw_daemon_config *config, struct pw_core *core);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __PIPEWIRE_DAEMON_CONFIG_H__ */
|
||||
56
src/daemon/main.c
Normal file
56
src/daemon/main.c
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/* PipeWire
|
||||
* Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <pipewire/pipewire.h>
|
||||
#include <pipewire/core.h>
|
||||
#include <pipewire/module.h>
|
||||
|
||||
#include "daemon-config.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct pw_core *core;
|
||||
struct pw_main_loop *loop;
|
||||
struct pw_daemon_config *config;
|
||||
char *err = NULL;
|
||||
|
||||
pw_init(&argc, &argv);
|
||||
|
||||
/* parse configuration */
|
||||
config = pw_daemon_config_new();
|
||||
if (!pw_daemon_config_load(config, &err)) {
|
||||
pw_log_error("failed to parse config: %s", err);
|
||||
free(err);
|
||||
return -1;
|
||||
}
|
||||
|
||||
loop = pw_main_loop_new();
|
||||
|
||||
core = pw_core_new(loop->loop, NULL);
|
||||
|
||||
pw_daemon_config_run_commands(config, core);
|
||||
|
||||
pw_main_loop_run(loop);
|
||||
|
||||
pw_main_loop_destroy(loop);
|
||||
|
||||
pw_core_destroy(core);
|
||||
|
||||
return 0;
|
||||
}
|
||||
30
src/daemon/meson.build
Normal file
30
src/daemon/meson.build
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
pipewire_sources = [
|
||||
'main.c',
|
||||
'daemon-config.c',
|
||||
]
|
||||
|
||||
pipewire_headers = [
|
||||
'daemon-config.h',
|
||||
]
|
||||
|
||||
pipewire_c_args = [
|
||||
'-DHAVE_CONFIG_H',
|
||||
'-D_GNU_SOURCE',
|
||||
'-DG_LOG_DOMAIN=g_log_domain_pipewire',
|
||||
]
|
||||
|
||||
conf_config = configuration_data()
|
||||
conf_install_dir = '@0@/pipewire'.format(get_option('sysconfdir'))
|
||||
|
||||
configure_file(input : 'pipewire.conf.in',
|
||||
output : 'pipewire.conf',
|
||||
configuration : conf_config,
|
||||
install_dir : conf_install_dir)
|
||||
|
||||
executable('pipewire',
|
||||
pipewire_sources,
|
||||
install: true,
|
||||
c_args : pipewire_c_args,
|
||||
include_directories : [configinc, spa_inc],
|
||||
dependencies : [pipewire_dep],
|
||||
)
|
||||
31
src/daemon/pipewire-system.conf
Normal file
31
src/daemon/pipewire-system.conf
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0"?><!--*-nxml-*-->
|
||||
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
|
||||
|
||||
<!--
|
||||
This file is part of PipeWire.
|
||||
|
||||
PipeWire is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
PipeWire is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||
Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with PipeWire; if not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<busconfig>
|
||||
|
||||
<!-- System-wide PipeWire runs as 'pipewire' user. This fragment is
|
||||
not necessary for user PipeWire instances. -->
|
||||
|
||||
<policy user="pipewire">
|
||||
<allow own="org.pipewire"/>
|
||||
</policy>
|
||||
|
||||
</busconfig>
|
||||
11
src/daemon/pipewire.conf.in
Normal file
11
src/daemon/pipewire.conf.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#load-module libpipewire-module-protocol-dbus
|
||||
load-module libpipewire-module-protocol-native
|
||||
load-module libpipewire-module-suspend-on-idle
|
||||
#load-module libpipewire-module-spa-monitor alsa/libspa-alsa alsa-monitor alsa
|
||||
load-module libpipewire-module-spa-monitor v4l2/libspa-v4l2 v4l2-monitor v4l2
|
||||
#load-module libpipewire-module-spa-node videotestsrc/libspa-videotestsrc videotestsrc videotestsrc media.class=Video/Source Spa:POD:Object:Props:patternType=Spa:POD:Object:Props:patternType:snow
|
||||
load-module libpipewire-module-autolink
|
||||
#load-module libpipewire-module-mixer
|
||||
load-module libpipewire-module-client-node
|
||||
load-module libpipewire-module-flatpak
|
||||
#load-module libpipewire-module-jack
|
||||
11
src/daemon/pipewire.desktop.in
Normal file
11
src/daemon/pipewire.desktop.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
[Desktop Entry]
|
||||
Version=1.0
|
||||
_Name=PipeWire Media System
|
||||
_Comment=Start the PipeWire Media System
|
||||
Exec=pipewire
|
||||
Terminal=false
|
||||
Type=Application
|
||||
Categories=
|
||||
GenericName=
|
||||
X-GNOME-Autostart-Phase=Initialization
|
||||
X-KDE-autostart-phase=1
|
||||
Loading…
Add table
Add a link
Reference in a new issue