Skip to content

Commit ab6a770

Browse files
committed
Sound: detect platform API
Ref: #1454
1 parent 0e99486 commit ab6a770

File tree

6 files changed

+22
-10
lines changed

6 files changed

+22
-10
lines changed

src/detection/sound/sound.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ typedef struct FFSoundDevice
88
{
99
FFstrbuf identifier;
1010
FFstrbuf name;
11+
FFstrbuf platformApi;
1112
uint8_t volume; // 0-100%
1213
bool main;
1314
bool active;

src/detection/sound/sound_apple.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const char* ffDetectSound(FFlist* devices /* List of FFSoundDevice */)
7373
device->volume = FF_SOUND_VOLUME_UNKNOWN;
7474
ffStrbufInitF(&device->identifier, "%u", (unsigned) deviceId);
7575
ffStrbufInit(&device->name);
76+
ffStrbufInitStatic(&device->platformApi, "Core Audio");
7677
ffCfStrGetString(name, &device->name);
7778

7879
uint32_t muted;

src/detection/sound/sound_bsd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ const char* ffDetectSound(FFlist* devices)
3939
FFSoundDevice* device = ffListAdd(devices);
4040
ffStrbufInitS(&device->identifier, path);
4141
ffStrbufInitF(&device->name, "%s %s", ci.longname, ci.hw_info);
42-
ffStrbufTrimRightSpace(&device->name);
42+
ffStrbufTrimRightSpace(&device->name);
43+
ffStrbufInitStatic(&device->platformApi, "OSS");
4344
device->volume = mutemask & SOUND_MASK_VOLUME
4445
? 0
4546
: ((uint8_t) volume /*left*/ + (uint8_t) (volume >> 8) /*right*/) / 2;

src/detection/sound/sound_linux.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ static void paSinkInfoCallback(pa_context *c, const pa_sink_info *i, int eol, vo
1313

1414
FFSoundDevice* device = ffListAdd(userdata);
1515
ffStrbufInitS(&device->identifier, i->name);
16+
ffStrbufInitS(&device->platformApi, "PulseAudio");
1617
ffStrbufTrimRightSpace(&device->identifier);
1718
ffStrbufInitS(&device->name, i->description);
1819
ffStrbufTrimRightSpace(&device->name);
@@ -22,20 +23,24 @@ static void paSinkInfoCallback(pa_context *c, const pa_sink_info *i, int eol, vo
2223
device->main = false;
2324
}
2425

25-
static void paServerInfoCallback(pa_context *c, const pa_server_info *i, void *userdata)
26+
static void paServerInfoCallback(FF_MAYBE_UNUSED pa_context *c, const pa_server_info *i, void *userdata)
2627
{
27-
FF_UNUSED(c);
28+
if(!i) return;
2829

29-
if(!i)
30-
return;
30+
FF_STRBUF_AUTO_DESTROY api = ffStrbufCreate();
31+
const char* realServer = strstr(i->server_name, "(on ");
32+
if (realServer)
33+
{
34+
ffStrbufSetS(&api, realServer + strlen("(on "));
35+
ffStrbufTrimRight(&api, ')');
36+
}
37+
else
38+
ffStrbufSetF(&api, "%s %s", i->server_name, i->server_version);
3139

3240
FF_LIST_FOR_EACH(FFSoundDevice, device, *(FFlist*)userdata)
3341
{
34-
if(ffStrbufEqualS(&device->identifier, i->default_sink_name))
35-
{
36-
device->main = true;
37-
break;
38-
}
42+
device->main = ffStrbufEqualS(&device->identifier, i->default_sink_name);
43+
ffStrbufSet(&device->platformApi, &api);
3944
}
4045
}
4146

src/detection/sound/sound_windows.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const char* ffDetectSound(FFlist* devices /* List of FFSoundDevice */)
6565
device->volume = FF_SOUND_VOLUME_UNKNOWN;
6666
ffStrbufInitWS(&device->identifier, immDeviceId);
6767
ffStrbufInit(&device->name);
68+
ffStrbufInitStatic(&device->platformApi, "Core Audio APIs");
6869

6970
{
7071
PROPVARIANT __attribute__((__cleanup__(PropVariantClear))) friendlyName;

src/modules/sound/sound.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ static void printDevice(FFSoundOptions* options, const FFSoundDevice* device, ui
5858
FF_FORMAT_ARG(percentageNum, "volume-percentage"),
5959
FF_FORMAT_ARG(device->identifier, "identifier"),
6060
FF_FORMAT_ARG(percentageBar, "volume-percentage-bar"),
61+
FF_FORMAT_ARG(device->platformApi, "platform-api"),
6162
}));
6263
}
6364
}
@@ -218,6 +219,7 @@ void ffGenerateSoundJsonResult(FF_MAYBE_UNUSED FFSoundOptions* options, yyjson_m
218219

219220
yyjson_mut_obj_add_strbuf(doc, obj, "name", &item->name);
220221
yyjson_mut_obj_add_strbuf(doc, obj, "identifier", &item->identifier);
222+
yyjson_mut_obj_add_strbuf(doc, obj, "platformApi", &item->platformApi);
221223
}
222224

223225
FF_LIST_FOR_EACH(FFSoundDevice, device, result)
@@ -241,6 +243,7 @@ static FFModuleBaseInfo ffModuleInfo = {
241243
{"Volume (in percentage num)", "volume-percentage"},
242244
{"Identifier", "identifier"},
243245
{"Volume (in percentage bar)", "volume-percentage-bar"},
246+
{"Platform API used", "platform-api"},
244247
}))
245248
};
246249

0 commit comments

Comments
 (0)