Commit 69cda19a authored by Michael Olbrich's avatar Michael Olbrich

Add pipewire plugin

It is quite similar to the remoting plugin. It just exports the frames via
pipewire instead of the builtin GStreamer pipeline.
It implements the same virtual output API. Virtual outputs can be created
by adding 'pipewire-output' sections to weston.ini.

The generated frames can be accessed with any pipewire client. e.g. with
GStreamer:

gst-launch-1.0 pipewiresrc ! video/x-raw,format=BGRx ! ...
Signed-off-by: Michael Olbrich's avatarMichael Olbrich <m.olbrich@pengutronix.de>
parent 7e5b765d
Pipeline #36358 failed with stages
in 39 seconds
......@@ -4,7 +4,7 @@ set -o xtrace
echo 'deb http://deb.debian.org/debian buster-backports main' >> /etc/apt/sources.list
apt-get update
apt-get -y --no-install-recommends install build-essential automake autoconf libtool pkg-config libexpat1-dev libffi-dev libxml2-dev libpixman-1-dev libpng-dev libjpeg-dev libcolord-dev mesa-common-dev libglu1-mesa-dev libegl1-mesa-dev libgles2-mesa-dev libwayland-dev libxcb1-dev libxcb-composite0-dev libxcb-xfixes0-dev libxcb-xkb-dev libx11-xcb-dev libx11-dev libudev-dev libgbm-dev libxkbcommon-dev libcairo2-dev libpango1.0-dev libgdk-pixbuf2.0-dev libxcursor-dev libmtdev-dev libpam0g-dev libvpx-dev libsystemd-dev libevdev-dev libinput-dev libwebp-dev libjpeg-dev libva-dev liblcms2-dev git libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev freerdp2-dev curl python3-pip python3-setuptools ninja-build libdbus-1-dev
apt-get -y --no-install-recommends install build-essential automake autoconf libtool pkg-config libexpat1-dev libffi-dev libxml2-dev libpixman-1-dev libpng-dev libjpeg-dev libcolord-dev mesa-common-dev libglu1-mesa-dev libegl1-mesa-dev libgles2-mesa-dev libwayland-dev libxcb1-dev libxcb-composite0-dev libxcb-xfixes0-dev libxcb-xkb-dev libx11-xcb-dev libx11-dev libudev-dev libgbm-dev libxkbcommon-dev libcairo2-dev libpango1.0-dev libgdk-pixbuf2.0-dev libxcursor-dev libmtdev-dev libpam0g-dev libvpx-dev libsystemd-dev libevdev-dev libinput-dev libwebp-dev libjpeg-dev libva-dev liblcms2-dev git libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev freerdp2-dev curl python3-pip python3-setuptools ninja-build libdbus-1-dev libpipewire-0.2-dev
pip3 install --user git+https://github.com/mesonbuild/meson.git@0.49
......
......@@ -64,6 +64,7 @@
#include <libweston/windowed-output-api.h>
#include <libweston/weston-debug.h>
#include "../remoting/remoting-plugin.h"
#include "../pipewire/pipewire-plugin.h"
#define WINDOW_TITLE "Weston Compositor"
......@@ -2319,6 +2320,130 @@ load_remoting(struct weston_compositor *c, struct weston_config *wc)
}
}
static int
drm_backend_pipewire_output_configure(struct weston_output *output,
struct weston_config_section *section,
char *modeline,
const struct weston_pipewire_api *api)
{
char *seat = NULL;
int ret;
ret = api->set_mode(output, modeline);
if (ret < 0) {
weston_log("Cannot configure an output \"%s\" using "
"weston_pipewire_api. Invalid mode\n",
output->name);
return -1;
}
wet_output_set_scale(output, section, 1, 0);
wet_output_set_transform(output, section, WL_OUTPUT_TRANSFORM_NORMAL,
UINT32_MAX);
weston_config_section_get_string(section, "seat", &seat, "");
api->set_seat(output, seat);
free(seat);
return 0;
}
static void
pipewire_output_init(struct weston_compositor *c,
struct weston_config_section *section,
const struct weston_pipewire_api *api)
{
struct weston_output *output = NULL;
char *output_name, *modeline = NULL;
int ret;
weston_config_section_get_string(section, "name", &output_name,
NULL);
if (!output_name)
return;
weston_config_section_get_string(section, "mode", &modeline, "off");
if (strcmp(modeline, "off") == 0)
goto err;
output = api->create_output(c, output_name);
if (!output) {
weston_log("Cannot create pipewire output \"%s\".\n",
output_name);
goto err;
}
ret = drm_backend_pipewire_output_configure(output, section, modeline,
api);
if (ret < 0) {
weston_log("Cannot configure pipewire output \"%s\".\n",
output_name);
goto err;
}
if (weston_output_enable(output) < 0) {
weston_log("Enabling pipewire output \"%s\" failed.\n",
output_name);
goto err;
}
free(modeline);
free(output_name);
weston_log("pipewire output '%s' enabled\n", output->name);
return;
err:
free(modeline);
free(output_name);
if (output)
weston_output_destroy(output);
}
static void
load_pipewire(struct weston_compositor *c, struct weston_config *wc)
{
const struct weston_pipewire_api *api = NULL;
int (*module_init)(struct weston_compositor *ec);
struct weston_config_section *section = NULL;
const char *section_name;
/* read pipewire-output section in weston.ini */
while (weston_config_next_section(wc, &section, &section_name)) {
if (strcmp(section_name, "pipewire-output"))
continue;
if (!api) {
char *module_name;
struct weston_config_section *core_section =
weston_config_get_section(wc, "core", NULL,
NULL);
weston_config_section_get_string(core_section,
"pipewire",
&module_name,
"pipewire-plugin.so");
module_init = weston_load_module(module_name,
"weston_module_init");
free(module_name);
if (!module_init) {
weston_log("Can't load pipewire-plugin\n");
return;
}
if (module_init(c) < 0) {
weston_log("Pipewire-plugin init failed\n");
return;
}
api = weston_pipewire_get_api(c);
if (!api)
return;
}
pipewire_output_init(c, section, api);
}
}
static int
load_drm_backend(struct weston_compositor *c,
int *argc, char **argv, struct weston_config *wc)
......@@ -2372,6 +2497,9 @@ load_drm_backend(struct weston_compositor *c,
/* remoting */
load_remoting(c, wc);
/* pipewire */
load_pipewire(c, wc);
free(config.gbm_format);
free(config.seat_id);
......
......@@ -152,6 +152,7 @@ subdir('desktop-shell')
subdir('fullscreen-shell')
subdir('ivi-shell')
subdir('remoting')
subdir('pipewire')
subdir('clients')
subdir('wcap')
subdir('tests')
......
......@@ -99,6 +99,13 @@ option(
description: 'Virtual remote output with GStreamer on DRM backend'
)
option(
'pipewire',
type: 'boolean',
value: true,
description: 'Virtual remote output with Pipewire on DRM backend'
)
option(
'shell-desktop',
type: 'boolean',
......
if get_option('pipewire')
user_hint = 'If you rather not build this, set "pipewire=false".'
if not get_option('backend-drm')
error('Attempting to build the pipewire plugin without the required DRM backend. ' + user_hint)
endif
depnames = [
'libpipewire-0.2', 'libspa-0.1'
]
deps_pipewire = [ dep_libweston ]
foreach depname : depnames
dep = dependency(depname, required: false)
if not dep.found()
error('Pipewire plugin requires @0@ which was not found. '.format(depname) + user_hint)
endif
deps_pipewire += dep
endforeach
plugin_pipewire = shared_library(
'pipewire-plugin',
'pipewire-plugin.c',
include_directories: include_directories('..', '../shared'),
dependencies: deps_pipewire,
name_prefix: '',
install: true,
install_dir: dir_module_libweston
)
env_modmap += 'pipewire-plugin.so=@0@;'.format(plugin_pipewire.full_path())
endif
This diff is collapsed.
/*
* Copyright © 2019 Pengutronix, Michael Olbrich <m.olbrich@pengutronix.de>
*
* 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.
*/
#ifndef PIPEWIRE_PLUGIN_H
#define PIPEWIRE_PLUGIN_H
#include <libweston/libweston.h>
#include <libweston/plugin-registry.h>
#define WESTON_PIPEWIRE_API_NAME "weston_pipewire_api_v1"
struct weston_pipewire_api {
/** Create pipewire outputs
*
* Returns 0 on success, -1 on failure.
*/
struct weston_output *(*create_output)(struct weston_compositor *c,
char *name);
/** Check if output is pipewire */
bool (*is_pipewire_output)(struct weston_output *output);
/** Set mode */
int (*set_mode)(struct weston_output *output, const char *modeline);
/** Set seat */
void (*set_seat)(struct weston_output *output, const char *seat);
};
static inline const struct weston_pipewire_api *
weston_pipewire_get_api(struct weston_compositor *compositor)
{
const void *api;
api = weston_plugin_api_get(compositor, WESTON_PIPEWIRE_API_NAME,
sizeof(struct weston_pipewire_api));
return (const struct weston_pipewire_api *)api;
}
#endif /* PIPEWIRE_PLUGIN_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment