mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-09-21 18:55:24 +08:00
audio: Add Pipewire playback/capture sink
This commit is contained in:
committed by
Sam Lantinga
parent
57a927e8d7
commit
2f0b99a774
@@ -360,6 +360,8 @@ set_option(JACK "Support the JACK audio API" ${UNIX_SYS})
|
||||
dep_option(JACK_SHARED "Dynamically load JACK audio support" ON "JACK" OFF)
|
||||
set_option(ESD "Support the Enlightened Sound Daemon" ${UNIX_SYS})
|
||||
dep_option(ESD_SHARED "Dynamically load ESD audio support" ON "ESD" OFF)
|
||||
set_option(PIPEWIRE "Use Pipewire" ${UNIX_SYS})
|
||||
dep_option(PIPEWIRE_SHARED "Dynamically load Pipewire support" ON "PIPEWIRE" OFF)
|
||||
set_option(PULSEAUDIO "Use PulseAudio" ${UNIX_SYS})
|
||||
dep_option(PULSEAUDIO_SHARED "Dynamically load PulseAudio support" ON "PULSEAUDIO" OFF)
|
||||
set_option(ARTS "Support the Analog Real Time Synthesizer" ${UNIX_SYS})
|
||||
@@ -1165,6 +1167,7 @@ elseif(UNIX AND NOT APPLE AND NOT ANDROID AND NOT RISCOS)
|
||||
CheckOSS()
|
||||
CheckALSA()
|
||||
CheckJACK()
|
||||
CheckPipewire()
|
||||
CheckPulseAudio()
|
||||
CheckESD()
|
||||
CheckARTS()
|
||||
|
||||
@@ -128,6 +128,37 @@ macro(CheckALSA)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Requires:
|
||||
# - PkgCheckModules
|
||||
# Optional:
|
||||
# - PIPEWIRE_SHARED opt
|
||||
# - HAVE_DLOPEN opt
|
||||
macro(CheckPipewire)
|
||||
if(PIPEWIRE)
|
||||
pkg_check_modules(PKG_PIPEWIRE libpipewire-0.3>=0.3.20)
|
||||
if(PKG_PIPEWIRE_FOUND)
|
||||
set(HAVE_PIPEWIRE TRUE)
|
||||
file(GLOB PIPEWIRE_SOURCES ${SDL2_SOURCE_DIR}/src/audio/pipewire/*.c)
|
||||
set(SOURCE_FILES ${SOURCE_FILES} ${PIPEWIRE_SOURCES})
|
||||
set(SDL_AUDIO_DRIVER_PIPEWIRE 1)
|
||||
list(APPEND EXTRA_CFLAGS ${PKG_PIPEWIRE_CFLAGS})
|
||||
if(PIPEWIRE_SHARED)
|
||||
if(NOT HAVE_DLOPEN)
|
||||
message_warn("You must have SDL_LoadObject() support for dynamic Pipewire loading")
|
||||
else()
|
||||
FindLibraryAndSONAME("pipewire-0.3")
|
||||
set(SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC "\"${PIPEWIRE_0.3_LIB_SONAME}\"")
|
||||
set(HAVE_PIPEWIRE_SHARED TRUE)
|
||||
endif()
|
||||
else()
|
||||
list(APPEND EXTRA_LDFLAGS ${PKG_PIPEWIRE_LDFLAGS})
|
||||
endif()
|
||||
set(HAVE_SDL_AUDIO TRUE)
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
|
||||
# Requires:
|
||||
# - PkgCheckModules
|
||||
# Optional:
|
||||
|
||||
@@ -676,6 +676,8 @@ RPI_CFLAGS
|
||||
FUSIONSOUND_LIBS
|
||||
FUSIONSOUND_CFLAGS
|
||||
ARTSCONFIG
|
||||
PIPEWIRE_LIBS
|
||||
PIPEWIRE_CFLAGS
|
||||
PULSEAUDIO_LIBS
|
||||
PULSEAUDIO_CFLAGS
|
||||
ESD_LIBS
|
||||
@@ -838,6 +840,8 @@ with_esd_prefix
|
||||
with_esd_exec_prefix
|
||||
enable_esdtest
|
||||
enable_esd_shared
|
||||
enable_pipewire
|
||||
enable_pipewire_shared
|
||||
enable_pulseaudio
|
||||
enable_pulseaudio_shared
|
||||
enable_arts
|
||||
@@ -923,6 +927,8 @@ PKG_CONFIG_PATH
|
||||
PKG_CONFIG_LIBDIR
|
||||
JACK_CFLAGS
|
||||
JACK_LIBS
|
||||
PIPEWIRE_CFLAGS
|
||||
PIPEWIRE_LIBS
|
||||
PULSEAUDIO_CFLAGS
|
||||
PULSEAUDIO_LIBS
|
||||
FUSIONSOUND_CFLAGS
|
||||
@@ -1605,6 +1611,9 @@ Optional Features:
|
||||
--enable-esd support the Enlightened Sound Daemon [[default=yes]]
|
||||
--disable-esdtest Do not try to compile and run a test ESD program
|
||||
--enable-esd-shared dynamically load ESD audio support [[default=yes]]
|
||||
--enable-pipewire use Pipewire [[default=yes]]
|
||||
--enable-pipewire-shared
|
||||
dynamically load Pipewire support [[default=yes]]
|
||||
--enable-pulseaudio use PulseAudio [[default=yes]]
|
||||
--enable-pulseaudio-shared
|
||||
dynamically load PulseAudio support [[default=yes]]
|
||||
@@ -1732,6 +1741,10 @@ Some influential environment variables:
|
||||
path overriding pkg-config's built-in search path
|
||||
JACK_CFLAGS C compiler flags for JACK, overriding pkg-config
|
||||
JACK_LIBS linker flags for JACK, overriding pkg-config
|
||||
PIPEWIRE_CFLAGS
|
||||
C compiler flags for PIPEWIRE, overriding pkg-config
|
||||
PIPEWIRE_LIBS
|
||||
linker flags for PIPEWIRE, overriding pkg-config
|
||||
PULSEAUDIO_CFLAGS
|
||||
C compiler flags for PULSEAUDIO, overriding pkg-config
|
||||
PULSEAUDIO_LIBS
|
||||
@@ -18778,6 +18791,126 @@ _ACEOF
|
||||
fi
|
||||
}
|
||||
|
||||
CheckPipewire()
|
||||
{
|
||||
# Check whether --enable-pipewire was given.
|
||||
if test "${enable_pipewire+set}" = set; then :
|
||||
enableval=$enable_pipewire;
|
||||
else
|
||||
enable_pipewire=yes
|
||||
fi
|
||||
|
||||
if test x$enable_audio = xyes -a x$enable_pipewire = xyes; then
|
||||
|
||||
pkg_failed=no
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for libpipewire-0.3 >= 0.3.20" >&5
|
||||
$as_echo_n "checking for libpipewire-0.3 >= 0.3.20... " >&6; }
|
||||
|
||||
if test -n "$PIPEWIRE_CFLAGS"; then
|
||||
pkg_cv_PIPEWIRE_CFLAGS="$PIPEWIRE_CFLAGS"
|
||||
elif test -n "$PKG_CONFIG"; then
|
||||
if test -n "$PKG_CONFIG" && \
|
||||
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libpipewire-0.3 >= 0.3.20\""; } >&5
|
||||
($PKG_CONFIG --exists --print-errors "libpipewire-0.3 >= 0.3.20") 2>&5
|
||||
ac_status=$?
|
||||
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
|
||||
test $ac_status = 0; }; then
|
||||
pkg_cv_PIPEWIRE_CFLAGS=`$PKG_CONFIG --cflags "libpipewire-0.3 >= 0.3.20" 2>/dev/null`
|
||||
test "x$?" != "x0" && pkg_failed=yes
|
||||
else
|
||||
pkg_failed=yes
|
||||
fi
|
||||
else
|
||||
pkg_failed=untried
|
||||
fi
|
||||
if test -n "$PIPEWIRE_LIBS"; then
|
||||
pkg_cv_PIPEWIRE_LIBS="$PIPEWIRE_LIBS"
|
||||
elif test -n "$PKG_CONFIG"; then
|
||||
if test -n "$PKG_CONFIG" && \
|
||||
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libpipewire-0.3 >= 0.3.20\""; } >&5
|
||||
($PKG_CONFIG --exists --print-errors "libpipewire-0.3 >= 0.3.20") 2>&5
|
||||
ac_status=$?
|
||||
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
|
||||
test $ac_status = 0; }; then
|
||||
pkg_cv_PIPEWIRE_LIBS=`$PKG_CONFIG --libs "libpipewire-0.3 >= 0.3.20" 2>/dev/null`
|
||||
test "x$?" != "x0" && pkg_failed=yes
|
||||
else
|
||||
pkg_failed=yes
|
||||
fi
|
||||
else
|
||||
pkg_failed=untried
|
||||
fi
|
||||
|
||||
|
||||
|
||||
if test $pkg_failed = yes; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
$as_echo "no" >&6; }
|
||||
|
||||
if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
|
||||
_pkg_short_errors_supported=yes
|
||||
else
|
||||
_pkg_short_errors_supported=no
|
||||
fi
|
||||
if test $_pkg_short_errors_supported = yes; then
|
||||
PIPEWIRE_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libpipewire-0.3 >= 0.3.20" 2>&1`
|
||||
else
|
||||
PIPEWIRE_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libpipewire-0.3 >= 0.3.20" 2>&1`
|
||||
fi
|
||||
# Put the nasty error message in config.log where it belongs
|
||||
echo "$PIPEWIRE_PKG_ERRORS" >&5
|
||||
|
||||
audio_pipewire=no
|
||||
elif test $pkg_failed = untried; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
$as_echo "no" >&6; }
|
||||
audio_pipewire=no
|
||||
else
|
||||
PIPEWIRE_CFLAGS=$pkg_cv_PIPEWIRE_CFLAGS
|
||||
PIPEWIRE_LIBS=$pkg_cv_PIPEWIRE_LIBS
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
||||
$as_echo "yes" >&6; }
|
||||
audio_pipewire=yes
|
||||
fi
|
||||
|
||||
if test x$audio_pipewire = xyes; then
|
||||
# Check whether --enable-pipewire-shared was given.
|
||||
if test "${enable_pipewire_shared+set}" = set; then :
|
||||
enableval=$enable_pipewire_shared;
|
||||
else
|
||||
enable_pipewire_shared=yes
|
||||
fi
|
||||
|
||||
pipewire_lib=`find_lib "libpipewire-0.3.so.*" "$PIPEWIRE_LIBS" | sed 's/.*\/\(.*\)/\1/; q'`
|
||||
|
||||
|
||||
$as_echo "#define SDL_AUDIO_DRIVER_PIPEWIRE 1" >>confdefs.h
|
||||
|
||||
SOURCES="$SOURCES $srcdir/src/audio/pipewire/*.c"
|
||||
EXTRA_CFLAGS="$EXTRA_CFLAGS $PIPEWIRE_CFLAGS"
|
||||
if test x$have_loadso != xyes && \
|
||||
test x$enable_pipewire_shared = xyes; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: You must have SDL_LoadObject() support for dynamic Pipewire loading" >&5
|
||||
$as_echo "$as_me: WARNING: You must have SDL_LoadObject() support for dynamic Pipewire loading" >&2;}
|
||||
fi
|
||||
if test x$have_loadso = xyes && \
|
||||
test x$enable_pipewire_shared = xyes && test x$pipewire_lib != x; then
|
||||
echo "-- dynamic libpipewire-0.3 -> $pipewire_lib"
|
||||
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC "$pipewire_lib"
|
||||
_ACEOF
|
||||
|
||||
SUMMARY_audio="${SUMMARY_audio} pipewire(dynamic)"
|
||||
else
|
||||
EXTRA_LDFLAGS="$EXTRA_LDFLAGS $PIPEWIRE_LIBS"
|
||||
SUMMARY_audio="${SUMMARY_audio} pipewire"
|
||||
fi
|
||||
have_audio=yes
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
CheckPulseAudio()
|
||||
{
|
||||
# Check whether --enable-pulseaudio was given.
|
||||
@@ -24893,6 +25026,7 @@ $as_echo "#define SDL_VIDEO_DRIVER_ANDROID 1" >>confdefs.h
|
||||
CheckNEON
|
||||
CheckOSS
|
||||
CheckALSA
|
||||
CheckPipewire
|
||||
CheckPulseAudio
|
||||
CheckJACK
|
||||
CheckARTSC
|
||||
|
||||
@@ -1017,6 +1017,42 @@ AS_HELP_STRING([--enable-esd-shared], [dynamically load ESD audio support [[defa
|
||||
fi
|
||||
}
|
||||
|
||||
dnl Find Pipewire
|
||||
CheckPipewire()
|
||||
{
|
||||
AC_ARG_ENABLE(pipewire,
|
||||
AS_HELP_STRING([--enable-pipewire], [use Pipewire [[default=yes]]]),
|
||||
, enable_pipewire=yes)
|
||||
if test x$enable_audio = xyes -a x$enable_pipewire = xyes; then
|
||||
PKG_CHECK_MODULES([PIPEWIRE], [libpipewire-0.3 >= 0.3.20], audio_pipewire=yes, audio_pipewire=no)
|
||||
|
||||
if test x$audio_pipewire = xyes; then
|
||||
AC_ARG_ENABLE(pipewire-shared,
|
||||
AS_HELP_STRING([--enable-pipewire-shared], [dynamically load Pipewire support [[default=yes]]]),
|
||||
, enable_pipewire_shared=yes)
|
||||
pipewire_lib=[`find_lib "libpipewire-0.3.so.*" "$PIPEWIRE_LIBS" | sed 's/.*\/\(.*\)/\1/; q'`]
|
||||
|
||||
AC_DEFINE(SDL_AUDIO_DRIVER_PIPEWIRE, 1, [ ])
|
||||
SOURCES="$SOURCES $srcdir/src/audio/pipewire/*.c"
|
||||
EXTRA_CFLAGS="$EXTRA_CFLAGS $PIPEWIRE_CFLAGS"
|
||||
if test x$have_loadso != xyes && \
|
||||
test x$enable_pipewire_shared = xyes; then
|
||||
AC_MSG_WARN([You must have SDL_LoadObject() support for dynamic Pipewire loading])
|
||||
fi
|
||||
if test x$have_loadso = xyes && \
|
||||
test x$enable_pipewire_shared = xyes && test x$pipewire_lib != x; then
|
||||
echo "-- dynamic libpipewire-0.3 -> $pipewire_lib"
|
||||
AC_DEFINE_UNQUOTED(SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC, "$pipewire_lib", [ ])
|
||||
SUMMARY_audio="${SUMMARY_audio} pipewire(dynamic)"
|
||||
else
|
||||
EXTRA_LDFLAGS="$EXTRA_LDFLAGS $PIPEWIRE_LIBS"
|
||||
SUMMARY_audio="${SUMMARY_audio} pipewire"
|
||||
fi
|
||||
have_audio=yes
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
dnl Find PulseAudio
|
||||
CheckPulseAudio()
|
||||
{
|
||||
@@ -3604,6 +3640,7 @@ case "$host" in
|
||||
CheckNEON
|
||||
CheckOSS
|
||||
CheckALSA
|
||||
CheckPipewire
|
||||
CheckPulseAudio
|
||||
CheckJACK
|
||||
CheckARTSC
|
||||
|
||||
@@ -284,6 +284,8 @@
|
||||
#cmakedefine SDL_AUDIO_DRIVER_OSS @SDL_AUDIO_DRIVER_OSS@
|
||||
#cmakedefine SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H @SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H@
|
||||
#cmakedefine SDL_AUDIO_DRIVER_PAUDIO @SDL_AUDIO_DRIVER_PAUDIO@
|
||||
#cmakedefine SDL_AUDIO_DRIVER_PIPEWIRE @SDL_AUDIO_DRIVER_PIPEWIRE@
|
||||
#cmakedefine SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC @SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC@
|
||||
#cmakedefine SDL_AUDIO_DRIVER_PULSEAUDIO @SDL_AUDIO_DRIVER_PULSEAUDIO@
|
||||
#cmakedefine SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC @SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC@
|
||||
#cmakedefine SDL_AUDIO_DRIVER_QSA @SDL_AUDIO_DRIVER_QSA@
|
||||
|
||||
@@ -1610,6 +1610,26 @@ extern "C" {
|
||||
*/
|
||||
#define SDL_HINT_AUDIO_DEVICE_STREAM_NAME "SDL_AUDIO_DEVICE_STREAM_NAME"
|
||||
|
||||
/**
|
||||
* \brief Specify an application role for an audio device.
|
||||
*
|
||||
* Some audio backends (such as Pipewire) allow you to describe the role of
|
||||
* your audio stream. Among other things, this description might show up in
|
||||
* a system control panel or software for displaying and manipulating media
|
||||
* playback/capture graphs.
|
||||
*
|
||||
* This hints lets you transmit that information to the OS. The contents of
|
||||
* this hint are used while opening an audio device. You should use a string
|
||||
* that describes your what your program is playing (Game, Music, Movie,
|
||||
* etc...).
|
||||
*
|
||||
* Setting this to "" or leaving it unset will have SDL use a reasonable
|
||||
* default: "Game" or something similar.
|
||||
*
|
||||
* On targets where this is not supported, this hint does nothing.
|
||||
*/
|
||||
#define SDL_HINT_AUDIO_DEVICE_STREAM_ROLE "SDL_AUDIO_DEVICE_STREAM_ROLE"
|
||||
|
||||
/**
|
||||
* \brief Specify the behavior of Alt+Tab while the keyboard is grabbed.
|
||||
*
|
||||
|
||||
@@ -41,6 +41,9 @@ static const AudioBootStrap *const bootstrap[] = {
|
||||
#if SDL_AUDIO_DRIVER_ALSA
|
||||
&ALSA_bootstrap,
|
||||
#endif
|
||||
#if SDL_AUDIO_DRIVER_PIPEWIRE
|
||||
&PIPEWIRE_bootstrap,
|
||||
#endif
|
||||
#if SDL_AUDIO_DRIVER_SNDIO
|
||||
&SNDIO_bootstrap,
|
||||
#endif
|
||||
@@ -113,6 +116,7 @@ static const AudioBootStrap *const bootstrap[] = {
|
||||
#if SDL_AUDIO_DRIVER_DUMMY
|
||||
&DUMMYAUDIO_bootstrap,
|
||||
#endif
|
||||
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
@@ -182,6 +182,7 @@ typedef struct AudioBootStrap
|
||||
} AudioBootStrap;
|
||||
|
||||
/* Not all of these are available in a given build. Use #ifdefs, etc. */
|
||||
extern AudioBootStrap PIPEWIRE_bootstrap;
|
||||
extern AudioBootStrap PULSEAUDIO_bootstrap;
|
||||
extern AudioBootStrap ALSA_bootstrap;
|
||||
extern AudioBootStrap JACK_bootstrap;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#ifndef SDL_pipewire_h_
|
||||
#define SDL_pipewire_h_
|
||||
|
||||
#include "../SDL_sysaudio.h"
|
||||
#include <pipewire/pipewire.h>
|
||||
|
||||
/* Hidden "this" pointer for the audio functions */
|
||||
#define _THIS SDL_AudioDevice* this
|
||||
|
||||
struct SDL_PrivateAudioData
|
||||
{
|
||||
struct pw_thread_loop* loop;
|
||||
struct pw_stream* stream;
|
||||
struct pw_context* context;
|
||||
|
||||
Sint32 stride; /* Bytes-per-frame */
|
||||
};
|
||||
|
||||
#endif /* SDL_pipewire_h_ */
|
||||
Reference in New Issue
Block a user