=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2015-07-20 19:38:54 +0000
+++ CMakeLists.txt 2016-01-15 17:47:09 +0000
@@ -40,13 +40,6 @@
pkg_check_modules(SQLITE3 REQUIRED sqlite3)
pkg_check_modules(MC_PLUGINS REQUIRED mission-control-plugins)
-pkg_check_modules(PULSEAUDIO libpulse)
-if (PULSEAUDIO_FOUND)
- add_definitions(-DUSE_PULSEAUDIO)
- set(USE_PULSEAUDIO ON)
- include_directories(${PULSEAUDIO_INCLUDE_DIRS})
-endif (PULSEAUDIO_FOUND)
-
find_program(DBUS_RUNNER dbus-test-runner)
if(NOT DAEMON_DIR)
@@ -89,29 +82,22 @@
ofonoconferencecallchannel.cpp
emergencymodeiface.cpp
voicemailiface.cpp
- audiooutputsiface.cpp
mmsdmanager.cpp
mmsdservice.cpp
mmsdmessage.cpp
pendingmessagesmanager.cpp
phoneutils.cpp
- powerdaudiomodemediator.cpp
- powerddbus.cpp
sqlitedatabase.cpp
ussdiface.cpp
${telepathyfono_RES})
-if(USE_PULSEAUDIO)
- add_executable(${TELEPATHY_OFONO} qpulseaudioengine.cpp ${TELEPATHY_OFONO_SRC})
-else(USE_PULSEAUDIO)
- add_executable(${TELEPATHY_OFONO} ${TELEPATHY_OFONO_SRC})
-endif(USE_PULSEAUDIO)
+add_executable(${TELEPATHY_OFONO} ${TELEPATHY_OFONO_SRC})
qt5_use_modules(${TELEPATHY_OFONO} Core DBus Sql)
add_dependencies(${TELEPATHY_OFONO} schema_update qrc_update)
enable_testing()
-target_link_libraries(${TELEPATHY_OFONO} ${Qt5Core_LIBRARIES} ${Qt5DBus_LIBRARIES} ${WAUDIO_LIBRARIES} -ltelepathy-qt5 ${TELEPATHY_QT5_SERVICE_LIBRARIES} ${OFONO_QT_LIBRARIES} ${PULSEAUDIO_LIBRARIES} ${SQLITE3_LIBRARIES} ${LibPhoneNumber_LIBRARIES})
+target_link_libraries(${TELEPATHY_OFONO} ${Qt5Core_LIBRARIES} ${Qt5DBus_LIBRARIES} -ltelepathy-qt5 ${TELEPATHY_QT5_SERVICE_LIBRARIES} ${OFONO_QT_LIBRARIES} ${SQLITE3_LIBRARIES} ${LibPhoneNumber_LIBRARIES})
install(TARGETS ${TELEPATHY_OFONO} DESTINATION ${DAEMON_DIR})
configure_file(ofono.service.in org.freedesktop.Telepathy.ConnectionManager.ofono.service)
=== removed file 'audiooutputsiface.cpp'
--- audiooutputsiface.cpp 2014-08-05 02:01:51 +0000
+++ audiooutputsiface.cpp 1970-01-01 00:00:00 +0000
@@ -1,167 +0,0 @@
-/**
- * Copyright (C) 2013 Canonical, Ltd.
- *
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License version 3, as published by
- * the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
- * SATISFACTORY QUALITY, 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 program. If not, see .
- *
- * Authors: Tiago Salem Herrmann
- */
-
-#include
-
-#include
-#include
-
-#include "audiooutputsiface.h"
-
-
-QDBusArgument &operator<<(QDBusArgument &argument, const AudioOutput &output)
-{
- argument.beginStructure();
- argument << output.id << output.type << output.name;
- argument.endStructure();
- return argument;
-}
-
-const QDBusArgument &operator>>(const QDBusArgument &argument, AudioOutput &output)
-{
- argument.beginStructure();
- argument >> output.id >> output.type >> output.name;
- argument.endStructure();
- return argument;
-}
-
-// Chan.I.AudioOutputs
-BaseChannelAudioOutputsInterface::Adaptee::Adaptee(BaseChannelAudioOutputsInterface *interface)
- : QObject(interface),
- mInterface(interface)
-{
- qDBusRegisterMetaType();
- qDBusRegisterMetaType();
-}
-
-struct TP_QT_NO_EXPORT BaseChannelAudioOutputsInterface::Private {
- Private(BaseChannelAudioOutputsInterface *parent)
- : adaptee(new BaseChannelAudioOutputsInterface::Adaptee(parent)) {
- }
- AudioOutputList audioOutputs;
- QString activeAudioOutput;
- SetActiveAudioOutputCallback setActiveAudioOutputCB;
- BaseChannelAudioOutputsInterface::Adaptee *adaptee;
-};
-
-BaseChannelAudioOutputsInterface::Adaptee::~Adaptee()
-{
-}
-
-void BaseChannelAudioOutputsInterface::Adaptee::setActiveAudioOutput(const QString &id, const ChannelInterfaceAudioOutputsAdaptor::SetActiveAudioOutputContextPtr &context)
-{
- if (!mInterface->mPriv->setActiveAudioOutputCB.isValid()) {
- context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"));
- return;
- }
- Tp::DBusError error;
- mInterface->mPriv->setActiveAudioOutputCB(id, &error);
- if (error.isValid()) {
- context->setFinishedWithError(error.name(), error.message());
- return;
- }
- context->setFinished();
-}
-
-BaseChannelAudioOutputsInterface::BaseChannelAudioOutputsInterface()
- : AbstractChannelInterface(TP_QT_IFACE_CHANNEL_AUDIOOUTPUTS),
- mPriv(new Private(this))
-{
-}
-
-BaseChannelAudioOutputsInterface::~BaseChannelAudioOutputsInterface()
-{
- delete mPriv;
-}
-
-QString BaseChannelAudioOutputsInterface::activeAudioOutput() const
-{
- return mPriv->activeAudioOutput;
-}
-
-AudioOutputList BaseChannelAudioOutputsInterface::audioOutputs() const
-{
- return mPriv->audioOutputs;
-}
-
-void BaseChannelAudioOutputsInterface::setSetActiveAudioOutputCallback(const SetActiveAudioOutputCallback &cb)
-{
- mPriv->setActiveAudioOutputCB = cb;
-}
-
-void BaseChannelAudioOutputsInterface::setActiveAudioOutput(const QString &id)
-{
- mPriv->activeAudioOutput = id;
- Q_EMIT mPriv->adaptee->activeAudioOutputChanged(id);
-}
-
-void BaseChannelAudioOutputsInterface::setAudioOutputs(const AudioOutputList &outputs)
-{
- mPriv->audioOutputs = outputs;
- Q_EMIT mPriv->adaptee->audioOutputsChanged(outputs);
-}
-
-QVariantMap BaseChannelAudioOutputsInterface::immutableProperties() const
-{
- QVariantMap map;
- return map;
-}
-
-void BaseChannelAudioOutputsInterface::createAdaptor()
-{
- (void) new ChannelInterfaceAudioOutputsAdaptor(dbusObject()->dbusConnection(),
- mPriv->adaptee, dbusObject());
-}
-
-
-ChannelInterfaceAudioOutputsAdaptor::ChannelInterfaceAudioOutputsAdaptor(const QDBusConnection& bus, QObject* adaptee, QObject* parent)
- : Tp::AbstractAdaptor(bus, adaptee, parent)
-{
- connect(adaptee, SIGNAL(audioOutputsChanged(AudioOutputList)), SIGNAL(AudioOutputsChanged(AudioOutputList)));
- connect(adaptee, SIGNAL(activeAudioOutputChanged(QString)), SIGNAL(ActiveAudioOutputChanged(QString)));
-}
-
-ChannelInterfaceAudioOutputsAdaptor::~ChannelInterfaceAudioOutputsAdaptor()
-{
-}
-
-void ChannelInterfaceAudioOutputsAdaptor::SetActiveAudioOutput(const QString &id, const QDBusMessage& dbusMessage)
-{
- if (!adaptee()->metaObject()->indexOfMethod("setActiveAudioOutput(QString,ChannelInterfaceAudioOutputsAdaptor::SetActiveAudioOutputContextPtr)") == -1) {
- dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")));
- return;
- }
-
- SetActiveAudioOutputContextPtr ctx = SetActiveAudioOutputContextPtr(
- new Tp::MethodInvocationContext< >(dbusConnection(), dbusMessage));
- QMetaObject::invokeMethod(adaptee(), "setActiveAudioOutput",
- Q_ARG(QString, id),
- Q_ARG(ChannelInterfaceAudioOutputsAdaptor::SetActiveAudioOutputContextPtr, ctx));
- return;
-}
-
-QString ChannelInterfaceAudioOutputsAdaptor::ActiveAudioOutput() const
-{
- return qvariant_cast< QString >(adaptee()->property("activeAudioOutput"));
-}
-
-AudioOutputList ChannelInterfaceAudioOutputsAdaptor::AudioOutputs() const
-{
- return qvariant_cast< AudioOutputList >(adaptee()->property("audioOutputs"));
-}
-
=== removed file 'audiooutputsiface.h'
--- audiooutputsiface.h 2014-08-05 02:01:51 +0000
+++ audiooutputsiface.h 1970-01-01 00:00:00 +0000
@@ -1,148 +0,0 @@
-/**
- * Copyright (C) 2013 Canonical, Ltd.
- *
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License version 3, as published by
- * the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
- * SATISFACTORY QUALITY, 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 program. If not, see .
- *
- * Authors: Tiago Salem Herrmann
- */
-
-#ifndef OFONOAUDIOOUTPUTSIFACE_H
-#define OFONOAUDIOOUTPUTSIFACE_H
-
-// telepathy-qt
-#include
-#include
-#include
-#include
-#include
-
-#include "dbustypes.h"
-
-#define TP_QT_IFACE_CHANNEL_AUDIOOUTPUTS "com.canonical.Telephony.AudioOutputs"
-
-class BaseChannelAudioOutputsInterface;
-
-typedef Tp::SharedPtr BaseChannelAudioOutputsInterfacePtr;
-
-class TP_QT_EXPORT BaseChannelAudioOutputsInterface : public Tp::AbstractChannelInterface
-{
- Q_OBJECT
- Q_DISABLE_COPY(BaseChannelAudioOutputsInterface)
-
-public:
- static BaseChannelAudioOutputsInterfacePtr create() {
- return BaseChannelAudioOutputsInterfacePtr(new BaseChannelAudioOutputsInterface());
- }
- template
- static Tp::SharedPtr create() {
- return Tp::SharedPtr(
- new BaseChannelAudioOutputsInterfaceSubclass());
- }
- QVariantMap immutableProperties() const;
- virtual ~BaseChannelAudioOutputsInterface();
- AudioOutputList audioOutputs() const;
- QString activeAudioOutput() const;
-
- typedef Tp::Callback2 SetActiveAudioOutputCallback;
- void setSetActiveAudioOutputCallback(const SetActiveAudioOutputCallback &cb);
-
-public Q_SLOTS:
- void setActiveAudioOutput(const QString &id);
- void setAudioOutputs(const AudioOutputList &outputs);
-
-protected:
- BaseChannelAudioOutputsInterface();
-
-private:
- void createAdaptor();
-
- class Adaptee;
- friend class Adaptee;
- struct Private;
- friend struct Private;
- Private *mPriv;
-};
-
-
-class TP_QT_EXPORT ChannelInterfaceAudioOutputsAdaptor : public Tp::AbstractAdaptor
-{
- Q_OBJECT
- Q_CLASSINFO("D-Bus Interface", TP_QT_IFACE_CHANNEL_AUDIOOUTPUTS)
- Q_CLASSINFO("D-Bus Introspection", ""
-" \n"
-" \n"
-" \n"
-" \n"
-" \n"
-" \n"
-" \n"
-" \n"
-" \n"
-" \n"
-" \n"
-" \n"
-" \n"
-"")
- Q_PROPERTY(AudioOutputList AudioOutputs READ AudioOutputs)
- Q_PROPERTY(QString ActiveAudioOutput READ ActiveAudioOutput)
-public:
- ChannelInterfaceAudioOutputsAdaptor(const QDBusConnection& dbusConnection, QObject* adaptee, QObject* parent);
- virtual ~ChannelInterfaceAudioOutputsAdaptor();
-
- typedef Tp::MethodInvocationContextPtr< > SetActiveAudioOutputContextPtr;
-
-public: // PROPERTIES
- QString ActiveAudioOutput() const;
- AudioOutputList AudioOutputs() const;
-
-public Q_SLOTS: // METHODS
- void SetActiveAudioOutput(const QString &id, const QDBusMessage& dbusMessage);
-
-Q_SIGNALS: // SIGNALS
- void AudioOutputsChanged(const AudioOutputList &outputs);
- void ActiveAudioOutputChanged(const QString &id);
-};
-
-
-class TP_QT_NO_EXPORT BaseChannelAudioOutputsInterface::Adaptee : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(AudioOutputList audioOutputs READ audioOutputs)
- Q_PROPERTY(QString activeAudioOutput READ activeAudioOutput)
-
-public:
- Adaptee(BaseChannelAudioOutputsInterface *interface);
- ~Adaptee();
- AudioOutputList audioOutputs() const
- {
- return mInterface->audioOutputs();
- }
-
- QString activeAudioOutput() const
- {
- return mInterface->activeAudioOutput();
- }
-
-
-private Q_SLOTS:
- void setActiveAudioOutput(const QString &id, const ChannelInterfaceAudioOutputsAdaptor::SetActiveAudioOutputContextPtr &context);
-
-Q_SIGNALS:
- void activeAudioOutputChanged(const QString &id);
- void audioOutputsChanged(const AudioOutputList &outputs);
-
-public:
- BaseChannelAudioOutputsInterface *mInterface;
-};
-
-#endif
=== modified file 'connection.cpp'
--- connection.cpp 2015-10-13 19:29:54 +0000
+++ connection.cpp 2016-01-15 17:47:09 +0000
@@ -33,49 +33,10 @@
#include "mmsdmessage.h"
#include "mmsdservice.h"
-#ifdef USE_PULSEAUDIO
-#include "qpulseaudioengine.h"
-#endif
-
#include "sqlitedatabase.h"
#include "pendingmessagesmanager.h"
#include "dbustypes.h"
-static void enable_earpiece()
-{
-#ifdef USE_PULSEAUDIO
- QPulseAudioEngine::instance()->setCallMode(CallActive, AudioModeBtOrWiredOrEarpiece);
-#endif
-}
-
-static void enable_normal()
-{
-#ifdef USE_PULSEAUDIO
- QTimer* timer = new QTimer();
- timer->setSingleShot(true);
- QObject::connect(timer, &QTimer::timeout, [=](){
- QPulseAudioEngine::instance()->setMicMute(false);
- QPulseAudioEngine::instance()->setCallMode(CallEnded, AudioModeWiredOrSpeaker);
- timer->deleteLater();
- });
- timer->start(2000);
-#endif
-}
-
-static void enable_speaker()
-{
-#ifdef USE_PULSEAUDIO
- QPulseAudioEngine::instance()->setCallMode(CallActive, AudioModeSpeaker);
-#endif
-}
-
-static void enable_ringtone()
-{
-#ifdef USE_PULSEAUDIO
- QPulseAudioEngine::instance()->setCallMode(CallRinging, AudioModeWiredOrSpeaker);
-#endif
-}
-
oFonoConnection::oFonoConnection(const QDBusConnection &dbusConnection,
const QString &cmName,
const QString &protocolName,
@@ -86,8 +47,6 @@
mMmsdManager(new MMSDManager(this)),
mConferenceCall(NULL)
{
- qRegisterMetaType();
- qRegisterMetaType();
OfonoModem::SelectionSetting setting = OfonoModem::AutomaticSelect;
mModemPath = parameters["modem-objpath"].toString();
if (!mModemPath.isEmpty()) {
@@ -238,22 +197,6 @@
QObject::connect(mMmsdManager, SIGNAL(serviceAdded(const QString&)), SLOT(onMMSDServiceAdded(const QString&)));
QObject::connect(mMmsdManager, SIGNAL(serviceRemoved(const QString&)), SLOT(onMMSDServiceRemoved(const QString&)));
- // update audio route
- QObject::connect(mOfonoVoiceCallManager, SIGNAL(callAdded(QString,QVariantMap)), SLOT(updateAudioRoute()));
- QObject::connect(mOfonoVoiceCallManager, SIGNAL(callRemoved(QString)), SLOT(updateAudioRoute()));
-
-#ifdef USE_PULSEAUDIO
- // update audio modes
- QObject::connect(QPulseAudioEngine::instance(), SIGNAL(audioModeChanged(AudioMode)), SLOT(onAudioModeChanged(AudioMode)));
- QObject::connect(QPulseAudioEngine::instance(), SIGNAL(availableAudioModesChanged(AudioModes)), SLOT(onAvailableAudioModesChanged(AudioModes)));
-
- // check if we should indeed use pulseaudio
- QByteArray pulseAudioDisabled = qgetenv("PA_DISABLED");
- mHasPulseAudio = true;
- if (!pulseAudioDisabled.isEmpty())
- mHasPulseAudio = false;
-#endif
-
QObject::connect(mOfonoSupplementaryServices, SIGNAL(notificationReceived(const QString &)), supplementaryServicesIface.data(), SLOT(NotificationReceived(const QString &)));
QObject::connect(mOfonoSupplementaryServices, SIGNAL(requestReceived(const QString &)), supplementaryServicesIface.data(), SLOT(RequestReceived(const QString &)));
@@ -1073,27 +1016,11 @@
return mOfonoMessageWaiting->voicemailWaiting();
}
-QString oFonoConnection::activeAudioOutput()
-{
- return mActiveAudioOutput;
-}
-
-AudioOutputList oFonoConnection::audioOutputs()
-{
- return mAudioOutputs;
-}
-
QStringList oFonoConnection::emergencyNumbers(Tp::DBusError *error)
{
return mOfonoVoiceCallManager->emergencyNumbers();
}
-void oFonoConnection::setActiveAudioOutput(const QString &id)
-{
- mActiveAudioOutput = id;
- Q_EMIT activeAudioOutputChanged(id);
-}
-
void oFonoConnection::USSDInitiate(const QString &command, Tp::DBusError *error)
{
mOfonoSupplementaryServices->initiate(command);
@@ -1109,113 +1036,6 @@
mOfonoSupplementaryServices->cancel();
}
-#ifdef USE_PULSEAUDIO
-void oFonoConnection::onAudioModeChanged(AudioMode mode)
-{
- qDebug("PulseAudio audio mode changed: 0x%x", mode);
-
- if (mode == AudioModeEarpiece && mActiveAudioOutput != "earpiece") {
- setActiveAudioOutput("earpiece");
- } else if (mode == AudioModeWiredHeadset && mActiveAudioOutput != "wired_headset") {
- setActiveAudioOutput("wired_headset");
- } else if (mode == AudioModeSpeaker && mActiveAudioOutput != "speaker") {
- setActiveAudioOutput("speaker");
- } else if (mode == AudioModeBluetooth && mActiveAudioOutput != "bluetooth") {
- setActiveAudioOutput("bluetooth");
- }
-}
-
-void oFonoConnection::onAvailableAudioModesChanged(AudioModes modes)
-{
- qDebug("PulseAudio available audio modes changed");
- bool defaultFound = false;
- mAudioOutputs.clear();
- Q_FOREACH(const AudioMode &mode, modes) {
- AudioOutput output;
- if (mode == AudioModeBluetooth) {
- // there can be only one bluetooth
- output.id = "bluetooth";
- output.type = "bluetooth";
- // we dont support names for now, so we set a default value
- output.name = "bluetooth";
- } else if (mode == AudioModeEarpiece || mode == AudioModeWiredHeadset) {
- if (!defaultFound) {
- defaultFound = true;
- output.id = "default";
- output.type = "default";
- output.name = "default";
- } else {
- continue;
- }
- } else if (mode == AudioModeSpeaker) {
- output.id = "speaker";
- output.type = "speaker";
- output.name = "speaker";
- }
- mAudioOutputs << output;
- }
- Q_EMIT audioOutputsChanged(mAudioOutputs);
-}
-#endif
-
-void oFonoConnection::updateAudioRoute()
-{
-#ifdef USE_PULSEAUDIO
- if (!mHasPulseAudio)
- return;
-#endif
-
- int currentCalls = mOfonoVoiceCallManager->getCalls().size();
- if (currentCalls != 0) {
- if (currentCalls == 1) {
- // if we have only one call, check if it's incoming and
- // enable speaker mode so the ringtone is audible
- OfonoVoiceCall *call = new OfonoVoiceCall(mOfonoVoiceCallManager->getCalls().first());
- if (call) {
- if (call->state() == "incoming") {
- enable_ringtone();
- call->deleteLater();
- return;
- }
- if (call->state() == "disconnected") {
- enable_normal();
- call->deleteLater();
- return;
- }
- // if only one call and dialing, default to earpiece
- if (call->state() == "dialing") {
- enable_earpiece();
- call->deleteLater();
- return;
- }
- if (call->state().isEmpty()) {
- call->deleteLater();
- return;
- }
- call->deleteLater();
- }
- }
- } else {
- enable_normal();
- Q_EMIT lastChannelClosed();
- }
-
-}
-
-// this method is only called when call channels go from incoming to active.
-// please call this method only from oFonoCallChannel instances
-void oFonoConnection::updateAudioRouteToEarpiece()
-{
-#ifdef USE_PULSEAUDIO
- if (!mHasPulseAudio)
- return;
-#endif
-
- if (mOfonoVoiceCallManager->getCalls().size() == 1) {
- enable_earpiece();
- }
-}
-
QString oFonoConnection::uniqueName() const
{
QString timestamp(QString::number(QDateTime::currentMSecsSinceEpoch()));
=== modified file 'connection.h'
--- connection.h 2015-08-10 21:06:36 +0000
+++ connection.h 2016-01-15 17:47:09 +0000
@@ -46,12 +46,8 @@
#include "mmsdmanager.h"
#include "mmsdmessage.h"
#include "dbustypes.h"
-#include "audiooutputsiface.h"
#include "ussdiface.h"
-#ifdef USE_PULSEAUDIO
-#include "qpulseaudioengine.h"
-#endif
class oFonoConnection;
class oFonoTextChannel;
@@ -76,9 +72,6 @@
uint setPresence(const QString& status, const QString& statusMessage, Tp::DBusError *error);
void connect(Tp::DBusError *error);
void setSpeakerMode(bool active);
- void setActiveAudioOutput(const QString &id);
- AudioOutputList audioOutputs();
- QString activeAudioOutput();
QStringList emergencyNumbers(Tp::DBusError *error);
bool voicemailIndicator(Tp::DBusError *error);
QString voicemailNumber(Tp::DBusError *error);
@@ -114,17 +107,11 @@
~oFonoConnection();
Q_SIGNALS:
- void activeAudioOutputChanged(const QString &id);
- void audioOutputsChanged(const AudioOutputList &outputs);
void channelMerged(const QDBusObjectPath &objPath);
void channelSplitted(const QDBusObjectPath &objPath);
void channelHangup(const QDBusObjectPath &objPath);
void lastChannelClosed();
-public Q_SLOTS:
- void updateAudioRoute();
- void updateAudioRouteToEarpiece();
-
private Q_SLOTS:
void onOfonoIncomingMessage(const QString &message, const QVariantMap &info);
void onOfonoImmediateMessage(const QString &message, const QVariantMap &info);
@@ -148,11 +135,6 @@
void updateOnlineStatus();
void onDisconnected();
-#ifdef USE_PULSEAUDIO
- void onAudioModeChanged(AudioMode mode);
- void onAvailableAudioModesChanged(AudioModes modes);
-#endif
-
private:
void updateMcc();
bool isNetworkRegistered();
@@ -160,10 +142,6 @@
void ensureTextChannel(const QString &message, const QVariantMap &info, bool flash);
QMap mHandles;
-#ifdef USE_PULSEAUDIO
- bool mHasPulseAudio;
-#endif
-
QList mTextChannels;
QMap mCallChannels;
@@ -184,8 +162,6 @@
QMap > mServiceMMSList;
oFonoConferenceCallChannel *mConferenceCall;
QString mModemPath;
- QString mActiveAudioOutput;
- AudioOutputList mAudioOutputs;
};
#endif
=== modified file 'dbustypes.h'
--- dbustypes.h 2014-08-25 15:40:47 +0000
+++ dbustypes.h 2016-01-15 17:47:09 +0000
@@ -20,12 +20,6 @@
#define DBUSTYPES
#include
-struct AudioOutput {
- QString id;
- QString type;
- QString name;
-};
-
struct MessageStruct {
QDBusObjectPath path;
QVariantMap properties;
@@ -45,11 +39,6 @@
QString filePath;
};
-Q_DECLARE_METATYPE(AudioOutput)
-
-typedef QList AudioOutputList;
-Q_DECLARE_METATYPE(AudioOutputList)
-
typedef QList IncomingAttachmentList;
typedef QList OutgoingAttachmentList;
Q_DECLARE_METATYPE(IncomingAttachmentStruct)
=== modified file 'debian/control'
--- debian/control 2015-07-14 04:18:48 +0000
+++ debian/control 2016-01-15 17:47:09 +0000
@@ -12,9 +12,7 @@
libphonenumber-dev,
libqt5sql5-sqlite,
libtelepathy-qt5-dev (>= 0.9.3),
- libpulse-dev [armhf],
libsqlite3-dev,
- pulseaudio,
qt5-default (>= 5.0),
qtbase5-dev (>= 5.0),
sqlite3,
=== modified file 'ofonocallchannel.cpp'
--- ofonocallchannel.cpp 2015-07-14 17:25:33 +0000
+++ ofonocallchannel.cpp 2016-01-15 17:47:09 +0000
@@ -17,9 +17,6 @@
*/
#include "ofonocallchannel.h"
-#ifdef USE_PULSEAUDIO
-#include "qpulseaudioengine.h"
-#endif
oFonoCallChannel::oFonoCallChannel(oFonoConnection *conn, QString phoneNumber, uint targetHandle, QString voiceObj, QObject *parent):
@@ -47,15 +44,11 @@
mMuteIface = Tp::BaseCallMuteInterface::create();
mMuteIface->setSetMuteStateCallback(Tp::memFun(this,&oFonoCallChannel::onMuteStateChanged));
- mAudioOutputsIface = BaseChannelAudioOutputsInterface::create();
- mAudioOutputsIface->setSetActiveAudioOutputCallback(Tp::memFun(this,&oFonoCallChannel::onSetActiveAudioOutput));
-
mSplittableIface = Tp::BaseChannelSplittableInterface::create();
mSplittableIface->setSplitCallback(Tp::memFun(this,&oFonoCallChannel::onSplit));
baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mHoldIface));
baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mMuteIface));
- baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mAudioOutputsIface));
baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mSplittableIface));
mBaseChannel = baseChannel;
@@ -68,13 +61,6 @@
QObject::connect(this, SIGNAL(answerComplete(bool)), this, SLOT(onAnswerComplete(bool)));
// init must be called after initialization, otherwise we will have no object path registered.
QTimer::singleShot(0, this, SLOT(init()));
-
-#ifdef USE_PULSEAUDIO
- QByteArray pulseAudioDisabled = qgetenv("PA_DISABLED");
- mHasPulseAudio = true;
- if (!pulseAudioDisabled.isEmpty())
- mHasPulseAudio = false;
-#endif
}
Tp::CallState oFonoCallChannel::callState()
@@ -87,21 +73,6 @@
mConnection->voiceCallManager()->privateChat(path());
}
-void oFonoCallChannel::onSetActiveAudioOutput(const QString &id, Tp::DBusError *error)
-{
-#ifdef USE_PULSEAUDIO
- // fallback to earpiece/headset
- AudioMode mode = AudioModeWiredOrEarpiece;
- if (id == "bluetooth") {
- mode = AudioModeBluetooth;
- } else if (id == "speaker") {
- mode = AudioModeSpeaker;
- }
- if (mHasPulseAudio)
- QPulseAudioEngine::instance()->setCallMode(CallActive, mode);
-#endif
-}
-
void oFonoCallChannel::onHangupComplete(bool status)
{
if (!status) {
@@ -180,15 +151,10 @@
QObject::connect(mBaseChannel.data(), SIGNAL(closed()), this, SLOT(deleteLater()));
QObject::connect(mConnection->callVolume(), SIGNAL(mutedChanged(bool)), SLOT(onOfonoMuteChanged(bool)));
QObject::connect(this, SIGNAL(stateChanged(QString)), SLOT(onOfonoCallStateChanged(QString)));
- QObject::connect(mConnection, SIGNAL(activeAudioOutputChanged(QString)), mAudioOutputsIface.data(), SLOT(setActiveAudioOutput(QString)));
- QObject::connect(mConnection, SIGNAL(audioOutputsChanged(AudioOutputList)), mAudioOutputsIface.data(), SLOT(setAudioOutputs(AudioOutputList)));
QObject::connect(mConnection->voiceCallManager(), SIGNAL(sendTonesComplete(bool)), SLOT(onDtmfComplete(bool)));
QObject::connect(this, SIGNAL(multipartyChanged(bool)), this, SLOT(onMultipartyChanged(bool)));
QObject::connect(this, SIGNAL(disconnectReason(const QString &)), this, SLOT(onDisconnectReason(const QString &)));
-
- mAudioOutputsIface->setAudioOutputs(mConnection->audioOutputs());
- mAudioOutputsIface->setActiveAudioOutput(mConnection->activeAudioOutput());
}
void oFonoCallChannel::onDisconnectReason(const QString &reason) {
@@ -241,16 +207,8 @@
{
if (state == Tp::LocalMuteStateMuted) {
mConnection->callVolume()->setMuted(true);
-#ifdef USE_PULSEAUDIO
- if (mHasPulseAudio)
- QPulseAudioEngine::instance()->setMicMute(true);
-#endif
} else if (state == Tp::LocalMuteStateUnmuted) {
mConnection->callVolume()->setMuted(false);
-#ifdef USE_PULSEAUDIO
- if (mHasPulseAudio)
- QPulseAudioEngine::instance()->setMicMute(false);
-#endif
}
}
@@ -348,9 +306,6 @@
if (mMultiparty) {
Q_EMIT multipartyCallActive();
}
- if (mPreviousState == "incoming") {
- mConnection->updateAudioRouteToEarpiece();
- }
if (mPreviousState == "dialing" || mPreviousState == "alerting" ||
mPreviousState == "incoming") {
mConnection->callVolume()->setMuted(false);
@@ -372,7 +327,5 @@
} else if (state == "waiting") {
qDebug() << "waiting";
}
- // always update the audio route when call state changes
- mConnection->updateAudioRoute();
mPreviousState = state;
}
=== modified file 'ofonocallchannel.h'
--- ofonocallchannel.h 2015-02-17 17:03:42 +0000
+++ ofonocallchannel.h 2016-01-15 17:47:09 +0000
@@ -29,7 +29,6 @@
#include
#include "connection.h"
-#include "audiooutputsiface.h"
class oFonoConnection;
@@ -47,7 +46,6 @@
void onHoldStateChanged(const Tp::LocalHoldState &state, const Tp::LocalHoldStateReason &reason, Tp::DBusError *error);
void onDTMFStartTone(uchar event, Tp::DBusError *error);
void onDTMFStopTone(Tp::DBusError *error);
- void onSetActiveAudioOutput(const QString &id, Tp::DBusError *error);
void onSplit(Tp::DBusError *error);
Tp::CallState callState();
@@ -74,9 +72,6 @@
private:
QString mObjPath;
QString mPreviousState;
-#ifdef USE_PULSEAUDIO
- bool mHasPulseAudio;
-#endif
bool mIncoming;
bool mRequestedHangup;
Tp::BaseChannelPtr mBaseChannel;
@@ -86,7 +81,6 @@
Tp::BaseChannelHoldInterfacePtr mHoldIface;
Tp::BaseChannelSplittableInterfacePtr mSplittableIface;
Tp::BaseCallMuteInterfacePtr mMuteIface;
- BaseChannelAudioOutputsInterfacePtr mAudioOutputsIface;
Tp::BaseChannelCallTypePtr mCallChannel;
Tp::BaseCallContentDTMFInterfacePtr mDTMFIface;
Tp::BaseCallContentPtr mCallContent;
=== modified file 'ofonoconferencecallchannel.cpp'
--- ofonoconferencecallchannel.cpp 2015-07-14 17:25:33 +0000
+++ ofonoconferencecallchannel.cpp 2016-01-15 17:47:09 +0000
@@ -17,9 +17,6 @@
*/
#include "ofonoconferencecallchannel.h"
-#ifdef USE_PULSEAUDIO
-#include "qpulseaudioengine.h"
-#endif
#include "ofonocallchannel.h"
@@ -50,9 +47,6 @@
mMuteIface = Tp::BaseCallMuteInterface::create();
mMuteIface->setSetMuteStateCallback(Tp::memFun(this,&oFonoConferenceCallChannel::onMuteStateChanged));
- mAudioOutputsIface = BaseChannelAudioOutputsInterface::create();
- mAudioOutputsIface->setSetActiveAudioOutputCallback(Tp::memFun(this,&oFonoConferenceCallChannel::onSetActiveAudioOutput));
-
mConferenceIface = Tp::BaseChannelConferenceInterface::create(mCallChannels);
mMergeableIface = Tp::BaseChannelMergeableConferenceInterface::create();
@@ -60,7 +54,6 @@
baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mHoldIface));
baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mMuteIface));
- baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mAudioOutputsIface));
baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mConferenceIface));
baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mMergeableIface));
@@ -123,20 +116,6 @@
}
}
-void oFonoConferenceCallChannel::onSetActiveAudioOutput(const QString &id, Tp::DBusError *error)
-{
-#ifdef USE_PULSEAUDIO
- // fallback to earpiece/headset
- AudioMode mode = AudioModeWiredOrEarpiece;
- if (id == "bluetooth") {
- mode = AudioModeBluetooth;
- } else if (id == "speaker") {
- mode = AudioModeSpeaker;
- }
- QPulseAudioEngine::instance()->setCallMode(CallActive, mode);
-#endif
-}
-
void oFonoConferenceCallChannel::onHangup(uint reason, const QString &detailedReason, const QString &message, Tp::DBusError *error)
{
// TODO: use the parameters sent by telepathy
@@ -171,13 +150,8 @@
QObject::connect(mBaseChannel.data(), SIGNAL(closed()), this, SLOT(deleteLater()));
QObject::connect(mConnection->callVolume(), SIGNAL(mutedChanged(bool)), SLOT(onOfonoMuteChanged(bool)));
- QObject::connect(mConnection, SIGNAL(activeAudioOutputChanged(QString)), mAudioOutputsIface.data(), SLOT(setActiveAudioOutput(QString)));
- QObject::connect(mConnection, SIGNAL(audioOutputsChanged(AudioOutputList)), mAudioOutputsIface.data(), SLOT(setAudioOutputs(AudioOutputList)));
QObject::connect(mConnection->voiceCallManager(), SIGNAL(sendTonesComplete(bool)), SLOT(onDtmfComplete(bool)));
- mAudioOutputsIface->setAudioOutputs(mConnection->audioOutputs());
- mAudioOutputsIface->setActiveAudioOutput(mConnection->activeAudioOutput());
-
QObject::connect(mConnection, SIGNAL(channelMerged(const QDBusObjectPath&)), this, SLOT(onChannelMerged(const QDBusObjectPath&)));
QObject::connect(mConnection, SIGNAL(channelSplitted(const QDBusObjectPath&)), this, SLOT(onChannelSplitted(const QDBusObjectPath&)));
QObject::connect(mConnection, SIGNAL(channelHangup(const QDBusObjectPath&)), this, SLOT(onChannelSplitted(const QDBusObjectPath&)));
@@ -225,14 +199,8 @@
{
if (state == Tp::LocalMuteStateMuted) {
mConnection->callVolume()->setMuted(true);
-#ifdef USE_PULSEAUDIO
- QPulseAudioEngine::instance()->setMicMute(true);
-#endif
} else if (state == Tp::LocalMuteStateUnmuted) {
mConnection->callVolume()->setMuted(false);
-#ifdef USE_PULSEAUDIO
- QPulseAudioEngine::instance()->setMicMute(false);
-#endif
}
}
=== modified file 'ofonoconferencecallchannel.h'
--- ofonoconferencecallchannel.h 2015-01-26 18:52:02 +0000
+++ ofonoconferencecallchannel.h 2016-01-15 17:47:09 +0000
@@ -29,7 +29,6 @@
#include
#include "connection.h"
-#include "audiooutputsiface.h"
class oFonoConnection;
@@ -45,7 +44,6 @@
void onHoldStateChanged(const Tp::LocalHoldState &state, const Tp::LocalHoldStateReason &reason, Tp::DBusError *error);
void onDTMFStartTone(uchar event, Tp::DBusError *error);
void onDTMFStopTone(Tp::DBusError *error);
- void onSetActiveAudioOutput(const QString &id, Tp::DBusError *error);
void onMerge(const QDBusObjectPath &channel, Tp::DBusError *error);
Tp::BaseChannelPtr baseChannel();
void setConferenceActive(bool active);
@@ -72,7 +70,6 @@
Tp::BaseChannelConferenceInterfacePtr mConferenceIface;
Tp::BaseChannelMergeableConferenceInterfacePtr mMergeableIface;
Tp::BaseCallMuteInterfacePtr mMuteIface;
- BaseChannelAudioOutputsInterfacePtr mAudioOutputsIface;
Tp::BaseChannelCallTypePtr mCallChannel;
Tp::BaseCallContentDTMFInterfacePtr mDTMFIface;
Tp::BaseCallContentPtr mCallContent;
=== removed file 'powerd.h'
--- powerd.h 2014-09-30 17:25:02 +0000
+++ powerd.h 1970-01-01 00:00:00 +0000
@@ -1,34 +0,0 @@
-/**
- * Copyright (C) 2014 Canonical, Ltd.
- *
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License version 3, as published by
- * the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
- * SATISFACTORY QUALITY, 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 program. If not, see .
- *
- * Authors: Andreas Pokorny
- */
-
-#ifndef POWERD_H
-#define POWERD_H
-
-class PowerD
-{
-public:
- PowerD() = default;
- virtual ~PowerD() = default;
- PowerD(PowerD const&) = delete;
- PowerD& operator=(PowerD const&) = delete;
-
- virtual void enableProximityHandling() = 0;
- virtual void disableProximityHandling() = 0;
-};
-
-#endif // POWERD_H
=== removed file 'powerdaudiomodemediator.cpp'
--- powerdaudiomodemediator.cpp 2014-12-15 19:45:19 +0000
+++ powerdaudiomodemediator.cpp 1970-01-01 00:00:00 +0000
@@ -1,63 +0,0 @@
-/**
- * Copyright (C) 2014 Canonical, Ltd.
- *
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License version 3, as published by
- * the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
- * SATISFACTORY QUALITY, 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 program. If not, see .
- *
- * Authors: Andreas Pokorny
- */
-
-#include
-#include "powerdaudiomodemediator.h"
-
-PowerDAudioModeMediator::PowerDAudioModeMediator(PowerD &powerd)
- : powerd(powerd)
-{
-}
-
-void PowerDAudioModeMediator::audioModeChanged(const QString &mode)
-{
- bool enableProximity = !(mode == "speaker" || mode == "bluetooth" || mode == "wired_headset");
-
- if (mProximityEnabled != enableProximity)
- {
- mProximityEnabled = enableProximity;
- apply();
- }
-}
-
-void PowerDAudioModeMediator::apply() const
-{
- if (mProximityEnabled) {
- powerd.enableProximityHandling();
- } else {
- // we need to power the screen on before disabling the proximity handling
- QDBusInterface unityIface("com.canonical.Unity.Screen",
- "/com/canonical/Unity/Screen",
- "com.canonical.Unity.Screen",
- QDBusConnection::systemBus());
- QList args;
- args.append("on");
- args.append(3);
- unityIface.callWithArgumentList(QDBus::NoBlock, "setScreenPowerMode", args);
- powerd.disableProximityHandling();
- }
-}
-
-void PowerDAudioModeMediator::audioOutputClosed()
-{
- if (mProximityEnabled)
- {
- mProximityEnabled = false;
- apply();
- }
-}
=== removed file 'powerdaudiomodemediator.h'
--- powerdaudiomodemediator.h 2014-09-30 17:25:02 +0000
+++ powerdaudiomodemediator.h 1970-01-01 00:00:00 +0000
@@ -1,46 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Canonical, Ltd.
-**
-** Authors:
-** Andreas Pokorny
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-****************************************************************************/
-
-#ifndef POWERDAUDIOMODEMEDIATOR_H
-#define POWERDAUDIOMODEMEDIATOR_H
-
-#include "powerd.h"
-
-#include
-#include
-#include
-
-class PowerD;
-/*!
- * \brief PowerDAudioModeMediator is responsible for configuring proximity
- * handling of powerd during different call states and used audio outputs.
- * In General that mean enabling sreen blanking on proximity events, when
- * a call is active and neither a bluetooth headset nor the speakers are used.
- */
-class PowerDAudioModeMediator
-{
-public:
- PowerDAudioModeMediator(PowerD &powerd);
- void audioModeChanged(const QString &mode);
- void audioOutputClosed();
-private:
- void apply() const;
- PowerD &powerd;
- bool mProximityEnabled{false};
-};
-
-#endif
=== removed file 'powerddbus.cpp'
--- powerddbus.cpp 2014-09-30 17:25:02 +0000
+++ powerddbus.cpp 1970-01-01 00:00:00 +0000
@@ -1,43 +0,0 @@
-/**
- * Copyright (C) 2014 Canonical, Ltd.
- *
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License version 3, as published by
- * the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
- * SATISFACTORY QUALITY, 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 program. If not, see .
- *
- * Authors: Andreas Pokorny
- */
-
-#include "powerddbus.h"
-
-#include
-#include
-#include
-
-PowerDDBus::PowerDDBus()
- : mPowerDIface{
- new QDBusInterface(
- "com.canonical.powerd",
- "/com/canonical/powerd",
- "com.canonical.powerd",
- QDBusConnection::systemBus())}
-{
-}
-
-void PowerDDBus::enableProximityHandling()
-{
- mPowerDIface->call("enableProximityHandling", "telepathy-ofono");
-}
-
-void PowerDDBus::disableProximityHandling()
-{
- mPowerDIface->call("disableProximityHandling", "telepathy-ofono");
-}
=== removed file 'powerddbus.h'
--- powerddbus.h 2014-09-30 17:25:02 +0000
+++ powerddbus.h 1970-01-01 00:00:00 +0000
@@ -1,38 +0,0 @@
-/**
- * Copyright (C) 2014 Canonical, Ltd.
- *
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License version 3, as published by
- * the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
- * SATISFACTORY QUALITY, 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 program. If not, see .
- *
- * Authors: Andreas Pokorny
- */
-
-#ifndef POWERD_DUBS_H
-#define POWERD_DBUS_H
-
-#include "powerd.h"
-
-#include
-
-class QDBusInterface;
-
-class PowerDDBus : public PowerD
-{
-public:
- PowerDDBus();
- void enableProximityHandling() override;
- void disableProximityHandling() override;
-private:
- std::unique_ptr mPowerDIface;
-};
-
-#endif
=== modified file 'protocol.cpp'
--- protocol.cpp 2015-08-18 21:36:52 +0000
+++ protocol.cpp 2016-01-15 17:47:09 +0000
@@ -24,7 +24,7 @@
#include
Protocol::Protocol(const QDBusConnection &dbusConnection, const QString &name)
- : Tp::BaseProtocol(dbusConnection, name), mAudioModeMediator(mPowerDDBus)
+ : Tp::BaseProtocol(dbusConnection, name)
{
addressingIface = Tp::BaseProtocolAddressingInterface::create();
@@ -48,13 +48,5 @@
Tp::BaseConnectionPtr Protocol::createConnection(const QVariantMap ¶meters, Tp::DBusError *error) {
Q_UNUSED(error);
Tp::BaseConnectionPtr connection_ptr = Tp::BaseConnection::create("ofono", name().toLatin1(), parameters);
- connect(
- static_cast(connection_ptr.data()), &oFonoConnection::activeAudioOutputChanged,
- Tp::memFun(&mAudioModeMediator, &PowerDAudioModeMediator::audioModeChanged)
- );
- connect(
- static_cast(connection_ptr.data()), &oFonoConnection::lastChannelClosed,
- Tp::memFun(&mAudioModeMediator, &PowerDAudioModeMediator::audioOutputClosed)
- );
return connection_ptr;
}
=== modified file 'protocol.h'
--- protocol.h 2015-08-18 21:36:52 +0000
+++ protocol.h 2016-01-15 17:47:09 +0000
@@ -24,9 +24,6 @@
#include
-#include "powerdaudiomodemediator.h"
-#include "powerddbus.h"
-
class Protocol : public Tp::BaseProtocol
{
Q_OBJECT
@@ -38,8 +35,6 @@
private:
Tp::BaseConnectionPtr createConnection(const QVariantMap ¶meters, Tp::DBusError *error);
Tp::BaseProtocolAddressingInterfacePtr addressingIface;
- PowerDDBus mPowerDDBus;
- PowerDAudioModeMediator mAudioModeMediator;
};
#endif
=== removed file 'qpulseaudioengine.cpp'
--- qpulseaudioengine.cpp 2015-11-10 07:49:07 +0000
+++ qpulseaudioengine.cpp 1970-01-01 00:00:00 +0000
@@ -1,800 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file was taken from qt5 and modified by
-** David Henningsson for usage in
-** telepathy-ofono.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-****************************************************************************/
-
-#include
-
-#include "qpulseaudioengine.h"
-#include
-#include
-
-#define PULSEAUDIO_PROFILE_HSP "headset_head_unit"
-#define PULSEAUDIO_PROFILE_A2DP "a2dp_sink"
-
-QT_BEGIN_NAMESPACE
-
-static void contextStateCallbackInit(pa_context *context, void *userdata)
-{
- Q_UNUSED(context);
- QPulseAudioEngineWorker *pulseEngine = reinterpret_cast(userdata);
- pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
-}
-
-static void contextStateCallback(pa_context *context, void *userdata)
-{
- Q_UNUSED(userdata);
- Q_UNUSED(context);
-}
-
-static void success_cb(pa_context *context, int success, void *userdata)
-{
- QPulseAudioEngineWorker *pulseEngine = reinterpret_cast(userdata);
- pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
-}
-
-/* Callbacks used when handling events from PulseAudio */
-static void plug_card_cb(pa_context *c, const pa_card_info *info, int isLast, void *userdata)
-{
- QPulseAudioEngineWorker *pulseEngine = static_cast(userdata);
- if (isLast != 0 || !pulseEngine || !info) {
- pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
- return;
- }
- pulseEngine->plugCardCallback(info);
-}
-
-static void update_card_cb(pa_context *c, const pa_card_info *info, int isLast, void *userdata)
-{
- QPulseAudioEngineWorker *pulseEngine = static_cast(userdata);
- if (isLast != 0 || !pulseEngine || !info) {
- pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
- return;
- }
- pulseEngine->updateCardCallback(info);
-}
-
-static void unplug_card_cb(pa_context *c, const pa_card_info *info, int isLast, void *userdata)
-{
- QPulseAudioEngineWorker *pulseEngine = static_cast(userdata);
- if (!pulseEngine) {
- pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
- return;
- }
-
- if (info == NULL) {
- /* That means that the card used to query card_info was removed */
- pulseEngine->unplugCardCallback();
- }
-}
-
-static void subscribeCallback(pa_context *context, pa_subscription_event_type_t t, uint32_t idx, void *userdata)
-{
- /* For card change events (slot plug/unplug and add/remove card) */
- if ((t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) == PA_SUBSCRIPTION_EVENT_CARD) {
- if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_CHANGE) {
- QMetaObject::invokeMethod((QPulseAudioEngineWorker *) userdata, "handleCardEvent",
- Qt::QueuedConnection, Q_ARG(int, PA_SUBSCRIPTION_EVENT_CHANGE), Q_ARG(unsigned int, idx));
- } else if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW) {
- QMetaObject::invokeMethod((QPulseAudioEngineWorker *) userdata, "handleCardEvent",
- Qt::QueuedConnection, Q_ARG(int, PA_SUBSCRIPTION_EVENT_NEW), Q_ARG(unsigned int, idx));
- } else if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) {
- QMetaObject::invokeMethod((QPulseAudioEngineWorker *) userdata, "handleCardEvent",
- Qt::QueuedConnection, Q_ARG(int, PA_SUBSCRIPTION_EVENT_REMOVE), Q_ARG(unsigned int, idx));
- }
- }
-}
-
-QPulseAudioEngineWorker::QPulseAudioEngineWorker(QObject *parent)
- : QObject(parent)
- , m_mainLoopApi(0)
- , m_context(0)
- , m_callstatus(CallEnded)
- , m_audiomode(AudioModeSpeaker)
- , m_micmute(false)
- , m_defaultsink("sink.primary")
- , m_defaultsource("source.primary")
- , m_voicecallcard("")
- , m_voicecallhighest("")
- , m_voicecallprofile("")
- , m_bt_hsp("")
- , m_bt_hsp_a2dp("")
-
-{
- m_mainLoop = pa_threaded_mainloop_new();
- if (m_mainLoop == 0) {
- qWarning("Unable to create pulseaudio mainloop");
- return;
- }
-
- if (pa_threaded_mainloop_start(m_mainLoop) != 0) {
- qWarning("Unable to start pulseaudio mainloop");
- pa_threaded_mainloop_free(m_mainLoop);
- m_mainLoop = 0;
- return;
- }
-
- createPulseContext();
-}
-
-bool QPulseAudioEngineWorker::createPulseContext()
-{
- bool keepGoing = true;
- bool ok = true;
-
- if (m_context)
- return true;
-
- m_mainLoopApi = pa_threaded_mainloop_get_api(m_mainLoop);
-
- pa_threaded_mainloop_lock(m_mainLoop);
-
- m_context = pa_context_new(m_mainLoopApi, QString(QLatin1String("QtmPulseContext:%1")).arg(::getpid()).toLatin1().constData());
- pa_context_set_state_callback(m_context, contextStateCallbackInit, this);
-
- if (!m_context) {
- qWarning("Unable to create new pulseaudio context");
- pa_threaded_mainloop_unlock(m_mainLoop);
- return false;
- }
-
- if (pa_context_connect(m_context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL) < 0) {
- qWarning("Unable to create a connection to the pulseaudio context");
- pa_threaded_mainloop_unlock(m_mainLoop);
- releasePulseContext();
- return false;
- }
-
- pa_threaded_mainloop_wait(m_mainLoop);
-
- while (keepGoing) {
- switch (pa_context_get_state(m_context)) {
- case PA_CONTEXT_CONNECTING:
- case PA_CONTEXT_AUTHORIZING:
- case PA_CONTEXT_SETTING_NAME:
- break;
-
- case PA_CONTEXT_READY:
- qDebug("Pulseaudio connection established.");
- keepGoing = false;
- break;
-
- case PA_CONTEXT_TERMINATED:
- qCritical("Pulseaudio context terminated.");
- keepGoing = false;
- ok = false;
- break;
-
- case PA_CONTEXT_FAILED:
- default:
- qCritical() << QString("Pulseaudio connection failure: %1").arg(pa_strerror(pa_context_errno(m_context)));
- keepGoing = false;
- ok = false;
- }
-
- if (keepGoing) {
- pa_threaded_mainloop_wait(m_mainLoop);
- }
- }
-
- if (ok) {
- pa_context_set_state_callback(m_context, contextStateCallback, this);
- pa_context_set_subscribe_callback(m_context, subscribeCallback, this);
- pa_context_subscribe(m_context, PA_SUBSCRIPTION_MASK_CARD, NULL, this);
- } else {
- if (m_context) {
- pa_context_unref(m_context);
- m_context = 0;
- }
- }
-
- pa_threaded_mainloop_unlock(m_mainLoop);
- return true;
-}
-
-
-void QPulseAudioEngineWorker::releasePulseContext()
-{
- if (m_context) {
- pa_threaded_mainloop_lock(m_mainLoop);
- pa_context_disconnect(m_context);
- pa_context_unref(m_context);
- pa_threaded_mainloop_unlock(m_mainLoop);
- m_context = 0;
- }
-
-}
-
-QPulseAudioEngineWorker::~QPulseAudioEngineWorker()
-{
- releasePulseContext();
-
- if (m_mainLoop) {
- pa_threaded_mainloop_stop(m_mainLoop);
- pa_threaded_mainloop_free(m_mainLoop);
- m_mainLoop = 0;
- }
-}
-
-void QPulseAudioEngineWorker::cardInfoCallback(const pa_card_info *info)
-{
- pa_card_profile_info2 *voice_call = NULL, *highest = NULL;
- pa_card_profile_info2 *hsp = NULL, *a2dp = NULL;
-
- /* For now we only support one card with the voicecall feature */
- for (int i = 0; i < info->n_profiles; i++) {
- if (!highest || info->profiles2[i]->priority > highest->priority)
- highest = info->profiles2[i];
- if (!strcmp(info->profiles2[i]->name, "voicecall"))
- voice_call = info->profiles2[i];
- else if (!strcmp(info->profiles2[i]->name, PULSEAUDIO_PROFILE_HSP) &&
- info->profiles2[i]->available != 0)
- hsp = info->profiles2[i];
- else if (!strcmp(info->profiles2[i]->name, PULSEAUDIO_PROFILE_A2DP) &&
- info->profiles2[i]->available != 0)
- a2dp = info->profiles2[i];
- }
-
- /* Record the card that supports voicecall (default one to be used) */
- if (voice_call) {
- qDebug("Found card that supports voicecall: '%s'", info->name);
- m_voicecallcard = info->name;
- m_voicecallhighest = highest->name;
- m_voicecallprofile = voice_call->name;
- }
-
- /* Handle the use cases needed for bluetooth */
- if (hsp && a2dp) {
- qDebug("Found card that supports hsp and a2dp: '%s'", info->name);
- m_bt_hsp_a2dp = info->name;
- } else if (hsp && (a2dp == NULL)) {
- /* This card only provides the hsp profile */
- qDebug("Found card that supports only hsp: '%s'", info->name);
- m_bt_hsp = info->name;
- }
-}
-
-void QPulseAudioEngineWorker::sinkInfoCallback(const pa_sink_info *info)
-{
- pa_sink_port_info *earpiece = NULL, *speaker = NULL;
- pa_sink_port_info *wired_headset = NULL, *wired_headphone = NULL;
- pa_sink_port_info *preferred = NULL;
- pa_sink_port_info *bluetooth_sco = NULL;
- pa_sink_port_info *speaker_and_wired_headphone = NULL;
- AudioMode audiomodetoset;
- AudioModes modes;
-
- for (int i = 0; i < info->n_ports; i++) {
- if (!strcmp(info->ports[i]->name, "output-earpiece"))
- earpiece = info->ports[i];
- else if (!strcmp(info->ports[i]->name, "output-wired_headset") &&
- (info->ports[i]->available != PA_PORT_AVAILABLE_NO))
- wired_headset = info->ports[i];
- else if (!strcmp(info->ports[i]->name, "output-wired_headphone") &&
- (info->ports[i]->available != PA_PORT_AVAILABLE_NO))
- wired_headphone = info->ports[i];
- else if (!strcmp(info->ports[i]->name, "output-speaker"))
- speaker = info->ports[i];
- else if (!strcmp(info->ports[i]->name, "output-bluetooth_sco"))
- bluetooth_sco = info->ports[i];
- else if (!strcmp(info->ports[i]->name, "output-speaker+wired_headphone"))
- speaker_and_wired_headphone = info->ports[i];
- }
-
- if (!earpiece || !speaker)
- return; /* Not the right sink */
-
- /* Refresh list of available audio modes */
- modes.append(AudioModeEarpiece);
- modes.append(AudioModeSpeaker);
- if (wired_headset || wired_headphone)
- modes.append(AudioModeWiredHeadset);
- if (bluetooth_sco && ((m_bt_hsp != "") || (m_bt_hsp_a2dp != "")))
- modes.append(AudioModeBluetooth);
-
- /* Check if the requested mode is available (earpiece*/
- if (((m_audiomode == AudioModeWiredHeadset) && !modes.contains(AudioModeWiredHeadset)) ||
- ((m_audiomode == AudioModeBluetooth) && !modes.contains(AudioModeBluetooth)))
- return;
-
- /* Now to decide which output to be used, depending on the active mode */
- if (m_audiomode & AudioModeEarpiece) {
- preferred = earpiece;
- audiomodetoset = AudioModeEarpiece;
- }
- if (m_audiomode & AudioModeSpeaker) {
- preferred = speaker;
- audiomodetoset = AudioModeSpeaker;
- }
- if ((m_audiomode & AudioModeWiredHeadset) && (modes.contains(AudioModeWiredHeadset))) {
- preferred = wired_headset ? wired_headset : wired_headphone;
- audiomodetoset = AudioModeWiredHeadset;
- }
- if (m_callstatus == CallRinging && speaker_and_wired_headphone) {
- preferred = speaker_and_wired_headphone;
- }
- if ((m_audiomode & AudioModeBluetooth) && (modes.contains(AudioModeBluetooth))) {
- preferred = bluetooth_sco;
- audiomodetoset = AudioModeBluetooth;
- }
-
- m_audiomode = audiomodetoset;
-
- m_nametoset = info->name;
- if (info->active_port != preferred)
- m_valuetoset = preferred->name;
-
- if (modes != m_availableAudioModes)
- m_availableAudioModes = modes;
-}
-
-void QPulseAudioEngineWorker::sourceInfoCallback(const pa_source_info *info)
-{
- pa_source_port_info *builtin_mic = NULL, *preferred = NULL;
- pa_source_port_info *wired_headset = NULL, *bluetooth_sco = NULL;
-
- if (info->monitor_of_sink != PA_INVALID_INDEX)
- return; /* Not the right source */
-
- for (int i = 0; i < info->n_ports; i++) {
- if (!strcmp(info->ports[i]->name, "input-builtin_mic"))
- builtin_mic = info->ports[i];
- else if (!strcmp(info->ports[i]->name, "input-wired_headset") &&
- (info->ports[i]->available != PA_PORT_AVAILABLE_NO))
- wired_headset = info->ports[i];
- else if (!strcmp(info->ports[i]->name, "input-bluetooth_sco_headset"))
- bluetooth_sco = info->ports[i];
- }
-
- if (!builtin_mic)
- return; /* Not the right source */
-
- /* Now to decide which output to be used, depending on the active mode */
- if ((m_audiomode & AudioModeEarpiece) || (m_audiomode & AudioModeSpeaker))
- preferred = builtin_mic;
- if ((m_audiomode & AudioModeWiredHeadset) && (m_availableAudioModes.contains(AudioModeWiredHeadset)))
- preferred = wired_headset ? wired_headset : builtin_mic;
- if ((m_audiomode & AudioModeBluetooth) && (m_availableAudioModes.contains(AudioModeBluetooth)))
- preferred = bluetooth_sco;
-
- m_nametoset = info->name;
- if (info->active_port != preferred)
- m_valuetoset = preferred->name;
-}
-
-void QPulseAudioEngineWorker::serverInfoCallback(const pa_server_info *info)
-{
- /* Saving default sink/source to restore after call hangup */
- m_defaultsink = info->default_sink_name;
- m_defaultsource = info->default_source_name;
-
- /* In the case of a server callback we need to signal the mainloop */
- pa_threaded_mainloop_signal(mainloop(), 0);
-}
-
-static void cardinfo_cb(pa_context *context, const pa_card_info *info, int isLast, void *userdata)
-{
- QPulseAudioEngineWorker *pulseEngine = static_cast(userdata);
- if (isLast != 0 || !pulseEngine || !info) {
- pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
- return;
- }
- pulseEngine->cardInfoCallback(info);
-}
-
-static void sinkinfo_cb(pa_context *context, const pa_sink_info *info, int isLast, void *userdata)
-{
- QPulseAudioEngineWorker *pulseEngine = static_cast(userdata);
- if (isLast != 0 || !pulseEngine || !info) {
- pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
- return;
- }
- pulseEngine->sinkInfoCallback(info);
-}
-
-static void sourceinfo_cb(pa_context *context, const pa_source_info *info, int isLast, void *userdata)
-{
- QPulseAudioEngineWorker *pulseEngine = static_cast(userdata);
- if (isLast != 0 || !pulseEngine || !info) {
- pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
- return;
- }
- pulseEngine->sourceInfoCallback(info);
-}
-
-static void serverinfo_cb(pa_context *context, const pa_server_info *info, void *userdata)
-{
- QPulseAudioEngineWorker *pulseEngine = static_cast(userdata);
- if (!pulseEngine || !info) {
- pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
- return;
- }
- pulseEngine->serverInfoCallback(info);
-}
-
-bool QPulseAudioEngineWorker::handleOperation(pa_operation *operation, const char *func_name)
-{
- if (!operation) {
- qCritical("'%s' failed (lost PulseAudio connection?)", func_name);
- /* Free resources so it can retry a new connection during next operation */
- pa_threaded_mainloop_unlock(m_mainLoop);
- releasePulseContext();
- return false;
- }
-
- while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING)
- pa_threaded_mainloop_wait(m_mainLoop);
- pa_operation_unref(operation);
- return true;
-}
-
-int QPulseAudioEngineWorker::setupVoiceCall()
-{
- pa_operation *o;
-
- qDebug("Setting up pulseaudio for voice call");
-
- pa_threaded_mainloop_lock(m_mainLoop);
-
- /* Get and set the default sink/source to be restored later */
- o = pa_context_get_server_info(m_context, serverinfo_cb, this);
- if (!handleOperation(o, "pa_context_get_server_info"))
- return -1;
-
- qDebug("Recorded default sink: %s default source: %s",
- m_defaultsink.c_str(), m_defaultsource.c_str());
-
- /* Walk through the list of devices, find the voice call capable card and
- * identify if we have bluetooth capable devices (hsp and a2dp) */
- m_voicecallcard = m_voicecallhighest = m_voicecallprofile = "";
- m_bt_hsp = m_bt_hsp_a2dp = "";
- o = pa_context_get_card_info_list(m_context, cardinfo_cb, this);
- if (!handleOperation(o, "pa_context_get_card_info_list"))
- return -1;
- /* In case we have only one bt device that provides hsp and a2dp, we need
- * to make sure we switch the default profile for that card (to hsp) */
- if ((m_bt_hsp_a2dp != "") && (m_bt_hsp == "")) {
- qDebug("Setting PulseAudio card '%s' profile '%s'",
- m_bt_hsp_a2dp.c_str(), PULSEAUDIO_PROFILE_HSP);
- o = pa_context_set_card_profile_by_name(m_context,
- m_bt_hsp_a2dp.c_str(), PULSEAUDIO_PROFILE_HSP, success_cb, this);
- if (!handleOperation(o, "pa_context_set_card_profile_by_name"))
- return -1;
- }
-
- pa_threaded_mainloop_unlock(m_mainLoop);
-
- return 0;
-}
-
-void QPulseAudioEngineWorker::restoreVoiceCall()
-{
- pa_operation *o;
-
- qDebug("Restoring pulseaudio previous state");
-
- /* Then restore previous settings */
- pa_threaded_mainloop_lock(m_mainLoop);
-
- /* See if we need to restore any HSP+AD2P device state */
- if ((m_bt_hsp_a2dp != "") && (m_bt_hsp == "")) {
- qDebug("Restoring PulseAudio card '%s' to profile '%s'",
- m_bt_hsp_a2dp.c_str(), PULSEAUDIO_PROFILE_A2DP);
- o = pa_context_set_card_profile_by_name(m_context,
- m_bt_hsp_a2dp.c_str(), PULSEAUDIO_PROFILE_A2DP, success_cb, this);
- if (!handleOperation(o, "pa_context_set_card_profile_by_name"))
- return;
- }
-
- /* Restore default sink/source */
- if (m_defaultsink != "") {
- qDebug("Restoring PulseAudio default sink to '%s'", m_defaultsink.c_str());
- o = pa_context_set_default_sink(m_context, m_defaultsink.c_str(), success_cb, this);
- if (!handleOperation(o, "pa_context_set_default_sink"))
- return;
- }
- if (m_defaultsource != "") {
- qDebug("Restoring PulseAudio default source to '%s'", m_defaultsource.c_str());
- o = pa_context_set_default_source(m_context, m_defaultsource.c_str(), success_cb, this);
- if (!handleOperation(o, "pa_context_set_default_source"))
- return;
- }
-
- pa_threaded_mainloop_unlock(m_mainLoop);
-}
-
-void QPulseAudioEngineWorker::setCallMode(CallStatus callstatus, AudioMode audiomode)
-{
- if (!createPulseContext()) {
- return;
- }
- CallStatus p_callstatus = m_callstatus;
- AudioMode p_audiomode = m_audiomode;
- AudioModes p_availableAudioModes = m_availableAudioModes;
- pa_operation *o;
-
- /* Check if we need to save the current pulseaudio state (e.g. when starting a call) */
- if ((callstatus != CallEnded) && (p_callstatus == CallEnded)) {
- if (setupVoiceCall() < 0) {
- qCritical("Failed to setup PulseAudio for Voice Call");
- return;
- }
- }
-
- /* If we have an active call, update internal state (used later when updating sink/source ports) */
- m_callstatus = callstatus;
- m_audiomode = audiomode;
-
- pa_threaded_mainloop_lock(m_mainLoop);
-
- /* Switch the virtual card mode when call is active and not active
- * This needs to be done before sink/source gets updated, because after changing mode
- * it will automatically move to input/output-parking */
- if ((m_callstatus == CallActive) && (p_callstatus != CallActive) &&
- (m_voicecallcard != "") && (m_voicecallprofile != "")) {
- qDebug("Setting PulseAudio card '%s' profile '%s'",
- m_voicecallcard.c_str(), m_voicecallprofile.c_str());
- o = pa_context_set_card_profile_by_name(m_context,
- m_voicecallcard.c_str(), m_voicecallprofile.c_str(), success_cb, this);
- if (!handleOperation(o, "pa_context_set_card_profile_by_name"))
- return;
- } else if ((m_callstatus == CallEnded) && (m_voicecallcard != "") && (m_voicecallhighest != "")) {
- /* If using droid, make sure to restore to the profile that has the highest score */
- qDebug("Restoring PulseAudio card '%s' to profile '%s'",
- m_voicecallcard.c_str(), m_voicecallhighest.c_str());
- o = pa_context_set_card_profile_by_name(m_context,
- m_voicecallcard.c_str(), m_voicecallhighest.c_str(), success_cb, this);
- if (!handleOperation(o, "pa_context_set_card_profile_by_name"))
- return;
- }
-
- /* Find highest compatible sink/source elements from the voicecall
- compatible card (on touch this means the pulse droid element) */
- m_nametoset = m_valuetoset = "";
- o = pa_context_get_sink_info_list(m_context, sinkinfo_cb, this);
- if (!handleOperation(o, "pa_context_get_sink_info_list"))
- return;
- if ((m_nametoset != "") && (m_nametoset != m_defaultsink)) {
- qDebug("Setting PulseAudio default sink to '%s'", m_nametoset.c_str());
- o = pa_context_set_default_sink(m_context, m_nametoset.c_str(), success_cb, this);
- if (!handleOperation(o, "pa_context_set_default_sink"))
- return;
- }
- if (m_valuetoset != "") {
- qDebug("Setting PulseAudio sink '%s' port '%s'",
- m_nametoset.c_str(), m_valuetoset.c_str());
- o = pa_context_set_sink_port_by_name(m_context, m_nametoset.c_str(),
- m_valuetoset.c_str(), success_cb, this);
- if (!handleOperation(o, "pa_context_set_sink_port_by_name"))
- return;
- }
-
- /* Same for source */
- m_nametoset = m_valuetoset = "";
- o = pa_context_get_source_info_list(m_context, sourceinfo_cb, this);
- if (!handleOperation(o, "pa_context_get_source_info_list"))
- return;
- if ((m_nametoset != "") && (m_nametoset != m_defaultsource)) {
- qDebug("Setting PulseAudio default source to '%s'", m_nametoset.c_str());
- o = pa_context_set_default_source(m_context, m_nametoset.c_str(), success_cb, this);
- if (!handleOperation(o, "pa_context_set_default_source"))
- return;
- }
- if (m_valuetoset != "") {
- qDebug("Setting PulseAudio source '%s' port '%s'",
- m_nametoset.c_str(), m_valuetoset.c_str());
- o = pa_context_set_source_port_by_name(m_context, m_nametoset.c_str(),
- m_valuetoset.c_str(), success_cb, this);
- if (!handleOperation(o, "pa_context_set_source_port_by_name"))
- return;
- }
-
- pa_threaded_mainloop_unlock(m_mainLoop);
-
- /* Notify if the list of audio modes changed */
- if (p_availableAudioModes != m_availableAudioModes)
- Q_EMIT availableAudioModesChanged(m_availableAudioModes);
-
- /* Notify if call mode changed */
- if (p_audiomode != m_audiomode) {
- Q_EMIT audioModeChanged(m_audiomode);
- }
-
- /* If no more active voicecall, restore previous saved pulseaudio state */
- if (callstatus == CallEnded) {
- restoreVoiceCall();
- }
-
- /* In case the app had set mute when the call wasn't active, make sure we reflect it here */
- if (m_callstatus != CallEnded)
- setMicMute(m_micmute);
-}
-
-void QPulseAudioEngineWorker::setMicMute(bool muted)
-{
- if (!createPulseContext()) {
- return;
- }
-
- m_micmute = muted;
-
- if (m_callstatus == CallEnded)
- return;
-
- pa_threaded_mainloop_lock(m_mainLoop);
-
- m_nametoset = "";
- pa_operation *o = pa_context_get_source_info_list(m_context, sourceinfo_cb, this);
- if (!handleOperation(o, "pa_context_get_source_info_list"))
- return;
-
- if (m_nametoset != "") {
- int m = m_micmute ? 1 : 0;
- qDebug("Setting PulseAudio source '%s' muted '%d'", m_nametoset.c_str(), m);
- o = pa_context_set_source_mute_by_name(m_context,
- m_nametoset.c_str(), m, success_cb, this);
- if (!handleOperation(o, "pa_context_set_source_mute_by_name"))
- return;
- }
-
- pa_threaded_mainloop_unlock(m_mainLoop);
-}
-
-void QPulseAudioEngineWorker::plugCardCallback(const pa_card_info *info)
-{
- qDebug("Notified about card (%s) add event from PulseAudio", info->name);
-
- /* We only care about BT (HSP) devices, and if one is not already available */
- if ((m_callstatus != CallEnded) && ((m_bt_hsp == "") || (m_bt_hsp_a2dp == ""))) {
- /* Check if it's indeed a BT device (with at least one hsp profile) */
- pa_card_profile_info *hsp = NULL;
- for (int i = 0; i < info->n_profiles; i++) {
- if (!strcmp(info->profiles[i].name, PULSEAUDIO_PROFILE_HSP))
- hsp = &info->profiles[i];
- }
- if (hsp)
- m_handleevent = true;
- }
-}
-
-void QPulseAudioEngineWorker::updateCardCallback(const pa_card_info *info)
-{
- qDebug("Notified about card (%s) changes event from PulseAudio", info->name);
-
- /* We only care if the card event for the voicecall capable card */
- if ((m_callstatus == CallActive) && (!strcmp(info->name, m_voicecallcard.c_str()))) {
- if (m_audiomode == AudioModeWiredHeadset) {
- /* If previous mode is wired, it means it got unplugged */
- m_handleevent = true;
- m_audiomodetoset = AudioModeBtOrWiredOrEarpiece;
- } else if ((m_audiomode == AudioModeEarpiece) || ((m_audiomode == AudioModeSpeaker))) {
- /* Now only trigger the event in case wired headset/headphone is now available */
- pa_card_port_info *port_info = NULL;
- for (int i = 0; i < info->n_ports; i++) {
- if (info->ports[i] && (info->ports[i]->available == PA_PORT_AVAILABLE_YES) && (
- !strcmp(info->ports[i]->name, "output-wired_headset") ||
- !strcmp(info->ports[i]->name, "output-wired_headphone"))) {
- m_handleevent = true;
- m_audiomodetoset = AudioModeWiredOrEarpiece;
- }
- }
- } else if (m_audiomode == AudioModeBluetooth) {
- /* Handle the event so we can update the audiomodes */
- m_handleevent = true;
- m_audiomodetoset = AudioModeBluetooth;
- }
- }
-}
-
-void QPulseAudioEngineWorker::unplugCardCallback()
-{
- if (m_callstatus != CallEnded) {
- m_handleevent = true;
- }
-}
-
-void QPulseAudioEngineWorker::handleCardEvent(const int evt, const unsigned int idx)
-{
- pa_operation *o = NULL;
-
- /* Internal state var used to know if we need to update our internal state */
- m_handleevent = false;
-
- if (evt == PA_SUBSCRIPTION_EVENT_NEW) {
- o = pa_context_get_card_info_by_index(m_context, idx, plug_card_cb, this);
- if (!handleOperation(o, "pa_context_get_card_info_by_index"))
- return;
- if (m_handleevent) {
- qDebug("Adding new BT-HSP capable device");
- /* In case A2DP is available, switch to HSP */
- if (setupVoiceCall() < 0)
- return;
- /* Enable the HSP output port */
- setCallMode(m_callstatus, AudioModeBluetooth);
- }
- } else if (evt == PA_SUBSCRIPTION_EVENT_CHANGE) {
- o = pa_context_get_card_info_by_index(m_context, idx, update_card_cb, this);
- if (!handleOperation(o, "pa_context_get_card_info_by_index"))
- return;
- if (m_handleevent) {
- /* In this case it means the handset state changed */
- qDebug("Notifying card changes for the voicecall capable card");
- setCallMode(m_callstatus, m_audiomodetoset);
- }
- } else if (evt == PA_SUBSCRIPTION_EVENT_REMOVE) {
- /* Check if the main HSP card was removed */
- if (m_bt_hsp != "") {
- o = pa_context_get_card_info_by_name(m_context, m_bt_hsp.c_str(), unplug_card_cb, this);
- if (!handleOperation(o, "pa_context_get_sink_info_by_name"))
- return;
- }
- if (m_bt_hsp_a2dp != "") {
- o = pa_context_get_card_info_by_name(m_context, m_bt_hsp_a2dp.c_str(), unplug_card_cb, this);
- if (!handleOperation(o, "pa_context_get_sink_info_by_name"))
- return;
- }
- if (m_handleevent) {
- qDebug("Notifying about BT-HSP card removal");
- /* Needed in order to save the default sink/source */
- if (setupVoiceCall() < 0)
- return;
- /* Enable the default handset output port */
- setCallMode(m_callstatus, AudioModeWiredOrEarpiece);
- }
- }
-}
-
-Q_GLOBAL_STATIC(QPulseAudioEngine, pulseEngine);
-
-QPulseAudioEngine::QPulseAudioEngine(QObject *parent) :
- QObject(parent)
-{
- qRegisterMetaType();
- qRegisterMetaType();
- qRegisterMetaType();
- mWorker = new QPulseAudioEngineWorker();
- QObject::connect(mWorker, SIGNAL(audioModeChanged(const AudioMode)), this, SIGNAL(audioModeChanged(const AudioMode)), Qt::QueuedConnection);
- QObject::connect(mWorker, SIGNAL(availableAudioModesChanged(const AudioModes)), this, SIGNAL(availableAudioModesChanged(const AudioModes)), Qt::QueuedConnection);
- mWorker->createPulseContext();
- mWorker->moveToThread(&mThread);
- mThread.start();
-}
-
-QPulseAudioEngine::~QPulseAudioEngine()
-{
- mThread.quit();
- mThread.wait();
-}
-
-QPulseAudioEngine *QPulseAudioEngine::instance()
-{
- QPulseAudioEngine *engine = pulseEngine();
- return engine;
-}
-
-void QPulseAudioEngine::setCallMode(CallStatus callstatus, AudioMode audiomode)
-{
- QMetaObject::invokeMethod(mWorker, "setCallMode", Qt::QueuedConnection, Q_ARG(CallStatus, callstatus), Q_ARG(AudioMode, audiomode));
-}
-
-void QPulseAudioEngine::setMicMute(bool muted)
-{
- QMetaObject::invokeMethod(mWorker, "setMicMute", Qt::QueuedConnection, Q_ARG(bool, muted));
-}
-
-QT_END_NAMESPACE
-
=== removed file 'qpulseaudioengine.h'
--- qpulseaudioengine.h 2015-07-28 18:10:10 +0000
+++ qpulseaudioengine.h 1970-01-01 00:00:00 +0000
@@ -1,124 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file was taken from qt5 and modified by
-** David Henningsson for usage in
-** telepathy-ofono.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-****************************************************************************/
-
-#ifndef QPULSEAUDIOENGINE_H
-#define QPULSEAUDIOENGINE_H
-
-#include
-#include
-#include
-#include
-
-enum AudioMode {
- AudioModeEarpiece = 0x0001,
- AudioModeWiredHeadset = 0x0002,
- AudioModeSpeaker = 0x0004,
- AudioModeBluetooth = 0x0008,
- AudioModeBtOrWiredOrEarpiece = AudioModeBluetooth | AudioModeWiredHeadset | AudioModeEarpiece,
- AudioModeWiredOrEarpiece = AudioModeWiredHeadset | AudioModeEarpiece,
- AudioModeWiredOrSpeaker = AudioModeWiredHeadset | AudioModeSpeaker
-};
-
-Q_DECLARE_METATYPE(AudioMode)
-
-typedef QList AudioModes;
-Q_DECLARE_METATYPE(AudioModes)
-
-enum CallStatus {
- CallRinging,
- CallActive,
- CallEnded
-};
-
-Q_DECLARE_METATYPE(CallStatus)
-
-QT_BEGIN_NAMESPACE
-
-class QPulseAudioEngineWorker : public QObject
-{
- Q_OBJECT
-
-public:
- QPulseAudioEngineWorker(QObject *parent = 0);
- ~QPulseAudioEngineWorker();
-
- pa_threaded_mainloop *mainloop() { return m_mainLoop; }
- pa_context *context() { return m_context; }
- bool createPulseContext(void);
- int setupVoiceCall(void);
- void restoreVoiceCall(void);
- /* Callbacks to be used internally */
- void cardInfoCallback(const pa_card_info *card);
- void sinkInfoCallback(const pa_sink_info *sink);
- void sourceInfoCallback(const pa_source_info *source);
- void serverInfoCallback(const pa_server_info *server);
- void plugCardCallback(const pa_card_info *card);
- void updateCardCallback(const pa_card_info *card);
- void unplugCardCallback();
-
-Q_SIGNALS:
- void audioModeChanged(const AudioMode mode);
- void availableAudioModesChanged(const AudioModes modes);
-
-public Q_SLOTS:
- void handleCardEvent(const int evt, const unsigned int idx);
- void setCallMode(CallStatus callstatus, AudioMode audiomode);
- void setMicMute(bool muted); /* True if muted, false if unmuted */
-
-private:
- pa_mainloop_api *m_mainLoopApi;
- pa_threaded_mainloop *m_mainLoop;
- pa_context *m_context;
-
- AudioModes m_availableAudioModes;
- CallStatus m_callstatus;
- AudioMode m_audiomode;
- AudioMode m_audiomodetoset;
- bool m_micmute, m_handleevent;
- std::string m_nametoset, m_valuetoset;
- std::string m_defaultsink, m_defaultsource;
- std::string m_bt_hsp, m_bt_hsp_a2dp;
- std::string m_voicecallcard, m_voicecallhighest, m_voicecallprofile;
-
- bool handleOperation(pa_operation *operation, const char *func_name);
- void releasePulseContext(void);
-};
-
-class QPulseAudioEngine : public QObject
-{
- Q_OBJECT
-public:
- explicit QPulseAudioEngine(QObject *parent = 0);
- ~QPulseAudioEngine();
- static QPulseAudioEngine *instance();
-
- void setCallMode(CallStatus callstatus, AudioMode audiomode);
- void setMicMute(bool muted); /* True if muted, false if unmuted */
-
-Q_SIGNALS:
- void audioModeChanged(const AudioMode mode);
- void availableAudioModesChanged(const AudioModes modes);
-private:
- QPulseAudioEngineWorker *mWorker;
- QThread mThread;
-};
-
-QT_END_NAMESPACE
-
-#endif