85
src/engine/alsapcmdevicefinder.cpp
Normal file
85
src/engine/alsapcmdevicefinder.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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 <cstdio>
|
||||
#include <cerrno>
|
||||
#include <alsa/asoundlib.h>
|
||||
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
#include <QtDebug>
|
||||
|
||||
#include <core/logging.h>
|
||||
|
||||
#include "devicefinder.h"
|
||||
#include "alsapcmdevicefinder.h"
|
||||
|
||||
AlsaPCMDeviceFinder::AlsaPCMDeviceFinder()
|
||||
: DeviceFinder("alsa", {"alsa","alsasink"}) {}
|
||||
|
||||
QList<DeviceFinder::Device> AlsaPCMDeviceFinder::ListDevices() {
|
||||
|
||||
QList<Device> ret;
|
||||
|
||||
void **hints = nullptr;
|
||||
if (snd_device_name_hint(-1, "pcm", &hints) < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (void **n = hints ; *n ; ++n) {
|
||||
char *io = snd_device_name_get_hint(*n, "IOID");
|
||||
char *name = snd_device_name_get_hint(*n, "NAME");
|
||||
char *desc = snd_device_name_get_hint(*n, "DESC");
|
||||
if (io && name && desc && strcmp(io, "Output") == 0) {
|
||||
|
||||
char *desc_last = desc;
|
||||
QString description;
|
||||
for (char *desc_i = desc ; desc_i && *desc_i != '\0' ; ++desc_i) {
|
||||
if (*desc_i == '\n') {
|
||||
*desc_i = '\0';
|
||||
if (!description.isEmpty()) description.append(' ');
|
||||
description.append(desc_last);
|
||||
desc_last = desc_i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (desc_last) {
|
||||
if (!description.isEmpty()) description.append(' ');
|
||||
description.append(desc_last);
|
||||
}
|
||||
|
||||
Device device;
|
||||
device.value = name;
|
||||
device.description = description;
|
||||
device.iconname = GuessIconName(device.description);
|
||||
ret << device;
|
||||
}
|
||||
if (io) free(io);
|
||||
if (name) free(name);
|
||||
if (desc) free(desc);
|
||||
}
|
||||
|
||||
snd_device_name_free_hint(hints);
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
37
src/engine/alsapcmdevicefinder.h
Normal file
37
src/engine/alsapcmdevicefinder.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ALSAPCMDEVICEFINDER_H
|
||||
#define ALSAPCMDEVICEFINDER_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QList>
|
||||
|
||||
#include "devicefinder.h"
|
||||
|
||||
class AlsaPCMDeviceFinder : public DeviceFinder {
|
||||
public:
|
||||
explicit AlsaPCMDeviceFinder();
|
||||
|
||||
bool Initialize() override { return true; }
|
||||
QList<Device> ListDevices() override;
|
||||
};
|
||||
|
||||
#endif // ALSAPCMDEVICEFINDER_H
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
#ifdef HAVE_ALSA
|
||||
# include "alsadevicefinder.h"
|
||||
# include "alsapcmdevicefinder.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBPULSE
|
||||
@@ -57,6 +58,7 @@ void DeviceFinders::Init() {
|
||||
|
||||
#ifdef HAVE_ALSA
|
||||
device_finders.append(new AlsaDeviceFinder);
|
||||
device_finders.append(new AlsaPCMDeviceFinder);
|
||||
#endif
|
||||
#ifdef HAVE_LIBPULSE
|
||||
device_finders.append(new PulseDeviceFinder);
|
||||
|
||||
@@ -60,6 +60,8 @@ Engine::Base::Base()
|
||||
fadeout_duration_(2),
|
||||
fadeout_duration_nanosec_(2 * kNsecPerSec),
|
||||
proxy_authentication_(false),
|
||||
channels_enabled_(false),
|
||||
channels_(0),
|
||||
about_to_end_emitted_(false) {}
|
||||
|
||||
Engine::Base::~Base() {}
|
||||
@@ -110,6 +112,9 @@ void Engine::Base::ReloadSettings() {
|
||||
|
||||
volume_control_ = s.value("volume_control", true).toBool();
|
||||
|
||||
channels_enabled_ = s.value("channels_enabled", false).toBool();
|
||||
channels_ = s.value("channels", 0).toInt();
|
||||
|
||||
buffer_duration_nanosec_ = s.value("bufferduration", BackendSettingsPage::kDefaultBufferDuration).toLongLong() * kNsecPerMsec;
|
||||
buffer_low_watermark_ = s.value("bufferlowwatermark", BackendSettingsPage::kDefaultBufferLowWatermark).toDouble();
|
||||
buffer_high_watermark_ = s.value("bufferhighwatermark", BackendSettingsPage::kDefaultBufferHighWatermark).toDouble();
|
||||
@@ -156,6 +161,7 @@ void Engine::Base::ReloadSettings() {
|
||||
proxy_user_.clear();
|
||||
proxy_pass_.clear();
|
||||
}
|
||||
|
||||
s.endGroup();
|
||||
|
||||
}
|
||||
|
||||
@@ -206,6 +206,10 @@ class Base : public QObject {
|
||||
QString proxy_user_;
|
||||
QString proxy_pass_;
|
||||
|
||||
// Channels
|
||||
bool channels_enabled_;
|
||||
int channels_;
|
||||
|
||||
private:
|
||||
bool about_to_end_emitted_;
|
||||
Q_DISABLE_COPY(Base)
|
||||
|
||||
@@ -817,6 +817,7 @@ std::shared_ptr<GstEnginePipeline> GstEngine::CreatePipeline() {
|
||||
ret->set_buffer_low_watermark(buffer_low_watermark_);
|
||||
ret->set_buffer_high_watermark(buffer_high_watermark_);
|
||||
ret->set_proxy_settings(proxy_address_, proxy_authentication_, proxy_user_, proxy_pass_);
|
||||
ret->set_channels(channels_enabled_, channels_);
|
||||
|
||||
ret->AddBufferConsumer(this);
|
||||
for (GstBufferConsumer *consumer : buffer_consumers_) {
|
||||
|
||||
@@ -86,6 +86,8 @@ GstEnginePipeline::GstEnginePipeline(GstEngine *engine)
|
||||
buffer_high_watermark_(BackendSettingsPage::kDefaultBufferHighWatermark),
|
||||
buffering_(false),
|
||||
proxy_authentication_(false),
|
||||
channels_enabled_(false),
|
||||
channels_(0),
|
||||
segment_start_(0),
|
||||
segment_start_received_(false),
|
||||
end_offset_nanosec_(-1),
|
||||
@@ -206,6 +208,11 @@ void GstEnginePipeline::set_proxy_settings(const QString &address, const bool au
|
||||
proxy_pass_ = pass;
|
||||
}
|
||||
|
||||
void GstEnginePipeline::set_channels(const bool enabled, const int channels) {
|
||||
channels_enabled_ = enabled;
|
||||
channels_ = channels;
|
||||
}
|
||||
|
||||
bool GstEnginePipeline::InitFromUrl(const QByteArray &stream_url, const QUrl original_url, const qint64 end_nanosec) {
|
||||
|
||||
stream_url_ = stream_url;
|
||||
@@ -440,6 +447,10 @@ bool GstEnginePipeline::InitAudioBin() {
|
||||
gst_element_link(next, audioconverter);
|
||||
|
||||
GstCaps *caps = gst_caps_new_empty_simple("audio/x-raw");
|
||||
if (channels_enabled_ && channels_ > 0) {
|
||||
qLog(Debug) << "Setting channels to" << channels_;
|
||||
gst_caps_set_simple(caps, "channels", G_TYPE_INT, channels_, nullptr);
|
||||
}
|
||||
gst_element_link_filtered(audioconverter, audiosink, caps);
|
||||
gst_caps_unref(caps);
|
||||
|
||||
|
||||
@@ -74,6 +74,7 @@ class GstEnginePipeline : public QObject {
|
||||
void set_buffer_low_watermark(const double value);
|
||||
void set_buffer_high_watermark(const double value);
|
||||
void set_proxy_settings(const QString &address, const bool authentication, const QString &user, const QString &pass);
|
||||
void set_channels(const bool enabled, const int channels);
|
||||
|
||||
// Creates the pipeline, returns false on error
|
||||
bool InitFromUrl(const QByteArray &stream_url, const QUrl original_url, const qint64 end_nanosec);
|
||||
@@ -221,6 +222,10 @@ class GstEnginePipeline : public QObject {
|
||||
QString proxy_user_;
|
||||
QString proxy_pass_;
|
||||
|
||||
// Channels
|
||||
bool channels_enabled_;
|
||||
int channels_;
|
||||
|
||||
// These get called when there is a new audio buffer available
|
||||
QList<GstBufferConsumer*> buffer_consumers_;
|
||||
QMutex buffer_consumers_mutex_;
|
||||
|
||||
Reference in New Issue
Block a user