Sound (FreeBSD): new impl; drop pulseaudio dep

This commit is contained in:
Carter Li 2024-01-16 11:06:07 +08:00 committed by 李通洲
parent 1227799a38
commit 861eea5899
No known key found for this signature in database
GPG Key ID: 79D0E1C4B64C86A0
2 changed files with 41 additions and 2 deletions

View File

@ -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)

View File

@ -0,0 +1,38 @@
#include "sound.h"
#include <mixer.h>
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;
}