[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: kdereview/phonon/gstreamer
From: Matthias Kretz <kretz () kde ! org>
Date: 2008-04-23 8:50:22
Message-ID: 1208940622.817292.29206.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 800069 by mkretz:
implement new setOutputDevice function for libphonon in kdelibs trunk, this
gets phonon-gstreamer a big step closer to handle devices as good as \
phonon-xine
M +75 -1 audiooutput.cpp
M +5 -0 audiooutput.h
--- trunk/kdereview/phonon/gstreamer/audiooutput.cpp #800068:800069
@@ -1,6 +1,7 @@
/* This file is part of the KDE project.
Copyright (C) 2007 Trolltech ASA. All rights reserved.
+ 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 @@ -129,7 +130,6 @@
if (root()) {
root()->saveState();
- GstState state = GST_STATE(root()->pipeline());
if (gst_element_set_state(root()->pipeline(), GST_STATE_READY) == \
GST_STATE_CHANGE_FAILURE) return false;
}
@@ -163,7 +163,81 @@
return success;
}
+#if (PHONON_VERSION >= PHONON_VERSION_CHECK(4, 2, 0))
+bool AudioOutput::setOutputDevice(const AudioOutputDevice &newDevice)
+{
+ qDebug() << Q_FUNC_INFO << newDevice;
+ if (!m_audioSink || !newDevice.isValid()) {
+ return false;
+ }
+ const QVariant driver = newDevice.property("driver");
+ if (!driver.isValid()) {
+ return setOutputDevice(newDevice.index());
+ }
+ if (newDevice.index() == m_device) {
+ return true;
+ }
+
+ if (root()) {
+ root()->saveState();
+ if (gst_element_set_state(root()->pipeline(), GST_STATE_READY) == \
GST_STATE_CHANGE_FAILURE) + return false;
+ }
+
+ // Save previous state
+ const GstState oldState = GST_STATE(m_audioSink);
+ const QByteArray oldDeviceValue = GstHelper::property(m_audioSink, \
"device"); +
+ const QByteArray sinkName = GstHelper::property(m_audioSink, "name");
+ if (sinkName == "alsasink" || sinkName == "alsasink2") {
+ if (driver.toByteArray() != "alsa") {
+ return false;
+ }
+ }
+
+ const QVariant deviceIdsProperty = newDevice.property("deviceIds");
+ QStringList deviceIds;
+ if (deviceIdsProperty.type() == QVariant::StringList) {
+ deviceIds = deviceIdsProperty.toStringList();
+ } else if (deviceIdsProperty.type() == QVariant::String) {
+ deviceIds += deviceIdsProperty.toString();
+ }
+ qDebug() << Q_FUNC_INFO << deviceIds;
+
+ // We test if the device can be opened by checking if it can go from \
NULL to READY state + foreach (const QString &deviceId, deviceIds) {
+ gst_element_set_state(m_audioSink, GST_STATE_NULL);
+ if (GstHelper::setProperty(m_audioSink, "device", \
deviceId.toUtf8())) { + qDebug() << Q_FUNC_INFO << \
"setProperty(device," << deviceId.toUtf8() << ") succeeded"; + \
if (gst_element_set_state(m_audioSink, oldState) == \
GST_STATE_CHANGE_SUCCESS) { + qDebug() << Q_FUNC_INFO << "go \
to old state on device" << deviceId.toUtf8() << " succeeded"; + \
m_device = newDevice.index(); + if (root()) {
+ QMetaObject::invokeMethod(root(), "setState", \
Qt::QueuedConnection, Q_ARG(State, StoppedState)); + \
root()->resumeState(); + }
+ return true;
+ } else {
+ qDebug() << Q_FUNC_INFO << "go to old state on device" << \
deviceId.toUtf8() << " failed"; + }
+ } else {
+ qDebug() << Q_FUNC_INFO << "setProperty(device," << \
deviceId.toUtf8() << ") failed"; + }
+ }
+ // Revert state
+ GstHelper::setProperty(m_audioSink, "device", oldDeviceValue);
+ gst_element_set_state(m_audioSink, oldState);
+
+ if (root()) {
+ QMetaObject::invokeMethod(root(), "setState", \
Qt::QueuedConnection, Q_ARG(State, StoppedState)); + \
root()->resumeState(); + }
+
+ return false;
}
+#endif
+
+}
} //namespace Phonon::Gstreamer
QT_END_NAMESPACE
--- trunk/kdereview/phonon/gstreamer/audiooutput.h #800068:800069
@@ -1,6 +1,7 @@
/* This file is part of the KDE project.
Copyright (C) 2007 Trolltech ASA. All rights reserved.
+ 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 @@ -22,6 +23,7 @@
#include "medianode.h"
#include <phonon/audiooutputinterface.h>
+#include <phonon/phononnamespace.h>
#include <QtCore/QFile>
@@ -45,6 +47,9 @@
int outputDevice() const;
void setVolume(qreal newVolume);
bool setOutputDevice(int newDevice);
+#if (PHONON_VERSION >= PHONON_VERSION_CHECK(4, 2, 0))
+ bool setOutputDevice(const AudioOutputDevice &newDevice);
+#endif
public:
GstElement *audioElement()
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic