From 861eea5899eb0c484a6e9c964f411c1eef426dfe Mon Sep 17 00:00:00 2001 From: Carter Li Date: Tue, 16 Jan 2024 11:06:07 +0800 Subject: [PATCH] Sound (FreeBSD): new impl; drop pulseaudio dep --- CMakeLists.txt | 5 +++-- src/detection/sound/sound_bsd.c | 38 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 src/detection/sound/sound_bsd.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d34761b2..3b080fa15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,7 +66,7 @@ cmake_dependent_option(ENABLE_OSMESA "Enable osmesa" ON "LINUX OR BSD" OFF) cmake_dependent_option(ENABLE_OPENCL "Enable opencl" ON "LINUX OR BSD OR WIN32" OFF) cmake_dependent_option(ENABLE_LIBNM "Enable libnm" ON "LINUX" OFF) cmake_dependent_option(ENABLE_FREETYPE "Enable freetype" ON "ANDROID" OFF) -cmake_dependent_option(ENABLE_PULSE "Enable pulse" ON "LINUX OR BSD" OFF) +cmake_dependent_option(ENABLE_PULSE "Enable pulse" ON "LINUX" OFF) cmake_dependent_option(ENABLE_DDCUTIL "Enable ddcutil" ON "LINUX" OFF) cmake_dependent_option(ENABLE_DIRECTX_HEADERS "Enable DirectX headers for WSL" ON "LINUX" OFF) cmake_dependent_option(ENABLE_THREADS "Enable multithreading" ON "Threads_FOUND" OFF) @@ -533,7 +533,7 @@ elseif(BSD) src/detection/poweradapter/poweradapter_nosupport.c src/detection/processes/processes_bsd.c src/detection/gtk_qt/qt.c - src/detection/sound/sound_linux.c + src/detection/sound/sound_bsd.c src/detection/swap/swap_bsd.c src/detection/temps/temps_bsd.c src/detection/terminalfont/terminalfont_linux.c @@ -954,6 +954,7 @@ elseif(BSD) PRIVATE "m" PRIVATE "usbhid" PRIVATE "geom" + PRIVATE "mixer" ) elseif(ANDROID) CHECK_LIBRARY_EXISTS(-l:libandroid-wordexp.a wordexp "" HAVE_LIBANDROID_WORDEXP_STATIC) diff --git a/src/detection/sound/sound_bsd.c b/src/detection/sound/sound_bsd.c new file mode 100644 index 000000000..f6077818e --- /dev/null +++ b/src/detection/sound/sound_bsd.c @@ -0,0 +1,38 @@ +#include "sound.h" + +#include + +const char* ffDetectSound(FFlist* devices) +{ + int nmixers = mixer_get_nmixers(); + if (nmixers == 0) return "No mixers found"; + + if (__builtin_expect(nmixers > 9, false)) nmixers = 9; + + char path[] = "/dev/mixer0"; + + for (int idev = 0; idev < nmixers; ++idev) + { + path[strlen("/dev/mixer")] = (char) ('0' + idev); + struct mixer* m = mixer_open(path); + if (!m) continue; + + if (m->mode & MIX_MODE_PLAY) + { + struct mix_dev* dev = mixer_get_dev_byname(m, "vol"); + if (dev) + { + FFSoundDevice* device = ffListAdd(devices); + ffStrbufInitS(&device->identifier, path); + ffStrbufInitF(&device->name, "%s %s", m->ci.longname, m->ci.hw_info); + device->volume = MIX_ISMUTE(m, dev->devno) ? 0 : (uint8_t) MIX_VOLDENORM((dev->vol.left + dev->vol.right) / 2); + device->active = true; + device->main = !!m->f_default; + } + } + + mixer_close(m); + } + + return NULL; +}