Skip to content

Commit

Permalink
Meta: Consolidate checking for the system audio backend
Browse files Browse the repository at this point in the history
The goal here is to ensure we check for audio backends in a way that
makes sense. On macOS, let's just always use Audio Unit (and thus avoid
any checks for Pulse, to reduce needless/confusing build log noise). We
will also only use the Qt audio backend if no other backend was found,
rather than only checking for Pulse.
  • Loading branch information
trflynn89 committed Dec 23, 2024
1 parent 86fae59 commit 6b0b91b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 19 deletions.
16 changes: 7 additions & 9 deletions Libraries/LibMedia/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include(audio)

if (NOT ANDROID AND NOT WIN32)
include(ffmpeg)
include(pulseaudio)
endif()

set(SOURCES
Expand Down Expand Up @@ -30,23 +31,20 @@ else()
target_sources(LibMedia PRIVATE FFmpeg/FFmpegVideoDecoderStub.cpp)
endif()

# Audio backend -- how we output audio to the speakers
if (HAVE_PULSEAUDIO)
if (LADYBIRD_AUDIO_BACKEND STREQUAL "PULSE")
target_sources(LibMedia PRIVATE
Audio/PlaybackStreamPulseAudio.cpp
Audio/PulseAudioWrappers.cpp
)
target_link_libraries(LibMedia PRIVATE PkgConfig::PULSEAUDIO)
target_compile_definitions(LibMedia PUBLIC HAVE_PULSEAUDIO=1)
elseif (APPLE AND NOT IOS)
elseif (LADYBIRD_AUDIO_BACKEND STREQUAL "AUDIO_UNIT")
target_sources(LibMedia PRIVATE Audio/PlaybackStreamAudioUnit.cpp)

find_library(AUDIO_UNIT AudioUnit REQUIRED)
target_link_libraries(LibMedia PRIVATE ${AUDIO_UNIT})
elseif (ANDROID)
elseif (LADYBIRD_AUDIO_BACKEND STREQUAL "OBOE")
target_sources(LibMedia PRIVATE Audio/PlaybackStreamOboe.cpp)
find_package(oboe REQUIRED CONFIG)
target_link_libraries(LibMedia PRIVATE log oboe::oboe)
else()
message(WARNING "No audio backend available")
elseif (DEFINED LADYBIRD_AUDIO_BACKEND)
message(FATAL_ERROR "Please update ${CMAKE_CURRENT_LIST_FILE} for audio backend ${LADYBIRD_AUDIO_BACKEND}")
endif()
20 changes: 20 additions & 0 deletions Meta/CMake/audio.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
include_guard()

# Audio backend -- how we output audio to the speakers.
if (APPLE AND NOT IOS)
set(LADYBIRD_AUDIO_BACKEND "AUDIO_UNIT")
return()
elseif (ANDROID)
set(LADYBIRD_AUDIO_BACKEND "OBOE")
return()
elseif (NOT WIN32)
find_package(PkgConfig REQUIRED)
pkg_check_modules(PULSEAUDIO IMPORTED_TARGET libpulse)

if (PULSEAUDIO_FOUND)
set(LADYBIRD_AUDIO_BACKEND "PULSE")
return()
endif()
endif()

message(WARNING "No audio backend available")
8 changes: 0 additions & 8 deletions Meta/CMake/pulseaudio.cmake

This file was deleted.

4 changes: 2 additions & 2 deletions Services/WebContent/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include(pulseaudio)
include(audio)

set(SOURCES
ConnectionFromClient.cpp
Expand Down Expand Up @@ -35,7 +35,7 @@ if (ENABLE_QT)
target_link_libraries(WebContent PRIVATE Qt::Core)
target_compile_definitions(WebContent PRIVATE HAVE_QT=1)

if (NOT HAVE_PULSEAUDIO)
if (NOT DEFINED LADYBIRD_AUDIO_BACKEND)
find_package(Qt6 REQUIRED COMPONENTS Multimedia)

target_sources(WebContent PRIVATE
Expand Down
6 changes: 6 additions & 0 deletions Tests/LibMedia/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include(audio)

set(TEST_SOURCES
TestH264Decode.cpp
TestParseMatroska.cpp
Expand All @@ -10,3 +12,7 @@ set(TEST_SOURCES
foreach(source IN LISTS TEST_SOURCES)
lagom_test("${source}" LibMedia LIBS LibMedia LibFileSystem WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
endforeach()

if (LADYBIRD_AUDIO_BACKEND STREQUAL "PULSE")
target_compile_definitions(TestPlaybackStream PRIVATE HAVE_PULSEAUDIO=1)
endif()

0 comments on commit 6b0b91b

Please sign in to comment.