Skip to content

Commit

Permalink
Squash test (#2)
Browse files Browse the repository at this point in the history
* Preparation to start patching - TODOS and directory src/hostapi/Oboe

* Added src/hostapi/oboe/README.md

* Added include/pa_oboe.h and src/hostapi/oboe/pa_oboe.cpp

* Added PA_USE_OBOE section to CMakeLists.txt

* Added PA_USE_OBOE section to CMakeLists.txt

* Heavily reworked CMake dependencies, added FindOboe.cmake, updated pa_oboe.cpp, more work needed

* Included build_all_PaOboe.sh, more work needed on CMake

* Included build_all_PaOboe.sh, more work needed on CMake

* Update src/hostapi/oboe/README.md

* bindings/cpp: CMake: support pkgconfig with RelWithDebInfo (PortAudio#822)

bindings/cpp: add  `RelWithDebInfo` to the configurations allowed to install portaudiocpp.pc, otherwise you won't have support for pkg-config when building a release package with separate debugging information. Besides that, RelWithDebInfo is identical to Release.

* Fix MSVC warning C4018 signed/unsigned mismatch (PortAudio#821)

See PortAudio#810

* Built shared library

* Polished bits

* mme: don't restrict the host buffer to 16-bit

Currently, the MME Host API code only creates 16-bit integer MME
buffers. All audio data provided by the user is therefore converted by
PortAudio to and from 16-bit, regardless of the user buffer format.

This basically makes it impossible to pass 24-bit audio through the
MME Host API.

If the user buffer format is not 16-bit, this also causes pointless
conversions to take place, *even if the hardware is running at 16-bit*,
because modern Windows versions (Vista+) convert the data to floating
point behind the scenes before it is handed off to the hardware. This
can lead to silly situations where 32-bit float samples from the user
are (lossily) converted to 16-bit by PortAudio, then ended off to
Windows via MME, only to be converted back to 32-bit float again, before
finally being converted to the format the hardware device is configured
to use. This can easily lead to two layers of 16-bit dithering (one from
PortAudio, and one from Windows) being piled on top of each other,
resulting in an elevated noise floor.

This commit fixes this problem by configuring the MME buffers to use the
same format as the user buffer. This should stop PortAudio from
converting samples in all cases except paInt8, which is not supported by
WAVEFORMATEX (only paUInt8 is). This is pretty much the same idea as
PortAudio#774.

The new code assumes that MME will accept whatever format we throw at
it. I feel confident that this is always true on Vista+ regardless of
hardware, because starting from Vista MME does not access hardware
directly - it always goes through the Windows Audio Engine which
supports all formats in both directions (I verified this using
paloopback).

On pre-Vista Windows, this should still work all the way back to Windows
98 SE, because MME goes through KMixer which supports all formats [1].
Nevertheless, it's difficult to be sure, so this code checks the Windows
version it's running on and preserves the old behavior (i.e. always use
Int16) on pre-Vista Windows.

[1]: https://learn.microsoft.com/en-us/windows-hardware/drivers/audio/background-of-non-pcm-support#waveout-api

Fixes PortAudio#139

* Don't use absolute path when linking to macOS frameworks (PortAudio#829)

fixes PortAudio#828

* Fixing old problems

* Added some debug messages

* added new build script

* Added paOboe in the paHostApi array

* Added paOboe in pa_unix_hostapis.c

* Working patch

* win: New PaWinUtil_GetOsVersion() function for getting Windows OS version. Refactored WASAPI, DS, MME and WDMKS host back-ends to use PaWinUtil_GetOsVersion() instead of direct OS API.

* Ready for other users to compile/build

* Updated oboe/Readme.md

* Added sharing mode selection

* Fixed minor issue with sharing mode selection

* Removed references to KCTI

* Fixed error callback, added performance mode autoselection

* Minor change to CMakeLists, added low latency costant in pa_oboe.h

* Deleted Build_PaOboe.sh

* Ready to push (removed my paths to Oboe directory and Android NDK)

* Update README.md

* Update README.md

* remove all alternative sample conversion code using lrintf in pa_converters.c (PortAudio#403)

removes the code guarded by PA_USE_C99_LRINTF
See PortAudio#390

* updated readme

* fixed CMakeLists.txt

* fixed FindOboe.cmake

* Preparation to start patching - TODOS and directory src/hostapi/Oboe

* Added src/hostapi/oboe/README.md

* Added include/pa_oboe.h and src/hostapi/oboe/pa_oboe.cpp

* Added PA_USE_OBOE section to CMakeLists.txt

* Added PA_USE_OBOE section to CMakeLists.txt

* Heavily reworked CMake dependencies, added FindOboe.cmake, updated pa_oboe.cpp, more work needed

* Included build_all_PaOboe.sh, more work needed on CMake

* Included build_all_PaOboe.sh, more work needed on CMake

* Built shared library

* Polished bits

* Fixing old problems

* Added some debug messages

* added new build script

* Added paOboe in the paHostApi array

* Added paOboe in pa_unix_hostapis.c

* Working patch

* Ready for other users to compile/build

* Updated oboe/Readme.md

* Added sharing mode selection

* Fixed minor issue with sharing mode selection

* Removed references to KCTI

* Fixed error callback, added performance mode autoselection

* Minor change to CMakeLists, added low latency costant in pa_oboe.h

* Deleted Build_PaOboe.sh

* Ready to push (removed my paths to Oboe directory and Android NDK)

* Update src/hostapi/oboe/README.md

* Update README.md

* Update README.md

* updated readme

* fixed CMakeLists.txt

* fixed FindOboe.cmake

* corrected oboe/Readme.md

* Updated oboe/Readme.md

* PulseAudio Portaudio HostAPI (PortAudio#336)

Adds support for PulseAudio API on Linux.

For more information about Pulseaudio visit: https://www.freedesktop.org/wiki/Software/PulseAudio/

---------

Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Co-authored-by: sqweek <sqweek@gmail.com>
Co-authored-by: Daniel Schürmann <daschuer@mixxx.org>
Co-authored-by: Mooneer Salem <mooneer@gmail.com>
Co-authored-by: Be <be.0@gmx.com>
Co-authored-by: Mario Kleiner <mario.kleiner.de@gmail.com>

* pulseaudio: Move Pulseaudio include in correct place when using autoconf (PortAudio#843)

As Jack and Pulseaudio both needs Ringbuffer that include can
be done in same place. In configure.in also Pulseaudio header
file was included before it was sure that it was really needed.

Commit makes sure that Pulseaudio include is available only if
it's needed as it can cause failing in build if Pulseaudio
develoment files are not available.

* added .idea to gitignore

* added .idea to gitignore

* restored workflows directory

* Minor fixes to FindOboe.cmake

* Enhanced prebuilt libraries compatibility in FindOboe.cmake

* Minor changes to Pa_Oboe/Readme and pa_oboe.cpp

* Removed auto latency tuning in favor of simpler impleentation in pa_oboe.cpp

* Set paFloat32 as default format in pa_oboe.cpp

* Renamed most of the variables according to best coding practices.

* Added separate callback class to fix the single-stream issue.

* Modified OboeEngine accordingly

* Adjusted the code in the rest of pa_oboe.cpp

* Removed stop and close phases of OboeEngine::restartStream

* Updated functions' description

* minor description corrections

* fixed all compiling errors generated by typos

* Added OboeMediator class in place of OboeCallback, that mediates PortAudio C stream struct and the C++ OboeEngine class

* Fixed allocation problem, working PaOboe implementation

* Fix 'pulseaudioHostApi' use-after-free/null ptr deref in PaPulseAudio_Initialize (PortAudio#847)

The call to PaPulseAudio_UnLock( pulseaudioHostApi->mainloop ) in error-label is performed on 'pulseaudioHostApi' after 'pulseaudioHostApi' has been freed by PaPulseAudio_Free and set to NULL.

* wdmks: declare GUIDs with selectany attribute (PortAudio#846)

* wdmks: declare GUIDs with selectany attribute

Match the behavior of guiddef.h in both mingw and the Windows SDK headers. This prevents linking errors caused by multiply defined symbols when linking against certain Windows SDK libs (like dxguid.lib).

* Make sure this works even if DECLSPEC_SELECTANY is not defined

---------

Co-authored-by: Ross Bencina <rossb@audiomulch.com>

* fixed README.md indenting

* Removed .idea folder from repo

* replaced 'g_' with 'paOboe_' in non-static global variables

* replaced 'm_' prefix with 'm' prefix

* fixed OboeEngine::tryStream as requested

* PulseAudio Portaudio HostAPI (PortAudio#336)

Adds support for PulseAudio API on Linux.

For more information about Pulseaudio visit: https://www.freedesktop.org/wiki/Software/PulseAudio/

---------

Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Co-authored-by: sqweek <sqweek@gmail.com>
Co-authored-by: Daniel Schürmann <daschuer@mixxx.org>
Co-authored-by: Mooneer Salem <mooneer@gmail.com>
Co-authored-by: Be <be.0@gmx.com>
Co-authored-by: Mario Kleiner <mario.kleiner.de@gmail.com>

* pulseaudio: Move Pulseaudio include in correct place when using autoconf (PortAudio#843)

As Jack and Pulseaudio both needs Ringbuffer that include can
be done in same place. In configure.in also Pulseaudio header
file was included before it was sure that it was really needed.

Commit makes sure that Pulseaudio include is available only if
it's needed as it can cause failing in build if Pulseaudio
develoment files are not available.

* restored workflows directory

* Minor fixes to FindOboe.cmake

* Enhanced prebuilt libraries compatibility in FindOboe.cmake

* Minor changes to Pa_Oboe/Readme and pa_oboe.cpp

* Removed auto latency tuning in favor of simpler impleentation in pa_oboe.cpp

* Set paFloat32 as default format in pa_oboe.cpp

* Renamed most of the variables according to best coding practices.

* Added separate callback class to fix the single-stream issue.

* Modified OboeEngine accordingly

* Adjusted the code in the rest of pa_oboe.cpp

* Removed stop and close phases of OboeEngine::restartStream

* Updated functions' description

* minor description corrections

* fixed all compiling errors generated by typos

* Added OboeMediator class in place of OboeCallback, that mediates PortAudio C stream struct and the C++ OboeEngine class

* Fixed allocation problem, working PaOboe implementation

* fixed README.md indenting

* Removed .idea folder from repo

* replaced 'g_' with 'paOboe_' in non-static global variables

* replaced 'm_' prefix with 'm' prefix

* fixed OboeEngine::tryStream as requested

* Changed names to improve readability, i.e. OboeStream -> PaOboeStream

* fixed all compiling errors generated by typos

* Fixed minor problem with TryStream

* fixed long line in FindOboe.cmake

* fixed typos in pa_oboe.cpp

* set to verbose some logs

* Fixed minor problem with TryStream

* fixed long line in FindOboe.cmake

* fixed typos in pa_oboe.cpp

* set to verbose some logs

* Better handling of format in paOboe, removed junk code from CMakeLists

* Improved readability of some variables

* Removed '#include oboe/Oboe.h' from pa_oboe.h, and modified host api implementation accordingly

* static cast fixes

---------

Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Co-authored-by: Carlo Benfatti <benfatti@netresults.it>
Co-authored-by: hopefulGiupplo <116260612+hopefulGiupplo@users.noreply.github.com>
Co-authored-by: Carlo Bramini <30959007+carlo-bramini@users.noreply.github.com>
Co-authored-by: Etienne Dechamps <etienne@edechamps.fr>
Co-authored-by: Daniel Schürmann <daschuer@mixxx.org>
Co-authored-by: dmitrykos <dmitrykos@neutroncode.com>
Co-authored-by: Ross Bencina <rossb@audiomulch.com>
Co-authored-by: Tuukka Pasanen <pasanen.tuukka@gmail.com>
Co-authored-by: sqweek <sqweek@gmail.com>
Co-authored-by: Mooneer Salem <mooneer@gmail.com>
Co-authored-by: Be <be.0@gmx.com>
Co-authored-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Co-authored-by: Tuukka Pasanen <tuukka.pasanen@ilmi.fi>
Co-authored-by: invertego <invertego@users.noreply.github.com>
  • Loading branch information
15 people authored Mar 6, 2024
1 parent cb8d3dc commit 2a4167e
Show file tree
Hide file tree
Showing 38 changed files with 6,141 additions and 463 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ libtool
portaudio-2.0.pc
autom4te.cache/*

# build_all_PaOboe.sh CMake output folder
build
build_old

# Precompiled Headers
*.gch
*.pch
Expand Down Expand Up @@ -54,5 +58,7 @@ CMakeSettings.json
# VSCode
.vscode*

# idea
.idea*

# Common build directories of users and VSCode
build*
317 changes: 182 additions & 135 deletions CMakeLists.txt

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ PALIB = libportaudio.la
PAINC = include/portaudio.h

PA_LDFLAGS = $(LDFLAGS) $(SHARED_FLAGS) -rpath $(libdir) -no-undefined \
-export-symbols-regex "(Pa|PaMacCore|PaJack|PaAlsa|PaAsio|PaOSS|PaWasapi|PaWasapiWinrt|PaWinMME)_.*" \
-export-symbols-regex "(Pa|PaMacCore|PaPulseAudio|PaJack|PaAlsa|PaAsio|PaOSS|PaWasapi|PaWasapiWinrt|PaWinMME)_.*" \
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)

COMMON_OBJS = \
Expand All @@ -66,7 +66,7 @@ LOOPBACK_OBJS = \
qa/loopback/src/test_audio_analyzer.o \
qa/loopback/src/write_wav.o \
qa/loopback/src/paqa.o

EXAMPLES = \
bin/pa_devs \
bin/pa_fuzz \
Expand All @@ -82,7 +82,7 @@ SELFTESTS = \
bin/paqa_devs \
bin/paqa_errs \
bin/paqa_latency

TESTS = \
bin/patest1 \
bin/patest_buffer \
Expand Down Expand Up @@ -146,6 +146,7 @@ SRC_DIRS = \
src/hostapi/coreaudio \
src/hostapi/dsound \
src/hostapi/jack \
src/hostapi/pulseaudio \
src/hostapi/oss \
src/hostapi/skeleton \
src/hostapi/wasapi \
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Please feel free to join. See http://www.portaudio.com for details.
src/os = os specific (but host api neutral) code
src/hostapi = implementations for different host apis


### Host API Implementations:

src/hostapi/alsa = Advanced Linux Sound Architecture (ALSA)
Expand All @@ -40,7 +39,9 @@ Please feel free to join. See http://www.portaudio.com for details.
src/hostapi/coreaudio = Macintosh Core Audio for OS X
src/hostapi/dsound = Windows Direct Sound
src/hostapi/jack = JACK Audio Connection Kit
src/hostapi/oboe = Oboe Library for Android (see src/hostapi/oboe/README.md)
src/hostapi/oss = Unix Open Sound System (OSS)
src/hostapi/pulseaudio = Sound system for POSIX OSes
src/hostapi/wasapi = Windows Vista WASAPI
src/hostapi/wdmks = Windows WDM Kernel Streaming
src/hostapi/wmme = Windows MultiMedia Extensions (MME)
Expand Down
2 changes: 1 addition & 1 deletion bindings/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,5 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/PortAudioCppConfig.cmake"
set(PC_PREFIX "\${pcfiledir}/../..")
configure_file(cmake/portaudiocpp.pc.in "${CMAKE_CURRENT_BINARY_DIR}/portaudiocpp.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/portaudiocpp.pc"
CONFIGURATIONS Release
CONFIGURATIONS Release RelWithDebInfo
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
46 changes: 46 additions & 0 deletions build_all_PaOboe.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
# Script used to build Portaudio for multiple Android ABIs, useful for its Oboe host API.
#
# Ensure that ANDROID_NDK environment variable is set to your Android NDK location
# e.g. /Library/Android/sdk/ndk-bundle

if [ -z "$ANDROID_NDK" ]; then
echo "Please set ANDROID_NDK to the Android NDK folder"
exit 1
fi

# Build directory
BUILD_DIR=build

CMAKE_ARGS="-H. \
-DBUILD_SHARED_LIBS=true \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DANDROID_TOOLCHAIN=clang \
-DANDROID_STL=c++_shared \
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake \
-DCMAKE_INSTALL_PREFIX=."

function build_PaOboe {

ABI=$1
MINIMUM_API_LEVEL=$2
ABI_BUILD_DIR=${BUILD_DIR}/${ABI}

echo "Building Pa_Oboe for ${ABI}"

mkdir -p ${ABI_BUILD_DIR} ${ABI_BUILD_DIR}/${STAGING_DIR}

cmake -B${ABI_BUILD_DIR} \
-DANDROID_ABI=${ABI} \
-DANDROID_PLATFORM=android-${MINIMUM_API_LEVEL}\
${CMAKE_ARGS}

pushd ${ABI_BUILD_DIR}
make -j5
popd
}

#build_PaOboe armeabi-v7a 16
build_PaOboe arm64-v8a 21
#build_PaOboe x86 16
build_PaOboe x86_64 21
74 changes: 74 additions & 0 deletions cmake/modules/FindOboe.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#[=======================================================================[.rst:
Findoboe
--------

Finds the oboe library. OBOE_DIRECTORY has to be set to the path of the directory where
the oboe repository was cloned (see src/hostapi/oboe/README.md for more information).

Imported Targets
^^^^^^^^^^^^^^^^

This module provides the following imported target, if found:

``Oboe::oboe``
The OBOE library

#]=======================================================================]

if(NOT DEFINED OBOE_DIRECTORY)
#Insert the path of the directory where you cloned Oboe, i.e. ${CMAKE_CURRENT_SOURCE_DIR}/../oboe
set(OBOE_DIRECTORY FALSE)
endif()

if(NOT OBOE_DIRECTORY)
message(AUTHOR_WARNING
"If you're trying to use Oboe as a Host API, please specify the directory where you "
"cloned its repository. For further information, please read src/hostapi/oboe/README.md"
)
set(OBOE_FOUND FALSE)
else()
if(NOT DEFINED OBOE_INCLUDE_DIR)
set(OBOE_INCLUDE_DIR ${OBOE_DIRECTORY}/include)
endif()

if(NOT DEFINED OBOE_LIBRARY_DIRS)
set(OBOE_LIBRARY_DIRS ${OBOE_DIRECTORY}/build/${ANDROID_ABI})
endif()
set(OBOE_LIBRARIES ${OBOE_LIBRARY_DIRS}/liboboe.so)

find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_check_modules(OBOE Oboe)
else()
find_library(OBOE_LIBRARIES
NAMES liboboe.so
HINTS ${OBOE_LIBRARY_DIRS}
DOC "Oboe Library"
)
find_path(OBOE_INCLUDE_DIR
NAMES oboe/Oboe.h
DOC "Oboe header"
)
endif()

find_library(LOG_LIBRARY log) #used by pa_oboe.cpp and pa_oboe.h as a logging tool

set(OBOE_LINK_LIBRARIES ${OBOE_LIBRARIES} ${LOG_LIBRARY})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
Oboe
DEFAULT_MSG
OBOE_LINK_LIBRARIES
OBOE_INCLUDE_DIR
)

if(OBOE_INCLUDE_DIR AND OBOE_LINK_LIBRARIES)
set(OBOE_FOUND TRUE)
if(NOT TARGET Oboe::oboe)
add_library(Oboe::oboe INTERFACE IMPORTED GLOBAL)
target_link_libraries(Oboe::oboe INTERFACE "${OBOE_LINK_LIBRARIES}")
target_include_directories(Oboe::oboe INTERFACE "${OBOE_INCLUDE_DIR}")
endif()
endif()
endif()
147 changes: 147 additions & 0 deletions cmake/modules/FindPulseAudio.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# Copyright 2008 Matthias Kretz <kretz@kde.org>
# Copyright 2009 Marcus Hufgard <Marcus.Hufgard@hufgard.de>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# SPDX-FileCopyrightText: 2008 Matthias Kretz <kretz@kde.org>
# SPDX-FileCopyrightText: 2009 Marcus Hufgard <Marcus.Hufgard@hufgard.de>
#
# SPDX-License-Identifier: BSD-3-Clause

#.rst:
# FindPulseAudio
# --------------
#
# This is base on
# https://invent.kde.org/frameworks/extra-cmake-modules/-/blob/master/find-modules/FindPulseAudio.cmake
#
# Try to locate the PulseAudio library.
# If found, this will define the following variables:
#
# ``PulseAudio_FOUND``
# True if the system has the PulseAudio library of at least
# the minimum version specified by either the version parameter
# to find_package() or the variable PulseAudio_MINIMUM_VERSION
# ``PulseAudio_INCLUDE_DIRS``
# The PulseAudio include directory
# ``PulseAudio_LIBRARIES``
# The PulseAudio libraries for linking
# ``PulseAudio_MAINLOOP_LIBRARY``
# The libraries needed to use PulseAudio Mainloop
# ``PulseAudio_VERSION``
# The version of PulseAudio that was found
# ``PulseAudio_INCLUDE_DIR``
# Deprecated, use ``PulseAudio_INCLUDE_DIRS``
# ``PulseAudio_LIBRARY``
# Deprecated, use ``PulseAudio_LIBRARIES``
#
# If ``PulseAudio_FOUND`` is TRUE, it will also define the following
# imported target:
#
# ``PulseAudio::PulseAudio``
# The PulseAudio library
#
# Since 5.41.0.

# Support PulseAudio_MINIMUM_VERSION for compatibility:
if(NOT PulseAudio_FIND_VERSION)
set(PulseAudio_FIND_VERSION "${PulseAudio_MINIMUM_VERSION}")
endif()

# the minimum version of PulseAudio we require
if(NOT PulseAudio_FIND_VERSION)
set(PulseAudio_FIND_VERSION "1.0.0")
endif()

find_package(PkgConfig)
pkg_check_modules(PC_PulseAudio QUIET libpulse>=${PulseAudio_FIND_VERSION})
pkg_check_modules(PC_PulseAudio_MAINLOOP QUIET libpulse-mainloop-glib)

find_path(PulseAudio_INCLUDE_DIRS pulse/pulseaudio.h
HINTS
${PC_PulseAudio_INCLUDEDIR}
${PC_PulseAudio_INCLUDE_DIRS}
)

find_library(PulseAudio_LIBRARIES NAMES pulse libpulse
HINTS
${PC_PulseAudio_LIBDIR}
${PC_PulseAudio_LIBRARY_DIRS}
)

find_library(PulseAudio_MAINLOOP_LIBRARY
NAMES pulse-mainloop pulse-mainloop-glib libpulse-mainloop-glib
HINTS
${PC_PulseAudio_LIBDIR}
${PC_PulseAudio_LIBRARY_DIRS}
)

# Store the version number in the cache,
# so we don't have to search every time again:
if(PulseAudio_INCLUDE_DIRS AND NOT PulseAudio_VERSION)

# get PulseAudio's version from its version.h
file(STRINGS "${PulseAudio_INCLUDE_DIRS}/pulse/version.h" pulse_version_h
REGEX ".*pa_get_headers_version\\(\\).*")
string(REGEX REPLACE ".*pa_get_headers_version\\(\\)\ \\(\"([0-9]+\\.[0-9]+\\.[0-9]+)[^\"]*\"\\).*" "\\1"
_PulseAudio_VERSION "${pulse_version_h}")

set(PulseAudio_VERSION "${_PulseAudio_VERSION}"
CACHE STRING "Version number of PulseAudio"
FORCE)
endif()

# Use the new extended syntax of
# find_package_handle_standard_args(),
# which also handles version checking:
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(PulseAudio
REQUIRED_VARS PulseAudio_LIBRARIES
PulseAudio_INCLUDE_DIRS
VERSION_VAR PulseAudio_VERSION)

# Deprecated synonyms
set(PulseAudio_INCLUDE_DIR "${PulseAudio_INCLUDE_DIRS}")
set(PulseAudio_LIBRARY "${PulseAudio_LIBRARIES}")
set(PulseAudio_MAINLOOP_LIBRARY "${PulseAudio_MAINLOOP_LIBRARY}")
set(PulseAudio_FOUND "${PulseAudio_FOUND}")

if(PulseAudio_FOUND AND NOT TARGET PulseAudio::PulseAudio)
add_library(PulseAudio::PulseAudio UNKNOWN IMPORTED)
set_target_properties(PulseAudio::PulseAudio PROPERTIES
IMPORTED_LOCATION "${PulseAudio_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${PulseAudio_INCLUDE_DIRS}")
endif()

mark_as_advanced(PulseAudio_INCLUDE_DIRS PulseAudio_INCLUDE_DIR
PulseAudio_LIBRARIES PulseAudio_LIBRARY
PulseAudio_MAINLOOP_LIBRARY PulseAudio_MAINLOOP_LIBRARY)

include(FeatureSummary)
set_package_properties(PulseAudio PROPERTIES
URL "https://www.freedesktop.org/wiki/Software/PulseAudio"
DESCRIPTION "Sound server, for sound stream routing and mixing")
Loading

0 comments on commit 2a4167e

Please sign in to comment.