Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crude ALSA device selection. #5787

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,14 @@ optional_source(WIN32
${CMAKE_SOURCE_DIR}/3rdparty/tinysvcmdns
)

# Platform specific - Linux
optional_source(LINUX
SOURCES
engines/alsadevicefinder.cpp
HEADERS
engines/alsadevicefinder.h
)

# Platform specific - X11
optional_source(LINUX SOURCES widgets/osd_x11.cpp)

Expand Down
58 changes: 58 additions & 0 deletions src/engines/alsadevicefinder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* This file is part of Clementine.
Copyright 2017, Adam Borowski <kilobyte@angband.pl>

Clementine 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.

Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
*/

#include <QFile>

#include "alsadevicefinder.h"

AlsaDeviceFinder::AlsaDeviceFinder()
: DeviceFinder("alsasink") {
}

QList<DeviceFinder::Device> AlsaDeviceFinder::ListDevices() {
QList<Device> ret;

QFile cards("/proc/asound/cards");
if (!cards.open(QIODevice::ReadOnly)) return ret;

/* Syntax:
snd_iprintf(buffer, "%2i [%-15s]: %s - %s\n",
idx,
card->id,
card->driver,
card->shortname);
snd_iprintf(buffer, " %s\n",
card->longname);
*/
QRegExp regid("^ ?(\\d{1,2}) \\[.{15}\\]: .* - .*$");
QRegExp regln("^ (.*)\n");

while (1) {
QString line = cards.readLine();
if (regid.indexIn(line) == -1) break;
line = cards.readLine();
if (regln.indexIn(line) == -1) break;

Device dev;
dev.description = regln.cap(1).remove(QRegExp(" at .*$"));
dev.device_property_value = QString("hw:%1").arg(regid.cap(1));
dev.icon_name = GuessIconName(dev.description);
ret.append(dev);
}

return ret;
}
31 changes: 31 additions & 0 deletions src/engines/alsadevicefinder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* This file is part of Clementine.
Copyright 2017 Adam Borowski <kilobyte@angband.pl>

Clementine 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.

Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef ALSADEVICEFINDER_H
#define ALSADEVICEFINDER_H

#include "engines/devicefinder.h"

class AlsaDeviceFinder : public DeviceFinder {
public:
AlsaDeviceFinder();

virtual bool Initialise() { return true; }
virtual QList<Device> ListDevices();
};

#endif // ALSADEVICEFINDER_H
7 changes: 7 additions & 0 deletions src/engines/gstengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
#include "engines/pulsedevicefinder.h"
#endif

#ifdef Q_OS_LINUX
#include "engines/alsadevicefinder.h"
#endif

#ifdef Q_OS_DARWIN
#include "engines/osxdevicefinder.h"
#endif
Expand Down Expand Up @@ -162,6 +166,9 @@ void GstEngine::InitialiseGstreamer() {
#ifdef HAVE_LIBPULSE
device_finders.append(new PulseDeviceFinder);
#endif
#ifdef Q_OS_LINUX
device_finders.append(new AlsaDeviceFinder);
#endif
#ifdef Q_OS_DARWIN
device_finders.append(new OsxDeviceFinder);
#endif
Expand Down