Sound(linux): Implement using libpulse

Also differentiate between active and main device(s)
This commit is contained in:
Linus Dierheimer
2023-01-26 15:48:28 +01:00
parent 856c9d58b8
commit 184ada6ae8
13 changed files with 156 additions and 101 deletions
+30 -26
View File
@@ -15,10 +15,11 @@ static void printDevice(FFinstance* instance, const FFSoundDevice* device, uint8
printf(" (%d%%)", device->volume);
else
fputs(" (muted)", stdout);
if(device->main && instance->config.soundShowAll)
puts(" (*)");
else
putchar('\n');
if(device->main && index > 0)
fputs(" (*)", stdout);
putchar('\n');
}
else
{
@@ -31,6 +32,30 @@ static void printDevice(FFinstance* instance, const FFSoundDevice* device, uint8
}
}
static void printSound(FFinstance* instance, FFlist* devices)
{
FF_LIST_AUTO_DESTROY filtered;
ffListInit(&filtered, sizeof(FFSoundDevice*));
FF_LIST_FOR_EACH(FFSoundDevice, device, *devices)
{
if(!device->active && !instance->config.soundShowAll)
continue;
*(FFSoundDevice**)ffListAdd(&filtered) = device;
}
if(filtered.length == 0)
{
ffPrintError(instance, FF_SOUND_MODULE_NAME, 0, &instance->config.sound, "No active sound devices found");
return;
}
uint8_t index = 1;
FF_LIST_FOR_EACH(FFSoundDevice*, device, filtered)
printDevice(instance, *device, filtered.length == 1 ? 0 : index++);
}
void ffPrintSound(FFinstance* instance)
{
FF_LIST_AUTO_DESTROY result;
@@ -43,28 +68,7 @@ void ffPrintSound(FFinstance* instance)
return;
}
if(result.length == 0)
{
ffPrintError(instance, FF_SOUND_MODULE_NAME, 0, &instance->config.sound, "No sound devices found");
return;
}
if(instance->config.soundShowAll)
{
uint8_t index = 0;
FF_LIST_FOR_EACH(FFSoundDevice, device, result)
{
printDevice(instance, device, result.length == 1 ? 0 : ++index);
}
}
else
{
FF_LIST_FOR_EACH(FFSoundDevice, device, result)
{
if (!device->main) continue;
printDevice(instance, device, 0);
}
}
printSound(instance, &result);
FF_LIST_FOR_EACH(FFSoundDevice, device, result)
{