[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kmix/kmix-improvements] src/daemon2: Refactor PulseControl to also support source outputs
From: Trever Fischer <tdfischer () fedoraproject ! org>
Date: 2012-09-25 0:36:28
Message-ID: 20120925003628.5EE67A60D1 () git ! kde ! org
[Download RAW message or body]
Git commit f64c8d03ca973091de56a243945f554dfbb2d1ad by Trever Fischer.
Committed on 25/09/2012 at 02:22.
Pushed by tdfischer into branch 'kmix-improvements'.
Refactor PulseControl to also support source outputs
M +2 -0 src/daemon2/CMakeLists.txt
M +51 -7 src/daemon2/backends/PulseAudio.cpp
M +6 -1 src/daemon2/backends/PulseAudio.h
M +11 -30 src/daemon2/backends/PulseControl.cpp
M +4 -6 src/daemon2/backends/PulseControl.h
A +39 -0 src/daemon2/backends/PulseSinkControl.cpp [License: UNKNOWN] *
A +19 -0 src/daemon2/backends/PulseSinkControl.h [License: UNKNOWN] *
A +44 -0 src/daemon2/backends/PulseSourceOutputControl.cpp [License: \
UNKNOWN] * A +21 -0 src/daemon2/backends/PulseSourceOutputControl.h \
[License: UNKNOWN] *
The files marked with a * at the end have a non valid license. Please read: \
http://techbase.kde.org/Policies/Licensing_Policy and use the headers which are \
listed at that page.
http://commits.kde.org/kmix/f64c8d03ca973091de56a243945f554dfbb2d1ad
diff --git a/src/daemon2/CMakeLists.txt b/src/daemon2/CMakeLists.txt
index 5faa5c0..d19c325 100644
--- a/src/daemon2/CMakeLists.txt
+++ b/src/daemon2/CMakeLists.txt
@@ -24,6 +24,8 @@ set(kmixd_SRCS
backends/PulseAudio.cpp
backends/PulseControl.cpp
+ backends/PulseSourceOutputControl.cpp
+ backends/PulseSinkControl.cpp
)
qt4_add_dbus_adaptor( kmixd_SRCS ../dbus/org.kde.kmix.kmixd.xml
diff --git a/src/daemon2/backends/PulseAudio.cpp \
b/src/daemon2/backends/PulseAudio.cpp index 61b493a..af18760 100644
--- a/src/daemon2/backends/PulseAudio.cpp
+++ b/src/daemon2/backends/PulseAudio.cpp
@@ -20,6 +20,8 @@
#include "PulseAudio.h"
#include "PulseControl.h"
+#include "PulseSourceOutputControl.h"
+#include "PulseSinkControl.h"
#include <QtCore/QDebug>
namespace Backends {
@@ -44,21 +46,44 @@ PulseAudio::~PulseAudio()
}
}
-void PulseAudio::sink_cb(pa_context *cxt, const pa_sink_info *info, int eol, \
gpointer user_data) { +void PulseAudio::source_output_cb(pa_context *cxt, const \
pa_source_output_info *info, int eol, gpointer user_data) +{
+ PulseAudio *that = static_cast<PulseAudio*>(user_data);
+ qDebug() << "source output" << eol;
+ if (eol < 0) {
+ if (pa_context_errno(cxt) == PA_ERR_NOENTITY)
+ return;
+ }
+ if (eol > 0) {
+ return;
+ }
+ PulseSourceOutputControl *control;
+ qDebug() << "Stream output event for" << info->index;
+ if (!that->m_sourceOutputs.contains(info->index)) {
+ control = new PulseSourceOutputControl(cxt, info, that);
+ QObject::connect(control, SIGNAL(scheduleRefresh(int)), that, \
SLOT(refreshSourceOutput(int))); + that->m_sourceOutputs[info->index] = \
control; + that->registerControl(control);
+ } else {
+ control = that->m_sourceOutputs[info->index];
+ control->update(info);
+ }
+}
+
+void PulseAudio::sink_cb(pa_context *cxt, const pa_sink_info *info, int eol, \
gpointer user_data) +{
PulseAudio *that = static_cast<PulseAudio*>(user_data);
- qDebug() << eol;
if (eol < 0) {
- qDebug() << pa_context_errno(cxt);
if (pa_context_errno(cxt) == PA_ERR_NOENTITY)
return;
}
if (eol > 0) {
return;
}
- PulseControl *control;
+ PulseSinkControl *control;
qDebug() << "Event for" << info->index;
if (!that->m_sinks.contains(info->index)) {
- control = new PulseControl(cxt, info, that);
+ control = new PulseSinkControl(cxt, info, that);
QObject::connect(control, SIGNAL(scheduleRefresh(int)), that, \
SLOT(refreshSink(int))); that->m_sinks[info->index] = control;
that->registerControl(control);
@@ -70,13 +95,16 @@ void PulseAudio::sink_cb(pa_context *cxt, const pa_sink_info \
*info, int eol, gpo
void PulseAudio::refreshSink(int idx)
{
- qDebug() << "update queued for" << idx;
pa_context_get_sink_info_by_index(m_context, idx, sink_cb, this);
}
+void PulseAudio::refreshSourceOutput(int idx)
+{
+ pa_context_get_source_output_info(m_context, idx, source_output_cb, this);
+}
+
void PulseAudio::subscribe_cb(pa_context *cxt, pa_subscription_event_type t, \
uint32_t index, gpointer user_data) {
- qDebug() << "subscription" << t;
switch (t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) {
case PA_SUBSCRIPTION_EVENT_SINK:
if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == \
PA_SUBSCRIPTION_EVENT_REMOVE) { @@ -90,6 +118,18 @@ void \
PulseAudio::subscribe_cb(pa_context *cxt, pa_subscription_event_type t, uin \
pa_operation_unref(op); }
break;
+ case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT:
+ if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == \
PA_SUBSCRIPTION_EVENT_REMOVE) { + //FIXME
+ } else {
+ pa_operation *op;
+ if (!(op = pa_context_get_source_output_info(cxt, index, \
source_output_cb, user_data))) { + qWarning() << \
"pa_context_get_source_output_info failed"; + return;
+ }
+ pa_operation_unref(op);
+ }
+ break;
}
}
@@ -115,6 +155,10 @@ void PulseAudio::context_state_callback(pa_context *cxt, \
gpointer user_data) return;
}
pa_operation_unref(op);
+ if (!(op = pa_context_get_source_output_info_list(cxt, source_output_cb, \
that))) { + return;
+ }
+ pa_operation_unref(op);
}
}
diff --git a/src/daemon2/backends/PulseAudio.h b/src/daemon2/backends/PulseAudio.h
index 12f0bad..2352aaf 100644
--- a/src/daemon2/backends/PulseAudio.h
+++ b/src/daemon2/backends/PulseAudio.h
@@ -25,6 +25,8 @@
namespace Backends {
class PulseControl;
+class PulseSinkControl;
+class PulseSourceOutputControl;
class PulseAudio : public Backend {
Q_OBJECT
@@ -34,14 +36,17 @@ public:
bool open();
private slots:
void refreshSink(int idx);
+ void refreshSourceOutput(int idx);
private:
static void context_state_callback(pa_context *cxt, gpointer user_data);
static void sink_cb(pa_context *cxt, const pa_sink_info *info, int eol, gpointer \
user_data); + static void source_output_cb(pa_context *cxt, const \
pa_source_output_info *info, int eol, gpointer user_data);
static void subscribe_cb(pa_context *cxt, pa_subscription_event_type t, uint32_t \
index, gpointer user_data); pa_glib_mainloop *m_loop;
pa_mainloop_api *m_loopAPI;
pa_context *m_context;
- QMap<int, PulseControl*> m_sinks;
+ QMap<int, PulseSinkControl*> m_sinks;
+ QMap<int, PulseSourceOutputControl*> m_sourceOutputs;
};
} //namespace Backends
diff --git a/src/daemon2/backends/PulseControl.cpp \
b/src/daemon2/backends/PulseControl.cpp index 1acf274..1b28b3d 100644
--- a/src/daemon2/backends/PulseControl.cpp
+++ b/src/daemon2/backends/PulseControl.cpp
@@ -24,11 +24,10 @@
namespace Backends {
-PulseControl::PulseControl(pa_context *cxt, const pa_sink_info *info, QObject \
*parent)
- : Control(Control::HardwareOutput, parent)
+PulseControl::PulseControl(Category category, pa_context *cxt, QObject *parent)
+ : Control(category, parent)
, m_context(cxt)
{
- update(info);
}
QString PulseControl::displayName() const
@@ -51,14 +50,6 @@ int PulseControl::getVolume(Channel channel) const
return m_volumes.values[(int)channel];
}
-void PulseControl::setVolume(Channel c, int v)
-{
- m_volumes.values[(int)c] = v;
- if (!pa_context_set_sink_volume_by_index(m_context, m_idx, &m_volumes, NULL, \
NULL)) {
- qWarning() << "pa_context_set_sink_volume_by_index() failed";
- }
-}
-
bool PulseControl::isMuted() const
{
return m_muted;
@@ -70,35 +61,25 @@ void PulseControl::cb_refresh(pa_context *c, int success, void* \
user_data) emit that->scheduleRefresh(that->m_idx);
}
-void PulseControl::setMute(bool yes)
-{
- pa_context_set_sink_mute_by_index(m_context, m_idx, yes, cb_refresh, this);
-}
-
bool PulseControl::canMute() const
{
return true;
}
-void PulseControl::update(const pa_sink_info *info)
+void PulseControl::updateVolumes(const pa_cvolume &volumes)
{
- m_idx = info->index;
- m_displayName = QString::fromUtf8(info->description);
- m_iconName = QString::fromUtf8(pa_proplist_gets(info->proplist, \
PA_PROP_DEVICE_ICON_NAME));
- qDebug() << m_volumes.channels << info->volume.channels;
- if (m_volumes.channels == info->volume.channels) {
- for (int channel = 0;channel < info->volume.channels;channel++) {
- if (m_volumes.values[channel] != info->volume.values[channel]) {
- qDebug() << "Volume on" << channel << "from" << \
m_volumes.values[channel] << "to" << info->volume.values[channel]; + qDebug() << \
m_volumes.channels << volumes.channels; + if (m_volumes.channels == \
volumes.channels) { + for (int channel = 0;channel < \
volumes.channels;channel++) { + if (m_volumes.values[channel] != \
volumes.values[channel]) { + qDebug() << "Volume on" << channel << \
"from" << m_volumes.values[channel] << "to" << volumes.values[channel]; emit \
volumeChanged((Channel)channel); }
}
}
- m_volumes = info->volume;
- if (m_muted != info->mute) {
- emit muteChanged(info->mute);
- }
- m_muted = info->mute;
+ m_volumes = volumes;
}
} //namespace Backends
+
+#include "PulseControl.moc"
diff --git a/src/daemon2/backends/PulseControl.h \
b/src/daemon2/backends/PulseControl.h index 580554e..c129b6b 100644
--- a/src/daemon2/backends/PulseControl.h
+++ b/src/daemon2/backends/PulseControl.h
@@ -29,22 +29,20 @@ namespace Backends {
class PulseControl : public Control {
Q_OBJECT
public:
- PulseControl(pa_context *cxt, const pa_sink_info *info, QObject *parent = 0);
+ PulseControl(Category category, pa_context *cxt, QObject *parent = 0);
QString displayName() const;
QString iconName() const;
int channels() const;
int getVolume(Channel channel) const;
- void setVolume(Channel c, int v);
bool isMuted() const;
- void setMute(bool yes);
bool canMute() const;
- void update(const pa_sink_info *info);
+
signals:
void scheduleRefresh(int index);
-private:
+protected:
static void cb_refresh(pa_context *c, int success, void* user_data);
+ void updateVolumes(const pa_cvolume &volumes);
pa_context *m_context;
-
int m_idx;
QString m_displayName;
QString m_iconName;
diff --git a/src/daemon2/backends/PulseSinkControl.cpp \
b/src/daemon2/backends/PulseSinkControl.cpp new file mode 100644
index 0000000..2ac30ca
--- /dev/null
+++ b/src/daemon2/backends/PulseSinkControl.cpp
@@ -0,0 +1,39 @@
+#include "PulseSinkControl.h"
+#include <QtCore/QDebug>
+
+namespace Backends {
+
+PulseSinkControl::PulseSinkControl(pa_context *cxt, const pa_sink_info *info, \
QObject *parent) + : PulseControl(Control::HardwareOutput, cxt, parent)
+{
+ update(info);
+}
+
+void PulseSinkControl::setVolume(Channel c, int v)
+{
+ m_volumes.values[(int)c] = v;
+ if (!pa_context_set_sink_volume_by_index(m_context, m_idx, &m_volumes, NULL, \
NULL)) { + qWarning() << "pa_context_set_sink_volume_by_index() failed";
+ }
+}
+
+void PulseSinkControl::setMute(bool yes)
+{
+ pa_context_set_sink_mute_by_index(m_context, m_idx, yes, cb_refresh, this);
+}
+
+void PulseSinkControl::update(const pa_sink_info *info)
+{
+ m_idx = info->index;
+ m_displayName = QString::fromUtf8(info->description);
+ m_iconName = QString::fromUtf8(pa_proplist_gets(info->proplist, \
PA_PROP_DEVICE_ICON_NAME)); + updateVolumes(info->volume);
+ if (m_muted != info->mute) {
+ emit muteChanged(info->mute);
+ }
+ m_muted = info->mute;
+}
+
+}
+
+#include "PulseSinkControl.moc"
diff --git a/src/daemon2/backends/PulseSinkControl.h \
b/src/daemon2/backends/PulseSinkControl.h new file mode 100644
index 0000000..757a035
--- /dev/null
+++ b/src/daemon2/backends/PulseSinkControl.h
@@ -0,0 +1,19 @@
+#ifndef PULSESINKCONTROL_H
+#define PULSESINKCONTROL_H
+
+#include "PulseControl.h"
+
+namespace Backends {
+
+class PulseSinkControl : public PulseControl {
+ Q_OBJECT
+public:
+ PulseSinkControl(pa_context *cxt, const pa_sink_info *info, QObject *parent = \
0); + void setVolume(Channel c, int v);
+ void setMute(bool yes);
+ void update(const pa_sink_info *info);
+};
+
+}
+
+#endif // PULSESINKCONTROL_H
diff --git a/src/daemon2/backends/PulseSourceOutputControl.cpp \
b/src/daemon2/backends/PulseSourceOutputControl.cpp new file mode 100644
index 0000000..b001dcb
--- /dev/null
+++ b/src/daemon2/backends/PulseSourceOutputControl.cpp
@@ -0,0 +1,44 @@
+#include "PulseSourceOutputControl.h"
+
+#include <QtCore/QDebug>
+
+namespace Backends {
+
+PulseSourceOutputControl::PulseSourceOutputControl(pa_context *cxt, const \
pa_source_output_info *info, QObject *parent) + : \
PulseControl(Control::InputStream, cxt, parent) +{
+ update(info);
+}
+
+void PulseSourceOutputControl::setVolume(Channel c, int v)
+{
+ m_volumes.values[(int)c] = v;
+ if (!pa_context_set_source_output_volume(m_context, m_idx, &m_volumes, NULL, \
NULL)) { + qWarning() << "pa_context_set_source_output_volume() failed";
+ }
+}
+
+void PulseSourceOutputControl::setMute(bool yes)
+{
+ pa_context_set_source_output_mute(m_context, m_idx, yes, cb_refresh, this);
+}
+
+void PulseSourceOutputControl::cb_client_info(pa_context *cxt, const pa_client_info \
*info, int eol, void *userdata) +{
+}
+
+void PulseSourceOutputControl::update(const pa_source_output_info *info)
+{
+ m_idx = info->index;
+ m_displayName = QString::fromUtf8(pa_proplist_gets(info->proplist, \
PA_PROP_APPLICATION_NAME)); + m_iconName = \
QString::fromUtf8(pa_proplist_gets(info->proplist, PA_PROP_WINDOW_ICON_NAME)); + \
updateVolumes(info->volume); + if (m_muted != info->mute) {
+ emit muteChanged(info->mute);
+ }
+ m_muted = info->mute;
+}
+
+}
+
+#include "PulseSourceOutputControl.moc"
diff --git a/src/daemon2/backends/PulseSourceOutputControl.h \
b/src/daemon2/backends/PulseSourceOutputControl.h new file mode 100644
index 0000000..e537970
--- /dev/null
+++ b/src/daemon2/backends/PulseSourceOutputControl.h
@@ -0,0 +1,21 @@
+#ifndef PULSESOURCEOUTPUTCONTROL_H
+#define PULSESOURCEOUTPUTCONTROL_H
+
+#include "PulseControl.h"
+
+namespace Backends {
+
+class PulseSourceOutputControl : public PulseControl {
+ Q_OBJECT
+public:
+ PulseSourceOutputControl(pa_context *cxt, const pa_source_output_info *info, \
QObject *parent = 0); + void setVolume(Channel c, int v);
+ void setMute(bool yes);
+ void update(const pa_source_output_info *info);
+private:
+ void cb_client_info(pa_context *cxt, const pa_client_info *info, int eol, void \
*userdata); +};
+
+}
+
+#endif // PULSESOURCEOUTPUTCONTROL_H
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic