summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/phonon
diff options
context:
space:
mode:
authorJustin McPherson <justin.mcpherson@nokia.com>2010-03-25 06:58:42 (GMT)
committerJustin McPherson <justin.mcpherson@nokia.com>2010-03-25 06:58:42 (GMT)
commit9d324a07c9c87f972b165a43956424f5c92f80ad (patch)
tree740ace2a3aef7896b96a97a73fd31ec8bdfb5da7 /src/3rdparty/phonon
parent4931e0657af3f22478df8cb26faf178a9886e2d2 (diff)
downloadQt-9d324a07c9c87f972b165a43956424f5c92f80ad.zip
Qt-9d324a07c9c87f972b165a43956424f5c92f80ad.tar.gz
Qt-9d324a07c9c87f972b165a43956424f5c92f80ad.tar.bz2
Phonon; complete integration.
Diffstat (limited to 'src/3rdparty/phonon')
-rw-r--r--src/3rdparty/phonon/CMakeLists.txt4
-rw-r--r--src/3rdparty/phonon/gstreamer/backend.cpp27
-rw-r--r--src/3rdparty/phonon/phonon/audiodataoutput.cpp68
-rw-r--r--src/3rdparty/phonon/phonon/audiodataoutput.h129
-rw-r--r--src/3rdparty/phonon/phonon/audiodataoutput_p.h48
-rw-r--r--src/3rdparty/phonon/phonon/audiodataoutputinterface.h44
-rw-r--r--src/3rdparty/phonon/phonon/globalconfig.h71
-rw-r--r--src/3rdparty/phonon/phonon/pulsesupport.cpp1040
-rw-r--r--src/3rdparty/phonon/phonon/pulsesupport.h78
-rw-r--r--src/3rdparty/phonon/phonon/swiftslider.cpp103
-rw-r--r--src/3rdparty/phonon/phonon/swiftslider_p.h68
-rw-r--r--src/3rdparty/phonon/qt7/mediaobject.mm20
12 files changed, 1678 insertions, 22 deletions
diff --git a/src/3rdparty/phonon/CMakeLists.txt b/src/3rdparty/phonon/CMakeLists.txt
index ff89edb..ef7d6f5 100644
--- a/src/3rdparty/phonon/CMakeLists.txt
+++ b/src/3rdparty/phonon/CMakeLists.txt
@@ -70,6 +70,10 @@ if (CMAKE_COMPILER_IS_GNUCXX)
add_definitions(-DQT_NO_DEBUG)
endif (MINGW)
+ if (QT_USE_FRAMEWORKS)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -F${QT_LIBRARY_DIR}")
+ endif (QT_USE_FRAMEWORKS)
+
check_cxx_compiler_flag(-fPIE HAVE_FPIE_SUPPORT)
if(KDE4_ENABLE_FPIE)
if(HAVE_FPIE_SUPPORT)
diff --git a/src/3rdparty/phonon/gstreamer/backend.cpp b/src/3rdparty/phonon/gstreamer/backend.cpp
index 8c2b42f..729a1d3 100644
--- a/src/3rdparty/phonon/gstreamer/backend.cpp
+++ b/src/3rdparty/phonon/gstreamer/backend.cpp
@@ -220,14 +220,14 @@ QStringList Backend::availableMimeTypes() const
GstPluginFeature *feature = GST_PLUGIN_FEATURE(iter->data);
QString klass = gst_element_factory_get_klass(GST_ELEMENT_FACTORY(feature));
- if (klass == QLatin1String("Codec/Decoder") ||
- klass == QLatin1String("Codec/Decoder/Audio") ||
- klass == QLatin1String("Codec/Decoder/Video") ||
- klass == QLatin1String("Codec/Demuxer") ||
- klass == QLatin1String("Codec/Demuxer/Audio") ||
- klass == QLatin1String("Codec/Demuxer/Video") ||
- klass == QLatin1String("Codec/Parser") ||
- klass == QLatin1String("Codec/Parser/Audio") ||
+ if (klass == QLatin1String("Codec/Decoder") ||
+ klass == QLatin1String("Codec/Decoder/Audio") ||
+ klass == QLatin1String("Codec/Decoder/Video") ||
+ klass == QLatin1String("Codec/Demuxer") ||
+ klass == QLatin1String("Codec/Demuxer/Audio") ||
+ klass == QLatin1String("Codec/Demuxer/Video") ||
+ klass == QLatin1String("Codec/Parser") ||
+ klass == QLatin1String("Codec/Parser/Audio") ||
klass == QLatin1String("Codec/Parser/Video")) {
const GList *static_templates;
@@ -240,10 +240,13 @@ QStringList Backend::availableMimeTypes() const
GstCaps *caps = gst_static_pad_template_get_caps (padTemplate);
if (caps) {
- const GstStructure* capsStruct = gst_caps_get_structure (caps, 0);
- QString mime = QString::fromUtf8(gst_structure_get_name (capsStruct));
- if (!availableMimeTypes.contains(mime))
- availableMimeTypes.append(mime);
+ for (unsigned int struct_idx = 0; struct_idx < gst_caps_get_size (caps); struct_idx++) {
+
+ const GstStructure* capsStruct = gst_caps_get_structure (caps, struct_idx);
+ QString mime = QString::fromUtf8(gst_structure_get_name (capsStruct));
+ if (!availableMimeTypes.contains(mime))
+ availableMimeTypes.append(mime);
+ }
}
}
}
diff --git a/src/3rdparty/phonon/phonon/audiodataoutput.cpp b/src/3rdparty/phonon/phonon/audiodataoutput.cpp
new file mode 100644
index 0000000..6c737c2
--- /dev/null
+++ b/src/3rdparty/phonon/phonon/audiodataoutput.cpp
@@ -0,0 +1,68 @@
+/* This file is part of the KDE project
+ Copyright (C) 2005 Matthias Kretz <kretz@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) version 3, or any
+ later version accepted by the membership of KDE e.V. (or its
+ successor approved by the membership of KDE e.V.), Nokia Corporation
+ (or its successors, if any) and the KDE Free Qt Foundation, which shall
+ act as a proxy defined in Section 6 of version 3 of the license.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "audiodataoutput.h"
+#include "audiodataoutput_p.h"
+#include "factory_p.h"
+
+#define PHONON_CLASSNAME AudioDataOutput
+
+namespace Phonon
+{
+
+PHONON_HEIR_IMPL(AbstractAudioOutput)
+
+PHONON_GETTER(int, dataSize, d->dataSize)
+PHONON_GETTER(int, sampleRate, -1)
+PHONON_SETTER(setDataSize, dataSize, int)
+
+bool AudioDataOutputPrivate::aboutToDeleteBackendObject()
+{
+ Q_ASSERT(m_backendObject);
+ pBACKEND_GET(int, dataSize, "dataSize");
+
+ return AbstractAudioOutputPrivate::aboutToDeleteBackendObject();
+}
+
+void AudioDataOutputPrivate::setupBackendObject()
+{
+ Q_Q(AudioDataOutput);
+ Q_ASSERT(m_backendObject);
+ AbstractAudioOutputPrivate::setupBackendObject();
+
+ // set up attributes
+ pBACKEND_CALL1("setDataSize", int, dataSize);
+
+ qRegisterMetaType<QMap<Phonon::AudioDataOutput::Channel, QVector<qint16> > >("QMap<Phonon::AudioDataOutput::Channel, QVector<qint16> >");
+
+ QObject::connect(m_backendObject,
+ SIGNAL(dataReady(const QMap<Phonon::AudioDataOutput::Channel, QVector<qint16> > &)),
+ q, SIGNAL(dataReady(const QMap<Phonon::AudioDataOutput::Channel, QVector<qint16> > &)));
+ QObject::connect(m_backendObject, SIGNAL(endOfMedia(int)), q, SIGNAL(endOfMedia(int)));
+}
+
+} // namespace Phonon
+
+#include "audiodataoutput.moc"
+
+#undef PHONON_CLASSNAME
+// vim: sw=4 ts=4 tw=80
diff --git a/src/3rdparty/phonon/phonon/audiodataoutput.h b/src/3rdparty/phonon/phonon/audiodataoutput.h
new file mode 100644
index 0000000..8e8f8e0
--- /dev/null
+++ b/src/3rdparty/phonon/phonon/audiodataoutput.h
@@ -0,0 +1,129 @@
+/* This file is part of the KDE project
+ Copyright (C) 2005-2006 Matthias Kretz <kretz@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) version 3, or any
+ later version accepted by the membership of KDE e.V. (or its
+ successor approved by the membership of KDE e.V.), Nokia Corporation
+ (or its successors, if any) and the KDE Free Qt Foundation, which shall
+ act as a proxy defined in Section 6 of version 3 of the license.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+#ifndef Phonon_AUDIODATAOUTPUT_H
+#define Phonon_AUDIODATAOUTPUT_H
+
+#include "phonon_export.h"
+#include "abstractaudiooutput.h"
+#include "phonondefs.h"
+
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+template<typename T> class QVector;
+template<typename Key, typename T> class QMap;
+#endif
+
+namespace Phonon
+{
+ class AudioDataOutputPrivate;
+
+ /**
+ * \short This class gives you the audio data (for visualizations).
+ *
+ * This class implements a special AbstractAudioOutput that gives your
+ * application the audio data. Don't expect realtime performance. But
+ * the latencies should be low enough to use the audio data for
+ * visualizations. You can also use the audio data for further processing
+ * (e.g. encoding and saving to a file).
+ *
+ * \author Matthias Kretz <kretz@kde.org>
+ */
+ class PHONON_EXPORT AudioDataOutput : public AbstractAudioOutput
+ {
+ Q_OBJECT
+ K_DECLARE_PRIVATE(AudioDataOutput)
+ Q_ENUMS(Channel)
+ Q_PROPERTY(int dataSize READ dataSize WRITE setDataSize)
+ PHONON_HEIR(AudioDataOutput)
+ public:
+ /**
+ * Specifies the channel the audio data belongs to.
+ */
+ enum Channel
+ {
+ LeftChannel,
+ RightChannel,
+ CenterChannel,
+ LeftSurroundChannel,
+ RightSurroundChannel,
+ SubwooferChannel
+ };
+
+ /**
+ * Returns the currently used number of samples passed through
+ * the signal.
+ *
+ * \see setDataSize
+ */
+ int dataSize() const;
+
+ /**
+ * Returns the sample rate in Hz. Common sample rates are 44100 Hz
+ * and 48000 Hz. AudioDataOutput will not do any sample rate
+ * conversion for you. If you need to convert the sample rate you
+ * might want to take a look at libsamplerate. For visualizations it
+ * is often enough to do simple interpolation or even drop/duplicate
+ * samples.
+ *
+ * \return The sample rate as reported by the backend. If the
+ * backend is unavailable -1 is returned.
+ */
+ int sampleRate() const;
+
+ public Q_SLOTS:
+ /**
+ * Sets the number of samples to be passed in one signal emission.
+ *
+ * Defaults to 512 samples per emitted signal.
+ *
+ * \param size the number of samples
+ */
+ void setDataSize(int size);
+
+ Q_SIGNALS:
+ /**
+ * Emitted whenever another dataSize number of samples are ready.
+ *
+ * \param data A mapping of Channel to a vector holding the audio data.
+ */
+ void dataReady(const QMap<Phonon::AudioDataOutput::Channel, QVector<qint16> > &data);
+
+
+ /**
+ * This signal is emitted before the last dataReady signal of a
+ * media is emitted.
+ *
+ * If, for example, the playback of a media file has finished and the
+ * last audio data of that file is going to be passed with the next
+ * dataReady signal, and only the 28 first samples of the data
+ * vector are from that media file endOfMedia will be emitted right
+ * before dataReady with \p remainingSamples = 28.
+ *
+ * \param remainingSamples The number of samples in the next
+ * dataReady vector that belong to the media that was playing to
+ * this point.
+ */
+ void endOfMedia(int remainingSamples);
+ };
+} // namespace Phonon
+
+// vim: sw=4 ts=4 tw=80
+#endif // Phonon_AUDIODATAOUTPUT_H
diff --git a/src/3rdparty/phonon/phonon/audiodataoutput_p.h b/src/3rdparty/phonon/phonon/audiodataoutput_p.h
new file mode 100644
index 0000000..91103a9
--- /dev/null
+++ b/src/3rdparty/phonon/phonon/audiodataoutput_p.h
@@ -0,0 +1,48 @@
+/* This file is part of the KDE project
+ Copyright (C) 2006 Matthias Kretz <kretz@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) version 3, or any
+ later version accepted by the membership of KDE e.V. (or its
+ successor approved by the membership of KDE e.V.), Nokia Corporation
+ (or its successors, if any) and the KDE Free Qt Foundation, which shall
+ act as a proxy defined in Section 6 of version 3 of the license.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#ifndef AUDIODATAOUTPUT_P_H
+#define AUDIODATAOUTPUT_P_H
+
+#include "audiodataoutput.h"
+#include "abstractaudiooutput_p.h"
+
+namespace Phonon
+{
+
+class AudioDataOutputPrivate : public AbstractAudioOutputPrivate
+{
+ Q_DECLARE_PUBLIC(AudioDataOutput)
+ PHONON_PRIVATECLASS
+ protected:
+ AudioDataOutputPrivate()
+ : dataSize(512)
+ {
+ }
+
+ int dataSize;
+};
+
+} // namespace Phonon
+
+#endif // AUDIODATAOUTPUT_P_H
+// vim: sw=4 ts=4 tw=80
diff --git a/src/3rdparty/phonon/phonon/audiodataoutputinterface.h b/src/3rdparty/phonon/phonon/audiodataoutputinterface.h
new file mode 100644
index 0000000..bc1aad0
--- /dev/null
+++ b/src/3rdparty/phonon/phonon/audiodataoutputinterface.h
@@ -0,0 +1,44 @@
+/* This file is part of the KDE project
+ Copyright (C) 2008 Matthias Kretz <kretz@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) version 3, or any
+ later version accepted by the membership of KDE e.V. (or its
+ successor approved by the membership of KDE e.V.), Nokia Corporation
+ (or its successors, if any) and the KDE Free Qt Foundation, which shall
+ act as a proxy defined in Section 6 of version 3 of the license.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#ifndef PHONON_AUDIODATAOUTPUTINTERFACE_H
+#define PHONON_AUDIODATAOUTPUTINTERFACE_H
+
+namespace Phonon
+{
+
+class AudioDataOutput;
+
+class AudioDataOutputInterface
+{
+ public:
+ virtual ~AudioDataOutputInterface() {}
+
+ virtual AudioDataOutput *frontendObject() const = 0;
+ virtual void setFrontendObject(AudioDataOutput *) = 0;
+};
+
+} // namespace Phonon
+
+Q_DECLARE_INTERFACE(Phonon::AudioDataOutputInterface, "0AudioDataOutputInterface.phonon.kde.org")
+
+#endif // PHONON_AUDIODATAOUTPUTINTERFACE_H
diff --git a/src/3rdparty/phonon/phonon/globalconfig.h b/src/3rdparty/phonon/phonon/globalconfig.h
new file mode 100644
index 0000000..5233c7b
--- /dev/null
+++ b/src/3rdparty/phonon/phonon/globalconfig.h
@@ -0,0 +1,71 @@
+/* This file is part of the KDE project
+Copyright (C) 2006-2008 Matthias Kretz <kretz@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) version 3, or any
+ later version accepted by the membership of KDE e.V. (or its
+ successor approved by the membership of KDE e.V.), Nokia Corporation
+ (or its successors, if any) and the KDE Free Qt Foundation, which shall
+ act as a proxy defined in Section 6 of version 3 of the license.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#ifndef PHONON_GLOBALCONFIG_H
+#define PHONON_GLOBALCONFIG_H
+
+#include "phonon_export.h"
+#include "phononnamespace.h"
+#include "phonondefs.h"
+
+QT_BEGIN_HEADER
+QT_BEGIN_NAMESPACE
+
+namespace Phonon
+{
+ class GlobalConfigPrivate;
+
+ class PHONON_EXPORT GlobalConfig
+ {
+ K_DECLARE_PRIVATE(GlobalConfig)
+ public:
+ GlobalConfig();
+ virtual ~GlobalConfig();
+
+ enum DevicesToHideFlag {
+ ShowUnavailableDevices = 0,
+ ShowAdvancedDevices = 0,
+ HideAdvancedDevices = 1,
+ AdvancedDevicesFromSettings = 2,
+ HideUnavailableDevices = 4
+ };
+ bool hideAdvancedDevices() const;
+ void setHideAdvancedDevices(bool hide = true);
+ void setAudioOutputDeviceListFor(Phonon::Category category, QList<int> order);
+ QList<int> audioOutputDeviceListFor(Phonon::Category category, int override = AdvancedDevicesFromSettings) const;
+ int audioOutputDeviceFor(Phonon::Category category, int override = AdvancedDevicesFromSettings) const;
+
+#ifndef QT_NO_PHONON_AUDIOCAPTURE
+ void setAudioCaptureDeviceListFor(Phonon::Category category, QList<int> order);
+ QList<int> audioCaptureDeviceListFor(Phonon::Category category, int override = AdvancedDevicesFromSettings) const;
+ int audioCaptureDeviceFor(Phonon::Category category, int override = AdvancedDevicesFromSettings) const;
+#endif //QT_NO_PHONON_AUDIOCAPTURE
+
+ protected:
+ GlobalConfigPrivate *const k_ptr;
+ };
+} // namespace Phonon
+
+QT_END_NAMESPACE
+QT_END_HEADER
+
+#endif // PHONON_GLOBALCONFIG_H
diff --git a/src/3rdparty/phonon/phonon/pulsesupport.cpp b/src/3rdparty/phonon/phonon/pulsesupport.cpp
new file mode 100644
index 0000000..642843f
--- /dev/null
+++ b/src/3rdparty/phonon/phonon/pulsesupport.cpp
@@ -0,0 +1,1040 @@
+/* This file is part of the KDE project
+ Copyright (C) 2009 Colin Guthrie <cguthrie@mandriva.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) version 3, or any
+ later version accepted by the membership of KDE e.V. (or its
+ successor approved by the membership of KDE e.V.), Nokia Corporation
+ (or its successors, if any) and the KDE Free Qt Foundation, which shall
+ act as a proxy defined in Section 6 of version 3 of the license.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include <QtCore/QAbstractEventDispatcher>
+#include <QtCore/QEventLoop>
+#include <QtCore/QDebug>
+#include <QtCore/QStringList>
+
+#ifdef HAVE_PULSEAUDIO
+#include <glib.h>
+#include <pulse/pulseaudio.h>
+#include <pulse/xmalloc.h>
+#include <pulse/glib-mainloop.h>
+#ifdef HAVE_PULSEAUDIO_DEVICE_MANAGER
+# include <pulse/ext-device-manager.h>
+#endif
+#endif // HAVE_PULSEAUDIO
+
+#include "pulsesupport.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace Phonon
+{
+
+static PulseSupport* s_instance = NULL;
+
+#ifdef HAVE_PULSEAUDIO
+/***
+* Prints a conditional debug message based on the current debug level
+* If obj is provided, classname and objectname will be printed as well
+*
+* see debugLevel()
+*/
+
+static int debugLevel() {
+ static int level = -1;
+ if (level < 1) {
+ level = 0;
+ QString pulseenv = qgetenv("PHONON_PULSEAUDIO_DEBUG");
+ int l = pulseenv.toInt();
+ if (l > 0)
+ level = (l > 2 ? 2 : l);
+ }
+ return level;
+}
+
+static void logMessage(const QString &message, int priority = 2, QObject *obj=0);
+static void logMessage(const QString &message, int priority, QObject *obj)
+{
+ if (debugLevel() > 0) {
+ QString output;
+ if (obj) {
+ // Strip away namespace from className
+ QString className(obj->metaObject()->className());
+ int nameLength = className.length() - className.lastIndexOf(':') - 1;
+ className = className.right(nameLength);
+ output.sprintf("%s %s (%s %p)", message.toLatin1().constData(),
+ obj->objectName().toLatin1().constData(),
+ className.toLatin1().constData(), obj);
+ }
+ else {
+ output = message;
+ }
+ if (priority <= debugLevel()) {
+ qDebug() << QString("PulseSupport(%1): %2").arg(priority).arg(output);
+ }
+ }
+}
+
+
+class AudioDevice
+{
+ public:
+ inline
+ AudioDevice(QString name, QString desc, QString icon, uint32_t index)
+ : pulseName(name), pulseIndex(index)
+ {
+ properties["name"] = desc;
+ properties["description"] = ""; // We don't have descriptions (well we do, but we use them as the name!)
+ properties["icon"] = icon;
+ properties["available"] = (index != PA_INVALID_INDEX);
+ properties["isAdvanced"] = false; // Nothing is advanced!
+ }
+
+ // Needed for QMap
+ inline AudioDevice() {}
+
+ QString pulseName;
+ uint32_t pulseIndex;
+ QHash<QByteArray, QVariant> properties;
+};
+bool operator!=(const AudioDevice &a, const AudioDevice &b)
+{
+ return !(a.pulseName == b.pulseName && a.properties == b.properties);
+}
+
+class PulseUserData
+{
+ public:
+ inline
+ PulseUserData()
+ {
+ }
+
+ QMap<QString, AudioDevice> newOutputDevices;
+ QMap<Phonon::Category, QMap<int, int> > newOutputDevicePriorities; // prio, device
+
+ QMap<QString, AudioDevice> newCaptureDevices;
+ QMap<Phonon::Category, QMap<int, int> > newCaptureDevicePriorities; // prio, device
+};
+
+static QMap<QString, Phonon::Category> s_roleCategoryMap;
+
+static bool s_pulseActive = false;
+
+static pa_glib_mainloop *s_mainloop = NULL;
+static pa_context *s_context = NULL;
+
+
+
+static int s_deviceIndexCounter = 0;
+
+static QMap<QString, int> s_outputDeviceIndexes;
+static QMap<int, AudioDevice> s_outputDevices;
+static QMap<Phonon::Category, QMap<int, int> > s_outputDevicePriorities; // prio, device
+static QMap<QString, uint32_t> s_outputStreamIndexMap;
+
+static QMap<QString, int> s_captureDeviceIndexes;
+static QMap<int, AudioDevice> s_captureDevices;
+static QMap<Phonon::Category, QMap<int, int> > s_captureDevicePriorities; // prio, device
+static QMap<QString, uint32_t> s_captureStreamIndexMap;
+
+static void createGenericDevices()
+{
+ // OK so we don't have the device manager extension, but we can show a single device and fake it.
+ int index;
+ s_outputDeviceIndexes.clear();
+ s_outputDevices.clear();
+ s_outputDevicePriorities.clear();
+ index = s_deviceIndexCounter++;
+ s_outputDeviceIndexes.insert("sink:default", index);
+ s_outputDevices.insert(index, AudioDevice("sink:default", QObject::tr("PulseAudio Sound Server").toUtf8(), "audio-backend-pulseaudio", 0));
+ for (int i = Phonon::NoCategory; i <= Phonon::LastCategory; ++i) {
+ Phonon::Category cat = static_cast<Phonon::Category>(i);
+ s_outputDevicePriorities[cat].insert(0, index);
+ }
+
+ s_captureDeviceIndexes.clear();
+ s_captureDevices.clear();
+ s_captureDevicePriorities.clear();
+ index = s_deviceIndexCounter++;
+ s_captureDeviceIndexes.insert("source:default", index);
+ s_captureDevices.insert(index, AudioDevice("source:default", QObject::tr("PulseAudio Sound Server").toUtf8(), "audio-backend-pulseaudio", 0));
+ for (int i = Phonon::NoCategory; i <= Phonon::LastCategory; ++i) {
+ Phonon::Category cat = static_cast<Phonon::Category>(i);
+ s_captureDevicePriorities[cat].insert(0, index);
+ }
+}
+
+#ifdef HAVE_PULSEAUDIO_DEVICE_MANAGER
+static void ext_device_manager_read_cb(pa_context *c, const pa_ext_device_manager_info *info, int eol, void *userdata) {
+ Q_ASSERT(c);
+ Q_ASSERT(userdata);
+
+ PulseUserData *u = reinterpret_cast<PulseUserData*>(userdata);
+
+ if (eol < 0) {
+ logMessage(QString("Failed to initialize device manager extension: %1").arg(pa_strerror(pa_context_errno(c))));
+ logMessage("Falling back to single device mode");
+ createGenericDevices();
+ delete u;
+
+ // If this is our probe phase, exit now
+ if (s_context != c)
+ pa_context_disconnect(c);
+
+ return;
+ }
+
+ if (eol) {
+ // We're done reading the data, so order it by priority and copy it into the
+ // static variables where it can then be accessed by those classes that need it.
+
+ QMap<QString, AudioDevice>::iterator newdev_it;
+
+ // Check for new output devices or things changing about known output devices.
+ bool output_changed = false;
+ for (newdev_it = u->newOutputDevices.begin(); newdev_it != u->newOutputDevices.end(); ++newdev_it) {
+ QString name = newdev_it.key();
+
+ // The name + index map is always written when a new device is added.
+ Q_ASSERT(s_outputDeviceIndexes.contains(name));
+
+ int index = s_outputDeviceIndexes[name];
+ if (!s_outputDevices.contains(index)) {
+ // This is a totally new device
+ output_changed = true;
+ logMessage(QString("Brand New Output Device Found."));
+ s_outputDevices.insert(index, *newdev_it);
+ } else if (s_outputDevices[index] != *newdev_it) {
+ // We have this device already, but is it different?
+ output_changed = true;
+ logMessage(QString("Change to Existing Output Device (may be Added/Removed or something else)"));
+ s_outputDevices.remove(index);
+ s_outputDevices.insert(index, *newdev_it);
+ }
+ }
+ // Go through the output devices we know about and see if any are no longer mentioned in the list.
+ QMutableMapIterator<QString, int> output_existing_it(s_outputDeviceIndexes);
+ while (output_existing_it.hasNext()) {
+ output_existing_it.next();
+ if (!u->newOutputDevices.contains(output_existing_it.key())) {
+ output_changed = true;
+ logMessage(QString("Output Device Completely Removed"));
+ s_outputDevices.remove(output_existing_it.value());
+ output_existing_it.remove();
+ }
+ }
+
+ // Check for new capture devices or things changing about known capture devices.
+ bool capture_changed = false;
+ for (newdev_it = u->newCaptureDevices.begin(); newdev_it != u->newCaptureDevices.end(); ++newdev_it) {
+ QString name = newdev_it.key();
+
+ // The name + index map is always written when a new device is added.
+ Q_ASSERT(s_captureDeviceIndexes.contains(name));
+
+ int index = s_captureDeviceIndexes[name];
+ if (!s_captureDevices.contains(index)) {
+ // This is a totally new device
+ capture_changed = true;
+ logMessage(QString("Brand New Capture Device Found."));
+ s_captureDevices.insert(index, *newdev_it);
+ } else if (s_captureDevices[index] != *newdev_it) {
+ // We have this device already, but is it different?
+ capture_changed = true;
+ logMessage(QString("Change to Existing Capture Device (may be Added/Removed or something else)"));
+ s_captureDevices.remove(index);
+ s_captureDevices.insert(index, *newdev_it);
+ }
+ }
+ // Go through the capture devices we know about and see if any are no longer mentioned in the list.
+ QMutableMapIterator<QString, int> capture_existing_it(s_captureDeviceIndexes);
+ while (capture_existing_it.hasNext()) {
+ capture_existing_it.next();
+ if (!u->newCaptureDevices.contains(capture_existing_it.key())) {
+ capture_changed = true;
+ logMessage(QString("Capture Device Completely Removed"));
+ s_captureDevices.remove(capture_existing_it.value());
+ capture_existing_it.remove();
+ }
+ }
+
+ // Just copy accross the new priority lists as we know they are valid
+ if (s_outputDevicePriorities != u->newOutputDevicePriorities) {
+ output_changed = true;
+ s_outputDevicePriorities = u->newOutputDevicePriorities;
+ }
+ if (s_captureDevicePriorities != u->newCaptureDevicePriorities) {
+ capture_changed = true;
+ s_captureDevicePriorities = u->newCaptureDevicePriorities;
+ }
+
+ if (s_instance) {
+ // This wont be emitted durring the connection probe phase
+ // which is intensional
+ if (output_changed)
+ s_instance->emitObjectDescriptionChanged(AudioOutputDeviceType);
+ if (capture_changed)
+ s_instance->emitObjectDescriptionChanged(AudioCaptureDeviceType);
+ }
+
+ // We can free the user data as we will not be called again.
+ delete u;
+
+ // Some debug
+ logMessage(QString("Output Device Priority List:"));
+ for (int i = Phonon::NoCategory; i <= Phonon::LastCategory; ++i) {
+ Phonon::Category cat = static_cast<Phonon::Category>(i);
+ if (s_outputDevicePriorities.contains(cat)) {
+ logMessage(QString(" Phonon Category %1").arg(cat));
+ int count = 0;
+ foreach (int j, s_outputDevicePriorities[cat]) {
+ QHash<QByteArray, QVariant> &props = s_outputDevices[j].properties;
+ logMessage(QString(" %1. %2 (Available: %3)").arg(++count).arg(props["name"].toString()).arg(props["available"].toBool()));
+ }
+ }
+ }
+ logMessage(QString("Capture Device Priority List:"));
+ for (int i = Phonon::NoCategory; i <= Phonon::LastCategory; ++i) {
+ Phonon::Category cat = static_cast<Phonon::Category>(i);
+ if (s_captureDevicePriorities.contains(cat)) {
+ logMessage(QString(" Phonon Category %1").arg(cat));
+ int count = 0;
+ foreach (int j, s_captureDevicePriorities[cat]) {
+ QHash<QByteArray, QVariant> &props = s_captureDevices[j].properties;
+ logMessage(QString(" %1. %2 (Available: %3)").arg(++count).arg(props["name"].toString()).arg(props["available"].toBool()));
+ }
+ }
+ }
+
+ // If this is our probe phase, exit now as we're finished reading
+ // our device info and can exit and reconnect
+ if (s_context != c)
+ pa_context_disconnect(c);
+ }
+
+ if (!info)
+ return;
+
+ Q_ASSERT(info->name);
+ Q_ASSERT(info->description);
+ Q_ASSERT(info->icon);
+
+ // QString wrapper
+ QString name(info->name);
+ int index;
+ QMap<Phonon::Category, QMap<int, int> > *new_prio_map_cats; // prio, device
+ QMap<QString, AudioDevice> *new_devices;
+
+ if (name.startsWith("sink:")) {
+ new_devices = &u->newOutputDevices;
+ new_prio_map_cats = &u->newOutputDevicePriorities;
+
+ if (s_outputDeviceIndexes.contains(name))
+ index = s_outputDeviceIndexes[name];
+ else
+ index = s_outputDeviceIndexes[name] = s_deviceIndexCounter++;
+ } else if (name.startsWith("source:")) {
+ new_devices = &u->newCaptureDevices;
+ new_prio_map_cats = &u->newCaptureDevicePriorities;
+
+ if (s_captureDeviceIndexes.contains(name))
+ index = s_captureDeviceIndexes[name];
+ else
+ index = s_captureDeviceIndexes[name] = s_deviceIndexCounter++;
+ } else {
+ // This indicates a bug in pulseaudio.
+ return;
+ }
+
+ // Add the new device itself.
+ new_devices->insert(name, AudioDevice(name, info->description, info->icon, info->index));
+
+ // For each role in the priority, map it to a phonon category and store the order.
+ for (uint32_t i = 0; i < info->n_role_priorities; ++i) {
+ pa_ext_device_manager_role_priority_info* role_prio = &info->role_priorities[i];
+ Q_ASSERT(role_prio->role);
+
+ if (s_roleCategoryMap.contains(role_prio->role)) {
+ Phonon::Category cat = s_roleCategoryMap[role_prio->role];
+
+ (*new_prio_map_cats)[cat].insert(role_prio->priority, index);
+ }
+ }
+}
+
+static void ext_device_manager_subscribe_cb(pa_context *c, void *) {
+ Q_ASSERT(c);
+
+ pa_operation *o;
+ PulseUserData *u = new PulseUserData;
+ if (!(o = pa_ext_device_manager_read(c, ext_device_manager_read_cb, u))) {
+ logMessage(QString("pa_ext_device_manager_read() failed."));
+ delete u;
+ return;
+ }
+ pa_operation_unref(o);
+}
+#endif
+
+void sink_input_cb(pa_context *c, const pa_sink_input_info *i, int eol, void *userdata) {
+ Q_UNUSED(userdata);
+ Q_ASSERT(c);
+
+ if (eol < 0) {
+ if (pa_context_errno(c) == PA_ERR_NOENTITY)
+ return;
+
+ logMessage(QString("Sink input callback failure"));
+ return;
+ }
+
+ if (eol > 0)
+ return;
+
+ Q_ASSERT(i);
+
+ // loop through (*i) and extract phonon->streamindex...
+ const char *t;
+ if ((t = pa_proplist_gets(i->proplist, "phonon.streamid"))) {
+ logMessage(QString("Found PulseAudio stream index %1 for Phonon Output Stream %2").arg(i->index).arg(t));
+ s_outputStreamIndexMap[QString(t)] = i->index;
+
+ // Find the sink's phonon index and notify whoever cares...
+ if (PA_INVALID_INDEX != i->sink) {
+ bool found = false;
+ int device;
+ QMap<int, AudioDevice>::iterator it;
+ for (it = s_outputDevices.begin(); it != s_outputDevices.end(); ++it) {
+ if ((*it).pulseIndex == i->sink) {
+ found = true;
+ device = it.key();
+ break;
+ }
+ }
+ if (found) {
+ // OK so we just emit our signal
+ logMessage(QString("Letting the rest of phonon know about this"));
+ s_instance->emitUsingDevice(QString(t), device);
+ }
+ }
+ }
+}
+
+void source_output_cb(pa_context *c, const pa_source_output_info *i, int eol, void *userdata) {
+ Q_UNUSED(userdata);
+ Q_ASSERT(c);
+
+ if (eol < 0) {
+ if (pa_context_errno(c) == PA_ERR_NOENTITY)
+ return;
+
+ logMessage(QString("Source output callback failure"));
+ return;
+ }
+
+ if (eol > 0)
+ return;
+
+ Q_ASSERT(i);
+
+ // loop through (*i) and extract phonon->streamindex...
+ const char *t;
+ if ((t = pa_proplist_gets(i->proplist, "phonon.streamid"))) {
+ logMessage(QString("Found PulseAudio stream index %1 for Phonon Capture Stream %2").arg(i->index).arg(t));
+ s_captureStreamIndexMap[QString(t)] = i->index;
+
+ // Find the source's phonon index and notify whoever cares...
+ if (PA_INVALID_INDEX != i->source) {
+ bool found = false;
+ int device;
+ QMap<int, AudioDevice>::iterator it;
+ for (it = s_captureDevices.begin(); it != s_captureDevices.end(); ++it) {
+ if ((*it).pulseIndex == i->source) {
+ found = true;
+ device = it.key();
+ break;
+ }
+ }
+ if (found) {
+ // OK so we just emit our signal
+ logMessage(QString("Letting the rest of phonon know about this"));
+ s_instance->emitUsingDevice(QString(t), device);
+ }
+ }
+ }
+}
+
+static void subscribe_cb(pa_context *c, pa_subscription_event_type_t t, uint32_t index, void *userdata) {
+ Q_UNUSED(userdata);
+
+ switch (t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) {
+ case PA_SUBSCRIPTION_EVENT_SINK_INPUT:
+ if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) {
+ QString phononid = s_outputStreamIndexMap.key(index);
+ if (!phononid.isEmpty()) {
+ if (s_outputStreamIndexMap.contains(phononid)) {
+ logMessage(QString("Phonon Output Stream %1 is gone at the PA end. Marking it as invalid in our cache as we may reuse it.").arg(phononid));
+ s_outputStreamIndexMap[phononid] = PA_INVALID_INDEX;
+ } else {
+ logMessage(QString("Removing Phonon Output Stream %1 (it's gone!)").arg(phononid));
+ s_outputStreamIndexMap.remove(phononid);
+ }
+ }
+ } else {
+ pa_operation *o;
+ if (!(o = pa_context_get_sink_input_info(c, index, sink_input_cb, NULL))) {
+ logMessage(QString("pa_context_get_sink_input_info() failed"));
+ return;
+ }
+ pa_operation_unref(o);
+ }
+ break;
+
+ case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT:
+ if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) {
+ QString phononid = s_captureStreamIndexMap.key(index);
+ if (!phononid.isEmpty()) {
+ if (s_captureStreamIndexMap.contains(phononid)) {
+ logMessage(QString("Phonon Capture Stream %1 is gone at the PA end. Marking it as invalid in our cache as we may reuse it.").arg(phononid));
+ s_captureStreamIndexMap[phononid] = PA_INVALID_INDEX;
+ } else {
+ logMessage(QString("Removing Phonon Capture Stream %1 (it's gone!)").arg(phononid));
+ s_captureStreamIndexMap.remove(phononid);
+ }
+ }
+ } else {
+ pa_operation *o;
+ if (!(o = pa_context_get_source_output_info(c, index, source_output_cb, NULL))) {
+ logMessage(QString("pa_context_get_sink_input_info() failed"));
+ return;
+ }
+ pa_operation_unref(o);
+ }
+ break;
+ }
+}
+
+
+static const char* statename(pa_context_state_t state)
+{
+ switch (state)
+ {
+ case PA_CONTEXT_UNCONNECTED: return "Unconnected";
+ case PA_CONTEXT_CONNECTING: return "Connecting";
+ case PA_CONTEXT_AUTHORIZING: return "Authorizing";
+ case PA_CONTEXT_SETTING_NAME: return "Setting Name";
+ case PA_CONTEXT_READY: return "Ready";
+ case PA_CONTEXT_FAILED: return "Failed";
+ case PA_CONTEXT_TERMINATED: return "Terminated";
+ }
+
+ static QString unknown;
+ unknown = QString("Unknown state: %0").arg(state);
+ return unknown.toAscii().constData();
+}
+
+static void context_state_callback(pa_context *c, void *)
+{
+ Q_ASSERT(c);
+
+ logMessage(QString("context_state_callback %1").arg(statename(pa_context_get_state(c))));
+ pa_context_state_t state = pa_context_get_state(c);
+ if (state == PA_CONTEXT_READY) {
+ // We've connected to PA, so it is active
+ s_pulseActive = true;
+
+ // Attempt to load things up
+ pa_operation *o;
+
+ // 1. Register for the stream changes (except during probe)
+ if (s_context == c) {
+ pa_context_set_subscribe_callback(c, subscribe_cb, NULL);
+
+ if (!(o = pa_context_subscribe(c, (pa_subscription_mask_t)
+ (PA_SUBSCRIPTION_MASK_SINK_INPUT|
+ PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT), NULL, NULL))) {
+ logMessage(QString("pa_context_subscribe() failed"));
+ return;
+ }
+ pa_operation_unref(o);
+ }
+
+#ifdef HAVE_PULSEAUDIO_DEVICE_MANAGER
+ // 2a. Attempt to initialise Device Manager info (except during probe)
+ if (s_context == c) {
+ pa_ext_device_manager_set_subscribe_cb(c, ext_device_manager_subscribe_cb, NULL);
+ if (!(o = pa_ext_device_manager_subscribe(c, 1, NULL, NULL))) {
+ logMessage(QString("pa_ext_device_manager_subscribe() failed"));
+ return;
+ }
+ pa_operation_unref(o);
+ }
+
+ // 3. Attempt to read info from Device Manager
+ PulseUserData *u = new PulseUserData;
+ if (!(o = pa_ext_device_manager_read(c, ext_device_manager_read_cb, u))) {
+ logMessage(QString("pa_ext_device_manager_read() failed. Attempting to continue without device manager support"));
+ createGenericDevices();
+ delete u;
+
+ // If this is our probe phase, exit immediately
+ if (s_context != c)
+ pa_context_disconnect(c);
+
+ return;
+ }
+ pa_operation_unref(o);
+
+#else
+ // If we know do not have Device Manager support, we just create our dummy devices now
+ createGenericDevices();
+
+ // If this is our probe phase, exit immediately
+ if (s_context != c)
+ pa_context_disconnect(c);
+#endif
+ } else if (!PA_CONTEXT_IS_GOOD(state)) {
+ /// @todo Deal with reconnection...
+ //logMessage("Connection to PulseAudio lost");
+
+ // If this is our probe phase, exit our context immediately
+ if (s_context != c)
+ pa_context_disconnect(c);
+ }
+}
+#endif // HAVE_PULSEAUDIO
+
+
+PulseSupport* PulseSupport::getInstance()
+{
+ if (NULL == s_instance) {
+ s_instance = new PulseSupport();
+ }
+ return s_instance;
+}
+
+void PulseSupport::shutdown()
+{
+ if (NULL != s_instance) {
+ delete s_instance;
+ s_instance = NULL;
+ }
+}
+
+PulseSupport::PulseSupport()
+ : QObject(), mEnabled(false)
+{
+#ifdef HAVE_PULSEAUDIO
+ // Initialise our map (is there a better way to do this?)
+ s_roleCategoryMap["none"] = Phonon::NoCategory;
+ s_roleCategoryMap["video"] = Phonon::VideoCategory;
+ s_roleCategoryMap["music"] = Phonon::MusicCategory;
+ s_roleCategoryMap["game"] = Phonon::GameCategory;
+ s_roleCategoryMap["event"] = Phonon::NotificationCategory;
+ s_roleCategoryMap["phone"] = Phonon::CommunicationCategory;
+ //s_roleCategoryMap["animation"]; // No Mapping
+ //s_roleCategoryMap["production"]; // No Mapping
+ s_roleCategoryMap["a11y"] = Phonon::AccessibilityCategory;
+
+ // To allow for easy debugging, give an easy way to disable this pulseaudio check
+ QString pulseenv = qgetenv("PHONON_PULSEAUDIO_DISABLE");
+ if (pulseenv.toInt()) {
+ logMessage("PulseAudio support disabled: PHONON_PULSEAUDIO_DISABLE is set");
+ return;
+ }
+
+ // We require a glib event loop
+ if (QLatin1String(QAbstractEventDispatcher::instance()->metaObject()->className())
+ != "QGuiEventDispatcherGlib") {
+ logMessage("Disabling PulseAudio integration for lack of GLib event loop.");
+ return;
+ }
+
+ // First of all conenct to PA via simple/blocking means and if that succeeds,
+ // use a fully async integrated mainloop method to connect and get proper support.
+ pa_mainloop *p_test_mainloop;
+ if (!(p_test_mainloop = pa_mainloop_new())) {
+ logMessage("PulseAudio support disabled: Unable to create mainloop");
+ return;
+ }
+
+ pa_context *p_test_context;
+ if (!(p_test_context = pa_context_new(pa_mainloop_get_api(p_test_mainloop), "libphonon-probe"))) {
+ logMessage("PulseAudio support disabled: Unable to create context");
+ pa_mainloop_free(p_test_mainloop);
+ return;
+ }
+
+ logMessage("Probing for PulseAudio...");
+ // (cg) Convert to PA_CONTEXT_NOFLAGS when PulseAudio 0.9.19 is required
+ if (pa_context_connect(p_test_context, NULL, static_cast<pa_context_flags_t>(0), NULL) < 0) {
+ logMessage(QString("PulseAudio support disabled: %1").arg(pa_strerror(pa_context_errno(p_test_context))));
+ pa_context_disconnect(p_test_context);
+ pa_context_unref(p_test_context);
+ pa_mainloop_free(p_test_mainloop);
+ return;
+ }
+
+ pa_context_set_state_callback(p_test_context, &context_state_callback, NULL);
+ for (;;) {
+ pa_mainloop_iterate(p_test_mainloop, 1, NULL);
+
+ if (!PA_CONTEXT_IS_GOOD(pa_context_get_state(p_test_context))) {
+ logMessage("PulseAudio probe complete.");
+ break;
+ }
+ }
+ pa_context_disconnect(p_test_context);
+ pa_context_unref(p_test_context);
+ pa_mainloop_free(p_test_mainloop);
+
+ if (!s_pulseActive) {
+ logMessage("PulseAudio support is not available.");
+ return;
+ }
+
+ // If we're still here, PA is available.
+ logMessage("PulseAudio support enabled");
+
+ // Now we connect for real using a proper main loop that we can forget
+ // all about processing.
+ s_mainloop = pa_glib_mainloop_new(NULL);
+ Q_ASSERT(s_mainloop);
+ pa_mainloop_api *api = pa_glib_mainloop_get_api(s_mainloop);
+
+ s_context = pa_context_new(api, "libphonon");
+ // (cg) Convert to PA_CONTEXT_NOFLAGS when PulseAudio 0.9.19 is required
+ if (pa_context_connect(s_context, NULL, static_cast<pa_context_flags_t>(0), 0) >= 0)
+ pa_context_set_state_callback(s_context, &context_state_callback, NULL);
+#endif
+}
+
+PulseSupport::~PulseSupport()
+{
+#ifdef HAVE_PULSEAUDIO
+ if (s_context) {
+ pa_context_disconnect(s_context);
+ s_context = NULL;
+ }
+
+ if (s_mainloop) {
+ pa_glib_mainloop_free(s_mainloop);
+ s_mainloop = NULL;
+ }
+#endif
+}
+
+bool PulseSupport::isActive()
+{
+#ifdef HAVE_PULSEAUDIO
+ return mEnabled && s_pulseActive;
+#else
+ return false;
+#endif
+}
+
+void PulseSupport::enable(bool enabled)
+{
+ mEnabled = enabled;
+}
+
+QList<int> PulseSupport::objectDescriptionIndexes(ObjectDescriptionType type) const
+{
+ QList<int> list;
+
+ if (type != AudioOutputDeviceType && type != AudioCaptureDeviceType)
+ return list;
+
+#ifdef HAVE_PULSEAUDIO
+ if (s_pulseActive) {
+ switch (type) {
+
+ case AudioOutputDeviceType: {
+ QMap<QString, int>::iterator it;
+ for (it = s_outputDeviceIndexes.begin(); it != s_outputDeviceIndexes.end(); ++it) {
+ list.append(*it);
+ }
+ break;
+ }
+ case AudioCaptureDeviceType: {
+ QMap<QString, int>::iterator it;
+ for (it = s_captureDeviceIndexes.begin(); it != s_captureDeviceIndexes.end(); ++it) {
+ list.append(*it);
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ }
+#endif
+
+ return list;
+}
+
+QHash<QByteArray, QVariant> PulseSupport::objectDescriptionProperties(ObjectDescriptionType type, int index) const
+{
+ QHash<QByteArray, QVariant> ret;
+
+ if (type != AudioOutputDeviceType && type != AudioCaptureDeviceType)
+ return ret;
+
+#ifndef HAVE_PULSEAUDIO
+ Q_UNUSED(index);
+#else
+ if (s_pulseActive) {
+ switch (type) {
+
+ case AudioOutputDeviceType:
+ Q_ASSERT(s_outputDevices.contains(index));
+ ret = s_outputDevices[index].properties;
+ break;
+
+ case AudioCaptureDeviceType:
+ Q_ASSERT(s_captureDevices.contains(index));
+ ret = s_captureDevices[index].properties;
+ break;
+
+ default:
+ break;
+ }
+ }
+#endif
+
+ return ret;
+}
+
+QList<int> PulseSupport::objectIndexesByCategory(ObjectDescriptionType type, Category category) const
+{
+ QList<int> ret;
+
+ if (type != AudioOutputDeviceType && type != AudioCaptureDeviceType)
+ return ret;
+
+#ifndef HAVE_PULSEAUDIO
+ Q_UNUSED(category);
+#else
+ if (s_pulseActive) {
+ switch (type) {
+
+ case AudioOutputDeviceType:
+ if (s_outputDevicePriorities.contains(category))
+ ret = s_outputDevicePriorities[category].values();
+ break;
+
+ case AudioCaptureDeviceType:
+ if (s_captureDevicePriorities.contains(category))
+ ret = s_captureDevicePriorities[category].values();
+ break;
+
+ default:
+ break;
+ }
+ }
+#endif
+
+ return ret;
+}
+
+#ifdef HAVE_PULSEAUDIO
+static void setDevicePriority(Category category, QStringList list)
+{
+ QString role = s_roleCategoryMap.key(category);
+ if (role.isEmpty())
+ return;
+
+ logMessage(QString("Reindexing %1: %2").arg(role).arg(list.join(", ")));
+
+ char **devices;
+ devices = pa_xnew(char *, list.size()+1);
+ int i = 0;
+ foreach (QString str, list) {
+ devices[i++] = pa_xstrdup(str.toUtf8().constData());
+ }
+ devices[list.size()] = NULL;
+
+#ifdef HAVE_PULSEAUDIO_DEVICE_MANAGER
+ pa_operation *o;
+ if (!(o = pa_ext_device_manager_reorder_devices_for_role(s_context, role.toUtf8().constData(), (const char**)devices, NULL, NULL)))
+ logMessage(QString("pa_ext_device_manager_reorder_devices_for_role() failed"));
+ else
+ pa_operation_unref(o);
+#endif
+
+ for (i = 0; i < list.size(); ++i)
+ pa_xfree(devices[i]);
+ pa_xfree(devices);
+}
+#endif
+
+void PulseSupport::setOutputDevicePriorityForCategory(Category category, QList<int> order)
+{
+#ifndef HAVE_PULSEAUDIO
+ Q_UNUSED(category);
+ Q_UNUSED(order);
+#else
+ QStringList list;
+ QList<int>::iterator it;
+
+ for (it = order.begin(); it != order.end(); ++it) {
+ if (s_outputDevices.contains(*it)) {
+ list << s_outputDeviceIndexes.key(*it);
+ }
+ }
+ setDevicePriority(category, list);
+#endif
+}
+
+void PulseSupport::setCaptureDevicePriorityForCategory(Category category, QList<int> order)
+{
+#ifndef HAVE_PULSEAUDIO
+ Q_UNUSED(category);
+ Q_UNUSED(order);
+#else
+ QStringList list;
+ QList<int>::iterator it;
+
+ for (it = order.begin(); it != order.end(); ++it) {
+ if (s_captureDevices.contains(*it)) {
+ list << s_captureDeviceIndexes.key(*it);
+ }
+ }
+ setDevicePriority(category, list);
+#endif
+}
+
+void PulseSupport::setStreamPropList(Category category, QString streamUuid)
+{
+#ifndef HAVE_PULSEAUDIO
+ Q_UNUSED(category);
+ Q_UNUSED(streamUuid);
+#else
+ QString role = s_roleCategoryMap.key(category);
+ if (role.isEmpty())
+ return;
+
+ logMessage(QString("Setting role to %1 for streamindex %2").arg(role).arg(streamUuid));
+ setenv("PULSE_PROP_media.role", role.toLatin1().constData(), 1);
+ setenv("PULSE_PROP_phonon.streamid", streamUuid.toLatin1().constData(), 1);
+#endif
+}
+
+void PulseSupport::emitObjectDescriptionChanged(ObjectDescriptionType type)
+{
+ emit objectDescriptionChanged(type);
+}
+
+void PulseSupport::emitUsingDevice(QString streamUuid, int device)
+{
+ emit usingDevice(streamUuid, device);
+}
+
+bool PulseSupport::setOutputDevice(QString streamUuid, int device) {
+#ifndef HAVE_PULSEAUDIO
+ Q_UNUSED(streamUuid);
+ Q_UNUSED(device);
+ return false;
+#else
+ if (s_outputDevices.size() < 2)
+ return true;
+
+ if (!s_outputDevices.contains(device)) {
+ logMessage(QString("Attempting to set Output Device for invalid device id %1.").arg(device));
+ return false;
+ }
+ const QVariant var = s_outputDevices[device].properties["name"];
+ logMessage(QString("Attempting to set Output Device to '%1' for Output Stream %2").arg(var.toString()).arg(streamUuid));
+
+ // Attempt to look up the pulse stream index.
+ if (s_outputStreamIndexMap.contains(streamUuid) && s_outputStreamIndexMap[streamUuid] != PA_INVALID_INDEX) {
+ logMessage(QString("... Found in map. Moving now"));
+
+ uint32_t pulse_device_index = s_outputDevices[device].pulseIndex;
+ uint32_t pulse_stream_index = s_outputStreamIndexMap[streamUuid];
+
+ logMessage(QString("Moving Pulse Sink Input %1 to '%2' (Pulse Sink %3)").arg(pulse_stream_index).arg(var.toString()).arg(pulse_device_index));
+
+ /// @todo Find a way to move the stream without saving it... We don't want to pollute the stream restore db.
+ pa_operation* o;
+ if (!(o = pa_context_move_sink_input_by_index(s_context, pulse_stream_index, pulse_device_index, NULL, NULL))) {
+ logMessage(QString("pa_context_move_sink_input_by_index() failed"));
+ return false;
+ }
+ pa_operation_unref(o);
+ } else {
+ logMessage(QString("... Not found in map. We will be notified of the device when the stream appears and we can process any moves needed then"));
+ }
+ return true;
+#endif
+}
+
+bool PulseSupport::setCaptureDevice(QString streamUuid, int device) {
+#ifndef HAVE_PULSEAUDIO
+ Q_UNUSED(streamUuid);
+ Q_UNUSED(device);
+ return false;
+#else
+ if (s_captureDevices.size() < 2)
+ return true;
+
+ if (!s_captureDevices.contains(device)) {
+ logMessage(QString("Attempting to set Capture Device for invalid device id %1.").arg(device));
+ return false;
+ }
+ const QVariant var = s_captureDevices[device].properties["name"];
+ logMessage(QString("Attempting to set Capture Device to '%1' for Capture Stream %2").arg(var.toString()).arg(streamUuid));
+
+ // Attempt to look up the pulse stream index.
+ if (s_captureStreamIndexMap.contains(streamUuid) && s_captureStreamIndexMap[streamUuid] == PA_INVALID_INDEX) {
+ logMessage(QString("... Found in map. Moving now"));
+
+ uint32_t pulse_device_index = s_captureDevices[device].pulseIndex;
+ uint32_t pulse_stream_index = s_captureStreamIndexMap[streamUuid];
+
+ logMessage(QString("Moving Pulse Source Output %1 to '%2' (Pulse Sink %3)").arg(pulse_stream_index).arg(var.toString()).arg(pulse_device_index));
+
+ /// @todo Find a way to move the stream without saving it... We don't want to pollute the stream restore db.
+ pa_operation* o;
+ if (!(o = pa_context_move_source_output_by_index(s_context, pulse_stream_index, pulse_device_index, NULL, NULL))) {
+ logMessage(QString("pa_context_move_source_output_by_index() failed"));
+ return false;
+ }
+ pa_operation_unref(o);
+ } else {
+ logMessage(QString("... Not found in map. We will be notified of the device when the stream appears and we can process any moves needed then"));
+ }
+ return true;
+#endif
+}
+
+void PulseSupport::clearStreamCache(QString streamUuid) {
+#ifndef HAVE_PULSEAUDIO
+ Q_UNUSED(streamUuid);
+ return;
+#else
+ logMessage(QString("Clearing stream cache for stream %1").arg(streamUuid));
+ s_outputStreamIndexMap.remove(streamUuid);
+ s_captureStreamIndexMap.remove(streamUuid);
+#endif
+}
+
+} // namespace Phonon
+
+QT_END_NAMESPACE
+
+#include "moc_pulsesupport.cpp"
+
+// vim: sw=4 ts=4
diff --git a/src/3rdparty/phonon/phonon/pulsesupport.h b/src/3rdparty/phonon/phonon/pulsesupport.h
new file mode 100644
index 0000000..c38bece
--- /dev/null
+++ b/src/3rdparty/phonon/phonon/pulsesupport.h
@@ -0,0 +1,78 @@
+/* This file is part of the KDE project
+ Copyright (C) 2009 Colin Guthrie <cguthrie@mandriva.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) version 3, or any
+ later version accepted by the membership of KDE e.V. (or its
+ successor approved by the membership of KDE e.V.), Nokia Corporation
+ (or its successors, if any) and the KDE Free Qt Foundation, which shall
+ act as a proxy defined in Section 6 of version 3 of the license.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#ifndef PHONON_PULSESUPPORT_H
+#define PHONON_PULSESUPPORT_H
+
+#include "phonon_export.h"
+#include "phononnamespace.h"
+#include "objectdescription.h"
+
+#include <QtCore/QtGlobal>
+#include <QtCore/QSet>
+
+QT_BEGIN_HEADER
+QT_BEGIN_NAMESPACE
+
+namespace Phonon
+{
+ class PHONON_EXPORT PulseSupport : public QObject
+ {
+ Q_OBJECT
+ public:
+ static PulseSupport* getInstance();
+ static void shutdown();
+
+ bool isActive();
+ void enable(bool enabled = true);
+
+ QList<int> objectDescriptionIndexes(ObjectDescriptionType type) const;
+ QHash<QByteArray, QVariant> objectDescriptionProperties(ObjectDescriptionType type, int index) const;
+ QList<int> objectIndexesByCategory(ObjectDescriptionType type, Category category) const;
+
+ void setOutputDevicePriorityForCategory(Category category, QList<int> order);
+ void setCaptureDevicePriorityForCategory(Category category, QList<int> order);
+
+ void setStreamPropList(Category category, QString streamUuid);
+ void emitObjectDescriptionChanged(ObjectDescriptionType);
+ void emitUsingDevice(QString streamUuid, int device);
+
+ bool setOutputDevice(QString streamUuid, int device);
+ bool setCaptureDevice(QString streamUuid, int device);
+ void clearStreamCache(QString streamUuid);
+
+ signals:
+ void objectDescriptionChanged(ObjectDescriptionType);
+ void usingDevice(QString streamUuid, int device);
+
+ private:
+ PulseSupport();
+ ~PulseSupport();
+
+ bool mEnabled;
+ };
+} // namespace Phonon
+
+QT_END_NAMESPACE
+QT_END_HEADER
+
+#endif // PHONON_PULSESUPPORT_H
diff --git a/src/3rdparty/phonon/phonon/swiftslider.cpp b/src/3rdparty/phonon/phonon/swiftslider.cpp
new file mode 100644
index 0000000..1e274aa
--- /dev/null
+++ b/src/3rdparty/phonon/phonon/swiftslider.cpp
@@ -0,0 +1,103 @@
+/* This file is part of the KDE project
+ Copyright (C) 2006-2008 Ricardo Villalba <rvm@escomposlinux.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) version 3, or any
+ later version accepted by the membership of KDE e.V. (or its
+ successor approved by the membership of KDE e.V.), Nokia Corporation
+ (or its successors, if any) and the KDE Free Qt Foundation, which shall
+ act as a proxy defined in Section 6 of version 3 of the license.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "swiftslider_p.h"
+
+#include <QtGui/QMouseEvent>
+#include <QtGui/QStyle>
+#include <QtGui/QStyleOption>
+
+QT_BEGIN_NAMESPACE
+
+#if !defined(QT_NO_PHONON_SEEKSLIDER) && !defined(QT_NO_PHONON_VOLUMESLIDER)
+
+namespace Phonon
+{
+
+SwiftSlider::SwiftSlider(Qt::Orientation orientation, QWidget * parent)
+ : QSlider(orientation, parent)
+{
+}
+
+SwiftSlider::~SwiftSlider()
+{
+}
+
+// Function copied from qslider.cpp
+inline int SwiftSlider::pick(const QPoint &pt) const
+{
+ return orientation() == Qt::Horizontal ? pt.x() : pt.y();
+}
+
+// Function copied from qslider.cpp and modified to make it compile
+int SwiftSlider::pixelPosToRangeValue(int pos) const
+{
+ QStyleOptionSlider opt;
+ initStyleOption(&opt);
+ QRect gr = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove, this);
+ QRect sr = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);
+ int sliderMin, sliderMax, sliderLength;
+
+ if (orientation() == Qt::Horizontal) {
+ sliderLength = sr.width();
+ sliderMin = gr.x();
+ sliderMax = gr.right() - sliderLength + 1;
+ } else {
+ sliderLength = sr.height();
+ sliderMin = gr.y();
+ sliderMax = gr.bottom() - sliderLength + 1;
+ }
+ return QStyle::sliderValueFromPosition(minimum(), maximum(), pos - sliderMin,
+ sliderMax - sliderMin, opt.upsideDown);
+}
+
+// Based on code from qslider.cpp
+void SwiftSlider::mousePressEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton) {
+ QStyleOptionSlider opt;
+ initStyleOption(&opt);
+ const QRect sliderRect = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);
+ const QPoint center = sliderRect.center() - sliderRect.topLeft();
+ // to take half of the slider off for the setSliderPosition call we use the center - topLeft
+
+ if (!sliderRect.contains(event->pos())) {
+ event->accept();
+
+ setSliderPosition(pixelPosToRangeValue(pick(event->pos() - center)));
+ triggerAction(SliderMove);
+ setRepeatAction(SliderNoAction);
+ } else {
+ QSlider::mousePressEvent(event);
+ }
+ } else {
+ QSlider::mousePressEvent(event);
+ }
+}
+
+} // namespace Phonon
+
+#endif //QT_NO_PHONON_VOLUMESLIDER && QT_NO_PHONON_VOLUMESLIDER
+
+QT_END_NAMESPACE
+
+#include "moc_swiftslider_p.cpp"
diff --git a/src/3rdparty/phonon/phonon/swiftslider_p.h b/src/3rdparty/phonon/phonon/swiftslider_p.h
new file mode 100644
index 0000000..b063b47
--- /dev/null
+++ b/src/3rdparty/phonon/phonon/swiftslider_p.h
@@ -0,0 +1,68 @@
+/* This file is part of the KDE project
+ Copyright (C) 2006-2008 Ricardo Villalba <rvm@escomposlinux.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) version 3, or any
+ later version accepted by the membership of KDE e.V. (or its
+ successor approved by the membership of KDE e.V.), Nokia Corporation
+ (or its successors, if any) and the KDE Free Qt Foundation, which shall
+ act as a proxy defined in Section 6 of version 3 of the license.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#ifndef SWIFTSLIDER_H
+#define SWIFTSLIDER_H
+
+#include <QtGui/QSlider>
+
+QT_BEGIN_NAMESPACE
+
+#if !defined(QT_NO_PHONON_SEEKSLIDER) && !defined(QT_NO_PHONON_VOLUMESLIDER)
+
+namespace Phonon
+{
+
+/** \class SwiftSlider swiftslider_p.h phonon/SwiftSlider
+ * \short Modified QSlider that allows sudden/quick moves instead of stepped moves ("Click'n'Go" QSlider)
+ *
+ * This is an internal class used by SeekSlider and VolumeSlider.
+ *
+ * Ricardo Villalba, the original author of MySlider.cpp (from the SMPlayer project)
+ * gave his permission for the inclusion of this code inside Phonon by
+ * switching MySlider.cpp to the LGPLv2.1+ license.
+ * See http://smplayer.svn.sourceforge.net/viewvc/smplayer/smplayer/trunk/src/myslider.cpp?revision=2406&view=markup
+ *
+ * The original discussion about a "Click'n'Go QSlider": http://lists.trolltech.com/qt-interest/2006-11/msg00363.html
+ *
+ * \ingroup PhononWidgets
+ */
+class SwiftSlider : public QSlider
+{
+ Q_OBJECT
+public:
+ SwiftSlider(Qt::Orientation orientation, QWidget * parent);
+ ~SwiftSlider();
+
+private:
+ void mousePressEvent(QMouseEvent *event);
+ inline int pick(const QPoint &pt) const;
+ int pixelPosToRangeValue(int pos) const;
+};
+
+} // namespace Phonon
+
+#endif //QT_NO_PHONON_VOLUMESLIDER && QT_NO_PHONON_VOLUMESLIDER
+
+QT_END_NAMESPACE
+
+#endif //SWIFTSLIDER_H
diff --git a/src/3rdparty/phonon/qt7/mediaobject.mm b/src/3rdparty/phonon/qt7/mediaobject.mm
index f8d635a..002c337 100644
--- a/src/3rdparty/phonon/qt7/mediaobject.mm
+++ b/src/3rdparty/phonon/qt7/mediaobject.mm
@@ -88,7 +88,7 @@ bool MediaObject::setState(Phonon::State state)
emit stateChanged(m_state, prevState);
if (m_state != state){
// End-application did something
- // upon receiving the signal.
+ // upon receiving the signal.
return false;
}
}
@@ -122,7 +122,7 @@ void MediaObject::inspectGraph()
// Inspect the graph to check wether there are any
// effects or outputs connected. This will have
// influence on the audio system and video system that ends up beeing used:
- int prevVideoOutputCount = m_videoOutputCount;
+ int prevVideoOutputCount = m_videoOutputCount;
m_audioEffectCount = 0;
m_audioOutputCount = 0;
m_videoEffectCount = 0;
@@ -134,7 +134,7 @@ void MediaObject::inspectGraph()
if (m_videoOutputCount != prevVideoOutputCount){
MediaNodeEvent e1(MediaNodeEvent::VideoOutputCountChanged, &m_videoOutputCount);
notify(&e1);
- }
+ }
}
void MediaObject::setupAudioSystem()
@@ -167,14 +167,14 @@ void MediaObject::setupAudioSystem()
if (newAudioSystem == m_audioSystem)
return;
-
+
// Enable selected audio system:
- m_audioSystem = newAudioSystem;
+ m_audioSystem = newAudioSystem;
switch (newAudioSystem){
case AS_Silent:
m_audioGraph->stop();
m_videoPlayer->enableAudio(false);
- m_nextVideoPlayer->enableAudio(false);
+ m_nextVideoPlayer->enableAudio(false);
m_audioPlayer->enableAudio(false);
m_nextAudioPlayer->enableAudio(false);
break;
@@ -260,7 +260,7 @@ void MediaObject::setSource(const MediaSource &source)
return;
if (!m_videoPlayer->canPlayMedia())
SET_ERROR("Cannot play media.", FATAL_ERROR)
-
+
// The state might have changed from LoadingState
// as a response to an error state change. So we
// need to check it before stopping:
@@ -382,7 +382,7 @@ void MediaObject::play()
if (!m_videoPlayer->canPlayMedia())
return;
if (!setState(Phonon::PlayingState))
- return;
+ return;
if (m_audioSystem == AS_Graph){
m_audioGraph->start();
m_mediaObjectAudioNode->setMute(true);
@@ -446,7 +446,7 @@ void MediaObject::seek(qint64 milliseconds)
m_videoPlayer->seek(milliseconds);
m_audioPlayer->seek(m_videoPlayer->currentTime());
m_mediaObjectAudioNode->setMute(false);
-
+
// Update time and cancel pending swap:
if (m_currentTime < m_videoPlayer->duration())
m_waitNextSwap = false;
@@ -557,7 +557,7 @@ bool MediaObject::isSeekable() const
qint64 MediaObject::currentTime() const
{
IMPLEMENTED_SILENT;
- const_cast<MediaObject *>(this)->updateCurrentTime();
+ const_cast<MediaObject *>(this)->updateCurrentTime();
return m_currentTime;
}