summaryrefslogtreecommitdiffstats
path: root/pica-client/audiodevice.cpp
diff options
context:
space:
mode:
authorAnton <anton@picapica>2021-07-04 03:03:50 +0400
committerAnton <anton@picapica>2021-07-04 03:03:50 +0400
commitbac29a930f2cd5825f6edb400d87eea2171b0cc1 (patch)
treebeb810bc84f909185ac8cdc46d47c9fc127b2235 /pica-client/audiodevice.cpp
parentceeb6d790fa071637a6f24ce0df6b9e220690793 (diff)
downloadpica-pica-bac29a930f2cd5825f6edb400d87eea2171b0cc1.tar.gz
pica-pica-bac29a930f2cd5825f6edb400d87eea2171b0cc1.zip
pica-client/audio: enumerate ALSA devices on Linux
Diffstat (limited to 'pica-client/audiodevice.cpp')
-rw-r--r--pica-client/audiodevice.cpp56
1 files changed, 55 insertions, 1 deletions
diff --git a/pica-client/audiodevice.cpp b/pica-client/audiodevice.cpp
index 16bf0b1..d2995e3 100644
--- a/pica-client/audiodevice.cpp
+++ b/pica-client/audiodevice.cpp
@@ -1,5 +1,9 @@
#include "audiodevice.h"
+#ifdef Q_OS_LINUX
+#include <alsa/asoundlib.h>
+#endif
+
AudioDevice::AudioDevice()
{
@@ -10,7 +14,57 @@ AudioDevice::~AudioDevice()
}
-QList<MediaDeviceInfo> AudioDevice::Enumerate()
+void AudioDevice::Capture()
+{
+}
+
+void AudioDevice::Play()
+{
+}
+
+void AudioDevice::Close()
{
+}
+
+QList<MediaDeviceInfo> AudioDevice::Enumerate(enum MediaDeviceStreamDirection dir)
+{
+ QList<MediaDeviceInfo> result;
+ int index = 0;
+
+#ifdef Q_OS_LINUX
+ void **hints, **n;
+ char *name = NULL, *descr = NULL, *io = NULL;
+ const char *direction = (dir == PLAYBACK) ? "Output" : "Input";
+
+ if (snd_device_name_hint(-1, "pcm", &hints) < 0)
+ return result;
+ n = hints;
+ while(*n)
+ {
+ MediaDeviceInfo d;
+
+ name = snd_device_name_get_hint(*n, "NAME");
+ descr = snd_device_name_get_hint(*n, "DESC");
+ io = snd_device_name_get_hint(*n, "IOID");
+
+ if (io && strcmp(io, direction))
+ goto release_resources;
+
+ d.device = QLatin1String(name);
+ d.humanReadable = QLatin1String(descr);
+ d.index = index++;
+ if (strstr(name, "default") == name)
+ result.prepend(d);
+ else
+ result << d;
+ release_resources:
+ free(io);
+ free(descr);
+ free(name);
+ n++;
+ }
+ snd_device_name_free_hint(hints);
+#endif
+ return result;
}