From 0b4fa214b619164ddadd92fa559501481a042ff7 Mon Sep 17 00:00:00 2001 From: Tom M Date: Sat, 29 Jan 2022 13:13:25 +0100 Subject: [PATCH] Initialize Pipewire with pw_init() (#1032) Before you using any PipeWire functions, one must call pw_init() (e.g. https://docs.pipewire.org/page_tutorial1.html) --- doc/usage/audio_driver.txt | 7 +++++++ src/CMakeLists.txt | 4 ++++ src/drivers/fluid_pipewire.c | 2 +- src/fluidsynth.c | 9 ++++++++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/doc/usage/audio_driver.txt b/doc/usage/audio_driver.txt index e9b61a97..60e285b3 100644 --- a/doc/usage/audio_driver.txt +++ b/doc/usage/audio_driver.txt @@ -31,6 +31,7 @@ and a description. - file: Driver to output audio to a file - sdl2*: Simple DirectMedia Layer (Linux, Windows, Mac OS X, iOS, Android, FreeBSD, Haiku, etc.) +- pipewire**: PipeWire (Linux) The default audio driver depends on the settings with which FluidSynth was compiled. You can get the default driver with @@ -79,4 +80,10 @@ is responsible for initializing SDL (e.g. with SDL_Init()). This must be done Also make sure to call SDL_Quit() after all fluidsynth instances have been destroyed. +**Note: In order to use pipeiwre as audio driver, the application +is responsible for initializing PipeWire (e.g. with pw_init()). This must be done +before the first call to new_fluid_settings()! +Also make sure to call pw_deinit() after all fluidsynth instances have been +destroyed. + */ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c267abe0..e86a6429 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -490,6 +490,10 @@ if ( TARGET PkgConfig::SDL2 AND SDL2_SUPPORT ) # because SDL_Init() etc. target_link_libraries ( fluidsynth PRIVATE PkgConfig::SDL2 ) endif() +if ( TARGET PkgConfig::PIPEWIRE AND PIPEWIRE_SUPPORT ) # because pw_init() etc. + target_link_libraries ( fluidsynth PRIVATE PkgConfig::PIPEWIRE ) +endif() + if ( TARGET PkgConfig::LIBINSTPATCH AND LIBINSTPATCH_SUPPORT ) target_link_libraries ( fluidsynth PRIVATE PkgConfig::LIBINSTPATCH ) endif() diff --git a/src/drivers/fluid_pipewire.c b/src/drivers/fluid_pipewire.c index 58e05b52..0edd87fd 100644 --- a/src/drivers/fluid_pipewire.c +++ b/src/drivers/fluid_pipewire.c @@ -192,7 +192,7 @@ new_fluid_pipewire_audio_driver2(fluid_settings_t *settings, fluid_audio_func_t if(!drv->pw_loop) { - FLUID_LOG(FLUID_ERR, "Failed to allocate PipeWire loop"); + FLUID_LOG(FLUID_ERR, "Failed to allocate PipeWire loop. Have you called pw_init() ?"); goto driver_cleanup; } diff --git a/src/fluidsynth.c b/src/fluidsynth.c index e6631f65..eae9fdc5 100644 --- a/src/fluidsynth.c +++ b/src/fluidsynth.c @@ -42,6 +42,10 @@ #include #endif +#if PIPEWIRE_SUPPORT +#include +#endif + void print_usage(void); void print_help(fluid_settings_t *settings); void print_welcome(void); @@ -400,7 +404,6 @@ int main(int argc, char **argv) #endif #if SDL2_SUPPORT - if(SDL_Init(SDL_INIT_AUDIO) != 0) { fprintf(stderr, "Warning: Unable to initialize SDL2 Audio: %s", SDL_GetError()); @@ -409,7 +412,11 @@ int main(int argc, char **argv) { atexit(SDL_Quit); } +#endif +#if PIPEWIRE_SUPPORT + pw_init(&argc, &argv); + atexit(pw_deinit); #endif /* create the settings */