Merge lp:~tiagosh/telepathy-ofono/audioflinger-speakermode into lp:telepathy-ofono

Proposed by Tiago Salem Herrmann
Status: Merged
Approved by: Gustavo Pichorim Boiko
Approved revision: 36
Merged at revision: 35
Proposed branch: lp:~tiagosh/telepathy-ofono/audioflinger-speakermode
Merge into: lp:telepathy-ofono
Diff against target: 258 lines (+131/-5)
5 files modified
CMakeLists.txt (+7/-1)
connection.cpp (+109/-1)
connection.h (+8/-1)
debian/control (+1/-0)
ofonocallchannel.cpp (+6/-2)
To merge this branch: bzr merge lp:~tiagosh/telepathy-ofono/audioflinger-speakermode
Reviewer Review Type Date Requested Status
Gustavo Pichorim Boiko (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+178873@code.launchpad.net

Commit message

- Implement support for audioflingler when compiling for armhf
- Implement speaker mode.

Description of the change

- Add support for audioflingler when compiling for armhf
- Implement speaker mode.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
36. By Tiago Salem Herrmann

enable speaker phone mode on incoming calls.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Looks good and works as expected.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2013-05-08 13:51:52 +0000
3+++ CMakeLists.txt 2013-08-08 16:24:30 +0000
4@@ -11,6 +11,12 @@
5 find_package(Qt5DBus)
6 add_definitions(-DQT_NO_KEYWORDS)
7
8+check_include_file_cxx("waudio.h" USE_AUDIOFLINGER)
9+if (USE_AUDIOFLINGER)
10+ add_definitions(-DUSE_AUDIOFLINGER)
11+ set(WAUDIO_LIBRARIES -lwaudio)
12+endif (USE_AUDIOFLINGER)
13+
14 find_package(PkgConfig REQUIRED)
15 pkg_check_modules(TP_QT5 REQUIRED TelepathyQt5)
16
17@@ -33,7 +39,7 @@
18 add_executable(telepathy-ofono main.cpp protocol.cpp connection.cpp ofonotextchannel.cpp ofonocallchannel.cpp voicemailiface.cpp speakeriface.cpp)
19 qt5_use_modules(telepathy-ofono Core DBus)
20
21-target_link_libraries(telepathy-ofono ${Qt5Core_LIBRARIES} ${Qt5DBus_LIBRARIES} -ltelepathy-qt5 ${TELEPATHY_QT5_SERVICE_LIBRARIES} ${OFONO_QT_LIBRARIES})
22+target_link_libraries(telepathy-ofono ${Qt5Core_LIBRARIES} ${Qt5DBus_LIBRARIES} ${WAUDIO_LIBRARIES} -ltelepathy-qt5 ${TELEPATHY_QT5_SERVICE_LIBRARIES} ${OFONO_QT_LIBRARIES})
23 install(TARGETS telepathy-ofono DESTINATION ${DAEMON_DIR})
24
25 configure_file(ofono.service.in org.freedesktop.Telepathy.ConnectionManager.ofono.service)
26
27=== modified file 'connection.cpp'
28--- connection.cpp 2013-06-01 01:50:34 +0000
29+++ connection.cpp 2013-08-08 16:24:30 +0000
30@@ -30,6 +30,64 @@
31 #include "phoneutils.h"
32 #include "protocol.h"
33
34+// audioflinger
35+#ifdef USE_AUDIOFLINGER
36+#include <waudio.h>
37+#endif
38+
39+static void enable_earpiece()
40+{
41+#ifdef USE_AUDIOFLINGER
42+ char parameter[20];
43+ int i;
44+ /* Set the call mode in AudioFlinger */
45+ AudioSystem_setMode(AUDIO_MODE_IN_CALL);
46+ sprintf(parameter, "routing=%d", AUDIO_DEVICE_OUT_EARPIECE);
47+ /* Try the first 3 threads, as this is not fixed and there's no easy
48+ * way to retrieve the default thread/output from Android */
49+ for (i = 1; i <= 3; i++) {
50+ if (AudioSystem_setParameters(i, parameter) >= 0)
51+ break;
52+ }
53+#endif
54+}
55+
56+static void enable_normal()
57+{
58+#ifdef USE_AUDIOFLINGER
59+ char parameter[20];
60+ int i;
61+ /* Set normal mode in AudioFlinger */
62+ AudioSystem_setMode(AUDIO_MODE_NORMAL);
63+ /* Get device back to speaker mode, as by default in_call
64+ * mode sets up device out to earpiece */
65+ sprintf(parameter, "routing=%d", AUDIO_DEVICE_OUT_SPEAKER);
66+ /* Try the first 3 threads, as this is not fixed and there's no easy
67+ * way to retrieve the default thread/output from Android */
68+ for (i = 1; i <= 3; i++) {
69+ if (AudioSystem_setParameters(i, parameter) >= 0)
70+ break;
71+ }
72+#endif
73+}
74+
75+static void enable_speaker()
76+{
77+#ifdef USE_AUDIOFLINGER
78+ char parameter[20];
79+ int i;
80+ /* Set the call mode in AudioFlinger */
81+ AudioSystem_setMode(AUDIO_MODE_IN_CALL);
82+ sprintf(parameter, "routing=%d", AUDIO_DEVICE_OUT_SPEAKER);
83+ /* Try the first 3 threads, as this is not fixed and there's no easy
84+ * way to retrieve the default thread/output from Android */
85+ for (i = 1; i <= 3; i++) {
86+ if (AudioSystem_setParameters(i, parameter) >= 0)
87+ break;
88+ }
89+#endif
90+}
91+
92 // miliseconds
93 #define OFONO_REGISTER_RETRY_TIME 5000
94
95@@ -45,7 +103,8 @@
96 mOfonoNetworkRegistration(new OfonoNetworkRegistration(OfonoModem::AutomaticSelect, "")),
97 mOfonoMessageWaiting(new OfonoMessageWaiting(OfonoModem::AutomaticSelect, "")),
98 mHandleCount(0),
99- mRegisterTimer(new QTimer(this))
100+ mRegisterTimer(new QTimer(this)),
101+ mSpeakerMode(false)
102 {
103 setSelfHandle(newHandle("<SelfHandle>"));
104
105@@ -138,6 +197,10 @@
106 QObject::connect(mOfonoMessageWaiting, SIGNAL(voicemailWaitingChanged(bool)), voicemailIface.data(), SLOT(setVoicemailIndicator(bool)));
107
108 QObject::connect(mRegisterTimer, SIGNAL(timeout()), SLOT(onTryRegister()));
109+
110+ // update audio route
111+ QObject::connect(mOfonoVoiceCallManager, SIGNAL(callAdded(QString,QVariantMap)), SLOT(updateAudioRoute()));
112+ QObject::connect(mOfonoVoiceCallManager, SIGNAL(callRemoved(QString)), SLOT(updateAudioRoute()));
113 }
114
115 oFonoConnection::~oFonoConnection() {
116@@ -537,3 +600,48 @@
117 {
118 return mOfonoMessageWaiting->voicemailWaiting();
119 }
120+
121+bool oFonoConnection::speakerMode()
122+{
123+ return mSpeakerMode;
124+}
125+
126+void oFonoConnection::setSpeakerMode(bool active)
127+{
128+ if (mSpeakerMode != active) {
129+ mSpeakerMode = active;
130+ updateAudioRoute();
131+ Q_EMIT speakerModeChanged(active);
132+ }
133+}
134+
135+void oFonoConnection::updateAudioRoute()
136+{
137+ int currentCalls = mOfonoVoiceCallManager->getCalls().size();
138+ if (currentCalls != 0) {
139+ if (currentCalls == 1) {
140+ // if we have only one call, check if it's incoming and
141+ // enable speaker mode so the ringtone is audible
142+ OfonoVoiceCall *call = new OfonoVoiceCall(mOfonoVoiceCallManager->getCalls().first());
143+ if (call) {
144+ if (call->state() == "incoming") {
145+ enable_speaker();
146+ call->deleteLater();
147+ return;
148+ }
149+ call->deleteLater();
150+ }
151+ }
152+ if(mSpeakerMode) {
153+ enable_speaker();
154+ } else {
155+ enable_earpiece();
156+ }
157+ } else {
158+ enable_normal();
159+ setSpeakerMode(false);
160+ }
161+
162+}
163+
164+
165
166=== modified file 'connection.h'
167--- connection.h 2013-06-01 01:50:34 +0000
168+++ connection.h 2013-08-08 16:24:30 +0000
169@@ -42,6 +42,7 @@
170 #include "ofonotextchannel.h"
171 #include "ofonocallchannel.h"
172 #include "voicemailiface.h"
173+#include "speakeriface.h"
174
175 class oFonoConnection;
176 class oFonoTextChannel;
177@@ -65,6 +66,8 @@
178 uint setPresence(const QString& status, const QString& statusMessage, Tp::DBusError *error);
179 void connect(Tp::DBusError *error);
180 void setOnline(bool online);
181+ void setSpeakerMode(bool active);
182+ bool speakerMode();
183 bool voicemailIndicator(Tp::DBusError *error);
184 QString voicemailNumber(Tp::DBusError *error);
185 uint voicemailCount(Tp::DBusError *error);
186@@ -86,8 +89,12 @@
187 uint targetHandle, Tp::DBusError *error);
188
189 ~oFonoConnection();
190+Q_SIGNALS:
191+ void speakerModeChanged(bool active);
192+
193 public Q_SLOTS:
194 void Q_DBUS_EXPORT onTryRegister();
195+ void updateAudioRoute();
196
197 private Q_SLOTS:
198 void onOfonoIncomingMessage(const QString &message, const QVariantMap &info);
199@@ -97,7 +104,6 @@
200 void onCallChannelClosed();
201 void onValidityChanged(bool valid);
202
203-
204 private:
205 bool isNetworkRegistered();
206 QMap<uint, QString> mHandles;
207@@ -116,6 +122,7 @@
208 Tp::SimplePresence mSelfPresence;
209 Tp::SimplePresence mRequestedSelfPresence;
210 QTimer *mRegisterTimer;
211+ bool mSpeakerMode;
212 };
213
214 #endif
215
216=== modified file 'debian/control'
217--- debian/control 2013-06-13 17:32:47 +0000
218+++ debian/control 2013-08-08 16:24:30 +0000
219@@ -6,6 +6,7 @@
220 debhelper (>= 9),
221 libofono-qt-dev (>= 1.5),
222 libtelepathy-qt5-dev (>= 0.9.3),
223+ libwaudio1-dev [armhf],
224 qt5-default (>= 5.0),
225 qtbase5-dev (>= 5.0),
226 Standards-Version: 3.9.4
227
228=== modified file 'ofonocallchannel.cpp'
229--- ofonocallchannel.cpp 2013-06-01 01:50:34 +0000
230+++ ofonocallchannel.cpp 2013-08-08 16:24:30 +0000
231@@ -59,8 +59,7 @@
232
233 void oFonoCallChannel::onTurnOnSpeaker(bool active, Tp::DBusError *error)
234 {
235- // TODO - set modem speaker on.
236- //mSpeakerIface->setSpeakerMode(active);
237+ mConnection->setSpeakerMode(active);
238 }
239
240 void oFonoCallChannel::onHangup(uint reason, const QString &detailedReason, const QString &message, Tp::DBusError *error)
241@@ -118,6 +117,9 @@
242 QObject::connect(mBaseChannel.data(), SIGNAL(closed()), this, SLOT(deleteLater()));
243 QObject::connect(mConnection->callVolume(), SIGNAL(mutedChanged(bool)), SLOT(onOfonoMuteChanged(bool)));
244 QObject::connect(this, SIGNAL(stateChanged(QString)), SLOT(onOfonoCallStateChanged(QString)));
245+ QObject::connect(mConnection, SIGNAL(speakerModeChanged(bool)), mSpeakerIface.data(), SLOT(setSpeakerMode(bool)));
246+
247+ mSpeakerIface->setSpeakerMode(mConnection->speakerMode());
248 }
249
250 void oFonoCallChannel::onOfonoMuteChanged(bool mute)
251@@ -211,5 +213,7 @@
252 } else if (state == "waiting") {
253 qDebug() << "waiting";
254 }
255+ // always update the audio route when call state changes
256+ mConnection->updateAudioRoute();
257 mPreviousState = state;
258 }

Subscribers

People subscribed via source and target branches