Merge lp:~diwic/telepathy-ofono/monitor-pulseaudio-changes into lp:telepathy-ofono

Proposed by David Henningsson
Status: Merged
Approved by: Tiago Salem Herrmann
Approved revision: 46
Merged at revision: 45
Proposed branch: lp:~diwic/telepathy-ofono/monitor-pulseaudio-changes
Merge into: lp:telepathy-ofono
Diff against target: 99 lines (+31/-4)
2 files modified
qpulseaudioengine.cpp (+28/-3)
qpulseaudioengine.h (+3/-1)
To merge this branch: bzr merge lp:~diwic/telepathy-ofono/monitor-pulseaudio-changes
Reviewer Review Type Date Requested Status
Tiago Salem Herrmann (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+189213@code.launchpad.net

Commit message

Ensure speakermode status is correct even after plug/unplug of headphones

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

looks good now. Thanks for the patch.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'qpulseaudioengine.cpp'
2--- qpulseaudioengine.cpp 2013-08-22 07:22:28 +0000
3+++ qpulseaudioengine.cpp 2013-10-04 06:14:25 +0000
4@@ -47,12 +47,26 @@
5 #endif
6 }
7
8+static void subscribeCallback(pa_context *context, pa_subscription_event_type_t t, uint32_t idx, void *userdata)
9+{
10+ /* We're interested in plug/unplug stuff only, i e, card changes */
11+ if ((t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) != PA_SUBSCRIPTION_EVENT_CARD)
12+ return;
13+ if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) != PA_SUBSCRIPTION_EVENT_CHANGE)
14+ return;
15+
16+ /* Handle it later, and in the right thread */
17+ QMetaObject::invokeMethod((QPulseAudioEngine *) userdata, "plugUnplugSlot", Qt::QueuedConnection);
18+}
19+
20 Q_GLOBAL_STATIC(QPulseAudioEngine, pulseEngine);
21
22 QPulseAudioEngine::QPulseAudioEngine(QObject *parent)
23 : QObject(parent)
24 , m_mainLoopApi(0)
25 , m_context(0)
26+ , m_incall(false)
27+ , m_speakermode(false)
28
29 {
30 bool keepGoing = true;
31@@ -126,6 +140,8 @@
32
33 if (ok) {
34 pa_context_set_state_callback(m_context, contextStateCallback, this);
35+ pa_context_set_subscribe_callback(m_context, subscribeCallback, this);
36+ pa_context_subscribe(m_context, PA_SUBSCRIPTION_MASK_CARD, NULL, this);
37 } else {
38 if (m_context) {
39 pa_context_unref(m_context);
40@@ -159,8 +175,8 @@
41
42 void QPulseAudioEngine::sinkInfoCallback(const pa_sink_info *info)
43 {
44- pa_sink_port_info *earpiece = NULL, *speaker = NULL, *highest = NULL;
45- pa_sink_port_info *preferred = NULL;
46+ pa_sink_port_info *earpiece = NULL, *speaker = NULL, *headphones = NULL;
47+ pa_sink_port_info *highest = NULL, *preferred = NULL;
48
49 for (int i = 0; i < info->n_ports; i++) {
50 if (!highest || info->ports[i]->priority > highest->priority) {
51@@ -171,6 +187,8 @@
52 earpiece = info->ports[i];
53 if (!strcmp(info->ports[i]->name, "[Out] Speaker"))
54 speaker = info->ports[i];
55+ if (!strcmp(info->ports[i]->name, "[Out] Headphones") && info->ports[i]->available != PA_PORT_AVAILABLE_NO)
56+ headphones = info->ports[i];
57 }
58
59 if (!earpiece)
60@@ -182,7 +200,7 @@
61 if (m_speakermode)
62 preferred = speaker;
63 else if (m_incall)
64- preferred = earpiece;
65+ preferred = headphones ? headphones : earpiece;
66 if (!preferred)
67 preferred = highest;
68
69@@ -298,6 +316,13 @@
70 pa_threaded_mainloop_unlock(m_mainLoop);
71 }
72
73+void QPulseAudioEngine::plugUnplugSlot()
74+{
75+ qDebug("Notified about card event from PulseAudio");
76+ if (m_incall)
77+ setCallMode(m_incall, m_speakermode);
78+}
79+
80 QT_END_NAMESPACE
81
82 #endif
83
84=== modified file 'qpulseaudioengine.h'
85--- qpulseaudioengine.h 2013-08-22 07:22:28 +0000
86+++ qpulseaudioengine.h 2013-10-04 06:14:25 +0000
87@@ -41,9 +41,11 @@
88
89 void setCallMode(bool inCall, bool speakerMode);
90
91- /* These two are only used internally */
92+ /* These three are only used internally */
93 void cardInfoCallback(const pa_card_info *card);
94 void sinkInfoCallback(const pa_sink_info *sink);
95+public Q_SLOTS:
96+ void plugUnplugSlot();
97 private:
98 pa_mainloop_api *m_mainLoopApi;
99 pa_threaded_mainloop *m_mainLoop;

Subscribers

People subscribed via source and target branches