Sound: detect platform API

Ref: #1454
This commit is contained in:
Carter Li
2025-01-07 11:17:01 +08:00
committed by 李通洲
parent 0e99486efe
commit ab6a770155
6 changed files with 22 additions and 10 deletions
+1
View File
@@ -8,6 +8,7 @@ typedef struct FFSoundDevice
{
FFstrbuf identifier;
FFstrbuf name;
FFstrbuf platformApi;
uint8_t volume; // 0-100%
bool main;
bool active;
+1
View File
@@ -73,6 +73,7 @@ const char* ffDetectSound(FFlist* devices /* List of FFSoundDevice */)
device->volume = FF_SOUND_VOLUME_UNKNOWN;
ffStrbufInitF(&device->identifier, "%u", (unsigned) deviceId);
ffStrbufInit(&device->name);
ffStrbufInitStatic(&device->platformApi, "Core Audio");
ffCfStrGetString(name, &device->name);
uint32_t muted;
+2 -1
View File
@@ -39,7 +39,8 @@ const char* ffDetectSound(FFlist* devices)
FFSoundDevice* device = ffListAdd(devices);
ffStrbufInitS(&device->identifier, path);
ffStrbufInitF(&device->name, "%s %s", ci.longname, ci.hw_info);
ffStrbufTrimRightSpace(&device->name);
ffStrbufTrimRightSpace(&device->name);
ffStrbufInitStatic(&device->platformApi, "OSS");
device->volume = mutemask & SOUND_MASK_VOLUME
? 0
: ((uint8_t) volume /*left*/ + (uint8_t) (volume >> 8) /*right*/) / 2;
+14 -9
View File
@@ -13,6 +13,7 @@ static void paSinkInfoCallback(pa_context *c, const pa_sink_info *i, int eol, vo
FFSoundDevice* device = ffListAdd(userdata);
ffStrbufInitS(&device->identifier, i->name);
ffStrbufInitS(&device->platformApi, "PulseAudio");
ffStrbufTrimRightSpace(&device->identifier);
ffStrbufInitS(&device->name, i->description);
ffStrbufTrimRightSpace(&device->name);
@@ -22,20 +23,24 @@ static void paSinkInfoCallback(pa_context *c, const pa_sink_info *i, int eol, vo
device->main = false;
}
static void paServerInfoCallback(pa_context *c, const pa_server_info *i, void *userdata)
static void paServerInfoCallback(FF_MAYBE_UNUSED pa_context *c, const pa_server_info *i, void *userdata)
{
FF_UNUSED(c);
if(!i) return;
if(!i)
return;
FF_STRBUF_AUTO_DESTROY api = ffStrbufCreate();
const char* realServer = strstr(i->server_name, "(on ");
if (realServer)
{
ffStrbufSetS(&api, realServer + strlen("(on "));
ffStrbufTrimRight(&api, ')');
}
else
ffStrbufSetF(&api, "%s %s", i->server_name, i->server_version);
FF_LIST_FOR_EACH(FFSoundDevice, device, *(FFlist*)userdata)
{
if(ffStrbufEqualS(&device->identifier, i->default_sink_name))
{
device->main = true;
break;
}
device->main = ffStrbufEqualS(&device->identifier, i->default_sink_name);
ffStrbufSet(&device->platformApi, &api);
}
}
+1
View File
@@ -65,6 +65,7 @@ const char* ffDetectSound(FFlist* devices /* List of FFSoundDevice */)
device->volume = FF_SOUND_VOLUME_UNKNOWN;
ffStrbufInitWS(&device->identifier, immDeviceId);
ffStrbufInit(&device->name);
ffStrbufInitStatic(&device->platformApi, "Core Audio APIs");
{
PROPVARIANT __attribute__((__cleanup__(PropVariantClear))) friendlyName;