Skip to content

Commit c8f28e4

Browse files
committed
Sound (FreeBSD): don't use mixer.h
It's only supported in FreeBSD 14 and later
1 parent 861eea5 commit c8f28e4

File tree

2 files changed

+35
-26
lines changed

2 files changed

+35
-26
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,6 @@ elseif(BSD)
954954
PRIVATE "m"
955955
PRIVATE "usbhid"
956956
PRIVATE "geom"
957-
PRIVATE "mixer"
958957
)
959958
elseif(ANDROID)
960959
CHECK_LIBRARY_EXISTS(-l:libandroid-wordexp.a wordexp "" HAVE_LIBANDROID_WORDEXP_STATIC)

src/detection/sound/sound_bsd.c

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,47 @@
11
#include "sound.h"
2+
#include "common/io/io.h"
3+
#include "common/sysctl.h"
24

3-
#include <mixer.h>
5+
#include <fcntl.h>
6+
#include <sys/soundcard.h>
47

58
const char* ffDetectSound(FFlist* devices)
69
{
7-
int nmixers = mixer_get_nmixers();
8-
if (nmixers == 0) return "No mixers found";
9-
10-
if (__builtin_expect(nmixers > 9, false)) nmixers = 9;
11-
1210
char path[] = "/dev/mixer0";
11+
int defaultDev = ffSysctlGetInt("hw.snd.default_unit", -1);
1312

14-
for (int idev = 0; idev < nmixers; ++idev)
13+
for (int idev = 0; idev <= 9; ++idev)
1514
{
1615
path[strlen("/dev/mixer")] = (char) ('0' + idev);
17-
struct mixer* m = mixer_open(path);
18-
if (!m) continue;
19-
20-
if (m->mode & MIX_MODE_PLAY)
21-
{
22-
struct mix_dev* dev = mixer_get_dev_byname(m, "vol");
23-
if (dev)
24-
{
25-
FFSoundDevice* device = ffListAdd(devices);
26-
ffStrbufInitS(&device->identifier, path);
27-
ffStrbufInitF(&device->name, "%s %s", m->ci.longname, m->ci.hw_info);
28-
device->volume = MIX_ISMUTE(m, dev->devno) ? 0 : (uint8_t) MIX_VOLDENORM((dev->vol.left + dev->vol.right) / 2);
29-
device->active = true;
30-
device->main = !!m->f_default;
31-
}
32-
}
33-
34-
mixer_close(m);
16+
FF_AUTO_CLOSE_FD int fd = open(path, O_RDWR);
17+
if (fd < 0) break;
18+
19+
uint32_t devmask = 0;
20+
if (ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devmask) < 0)
21+
continue;
22+
if (!((1 << SOUND_MIXER_VOLUME) & devmask))
23+
continue;
24+
25+
uint32_t mutemask = 0;
26+
if (ioctl(fd, SOUND_MIXER_READ_MUTE, &mutemask) < 0)
27+
continue;
28+
29+
struct oss_card_info ci = { .card = idev };
30+
if (ioctl(fd, SNDCTL_CARDINFO, &ci) < 0)
31+
continue;
32+
33+
uint32_t volume;
34+
if (ioctl(fd, MIXER_READ(SOUND_MIXER_VOLUME), &volume) < 0)
35+
continue;
36+
37+
FFSoundDevice* device = ffListAdd(devices);
38+
ffStrbufInitS(&device->identifier, path);
39+
ffStrbufInitF(&device->name, "%s %s", ci.longname, ci.hw_info);
40+
device->volume = (1 << SOUND_MIXER_VOLUME) & mutemask
41+
? 0
42+
: ((uint8_t) volume /*left*/ + (uint8_t) (volume >> 8) /*right*/) / 2;
43+
device->active = true;
44+
device->main = defaultDev == idev;
3545
}
3646

3747
return NULL;

0 commit comments

Comments
 (0)