2021-05-11 19:14:00 +02:00
|
|
|
/*
|
|
|
|
* Strawberry Music Player
|
|
|
|
* Copyright 2021, Jonas Kvinge <jonas@jkvinge.net>
|
|
|
|
*
|
|
|
|
* Strawberry is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Strawberry is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <alsa/asoundlib.h>
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
#include <core/logging.h>
|
|
|
|
|
|
|
|
#include "alsapcmdevicefinder.h"
|
2023-06-01 19:31:19 +02:00
|
|
|
#include "enginedevice.h"
|
2021-05-11 19:14:00 +02:00
|
|
|
|
2024-04-11 02:56:01 +02:00
|
|
|
AlsaPCMDeviceFinder::AlsaPCMDeviceFinder() : DeviceFinder(QStringLiteral("alsa"), { QStringLiteral("alsa"), QStringLiteral("alsasink") }) {}
|
2021-05-11 19:14:00 +02:00
|
|
|
|
2023-06-01 19:31:19 +02:00
|
|
|
EngineDeviceList AlsaPCMDeviceFinder::ListDevices() {
|
2021-05-11 19:14:00 +02:00
|
|
|
|
2023-06-01 19:31:19 +02:00
|
|
|
EngineDeviceList ret;
|
2021-05-11 19:14:00 +02:00
|
|
|
|
|
|
|
void **hints = nullptr;
|
|
|
|
if (snd_device_name_hint(-1, "pcm", &hints) < 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-08-23 21:21:08 +02:00
|
|
|
for (void **n = hints; *n; ++n) {
|
2022-03-29 01:23:00 +02:00
|
|
|
char *hint_io = snd_device_name_get_hint(*n, "IOID");
|
|
|
|
char *hint_name = snd_device_name_get_hint(*n, "NAME");
|
|
|
|
char *hint_desc = snd_device_name_get_hint(*n, "DESC");
|
|
|
|
if (hint_io && hint_name && hint_desc && strcmp(hint_io, "Output") == 0) {
|
2021-05-11 19:14:00 +02:00
|
|
|
|
2024-04-11 02:56:01 +02:00
|
|
|
const QString name = QString::fromUtf8(hint_name);
|
2022-03-29 01:23:00 +02:00
|
|
|
|
|
|
|
char *desc_last = hint_desc;
|
2021-05-11 19:14:00 +02:00
|
|
|
QString description;
|
2022-03-29 01:23:00 +02:00
|
|
|
for (char *desc_i = hint_desc; desc_i && *desc_i != '\0'; ++desc_i) {
|
2021-05-11 19:14:00 +02:00
|
|
|
if (*desc_i == '\n') {
|
|
|
|
*desc_i = '\0';
|
2024-09-07 04:24:14 +02:00
|
|
|
if (!description.isEmpty()) description.append(u' ');
|
2024-04-11 02:56:01 +02:00
|
|
|
description.append(QString::fromUtf8(desc_last));
|
2021-05-11 19:14:00 +02:00
|
|
|
desc_last = desc_i + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (desc_last) {
|
2024-09-07 04:24:14 +02:00
|
|
|
if (!description.isEmpty()) description.append(u' ');
|
2024-04-11 02:56:01 +02:00
|
|
|
description.append(QString::fromUtf8(desc_last));
|
2021-05-11 19:14:00 +02:00
|
|
|
}
|
|
|
|
|
2023-06-01 19:31:19 +02:00
|
|
|
EngineDevice device;
|
2021-06-25 18:19:37 +02:00
|
|
|
device.value = name;
|
2021-05-11 19:14:00 +02:00
|
|
|
device.description = description;
|
2023-06-01 19:31:19 +02:00
|
|
|
device.iconname = device.GuessIconName();
|
2021-06-20 19:04:08 +02:00
|
|
|
ret << device; // clazy:exclude=reserve-candidates
|
2021-05-11 19:14:00 +02:00
|
|
|
}
|
2022-03-29 01:23:00 +02:00
|
|
|
if (hint_io) free(hint_io);
|
|
|
|
if (hint_name) free(hint_name);
|
|
|
|
if (hint_desc) free(hint_desc);
|
2021-05-11 19:14:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
snd_device_name_free_hint(hints);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|