Merge lp:~tiagosh/telepathy-ofono/fallback_a2dp into lp:telepathy-ofono

Proposed by Tiago Salem Herrmann on 2015-11-27
Status: Superseded
Proposed branch: lp:~tiagosh/telepathy-ofono/fallback_a2dp
Merge into: lp:telepathy-ofono
Diff against target: 137 lines (+60/-8)
3 files modified
connection.cpp (+1/-1)
qpulseaudioengine.cpp (+56/-6)
qpulseaudioengine.h (+3/-1)
To merge this branch: bzr merge lp:~tiagosh/telepathy-ofono/fallback_a2dp
Reviewer Review Type Date Requested Status
Ubuntu Phablet Team 2015-11-27 Pending
Review via email: mp+278838@code.launchpad.net

This proposal has been superseded by a proposal from 2015-11-27.

Commit message

Fallback to a2dp if no profile is set.

Description of the change

Fallback to a2dp if no profile is set.

To post a comment you must log in.

Unmerged revisions

172. By Tiago Salem Herrmann on 2015-11-27

Fallback to a2dp if no profile is set

171. By Tiago Salem Herrmann on 2015-11-24

Set bluetooth device when playing the ringtone

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'connection.cpp'
2--- connection.cpp 2015-10-13 19:29:54 +0000
3+++ connection.cpp 2015-11-27 15:56:01 +0000
4@@ -72,7 +72,7 @@
5 static void enable_ringtone()
6 {
7 #ifdef USE_PULSEAUDIO
8- QPulseAudioEngine::instance()->setCallMode(CallRinging, AudioModeWiredOrSpeaker);
9+ QPulseAudioEngine::instance()->setCallMode(CallRinging, AudioModeBtOrWiredOrSpeaker);
10 #endif
11 }
12
13
14=== modified file 'qpulseaudioengine.cpp'
15--- qpulseaudioengine.cpp 2015-11-10 07:49:07 +0000
16+++ qpulseaudioengine.cpp 2015-11-27 15:56:01 +0000
17@@ -113,6 +113,7 @@
18 , m_voicecallprofile("")
19 , m_bt_hsp("")
20 , m_bt_hsp_a2dp("")
21+ , m_default_bt_card_fallback("")
22
23 {
24 m_mainLoop = pa_threaded_mainloop_new();
25@@ -658,14 +659,26 @@
26 {
27 qDebug("Notified about card (%s) add event from PulseAudio", info->name);
28
29+ /* Check if it's indeed a BT device (with at least one hsp profile) */
30+ pa_card_profile_info2 *hsp = NULL, *a2dp = NULL;
31+ for (int i = 0; i < info->n_profiles; i++) {
32+ if (!strcmp(info->profiles2[i]->name, PULSEAUDIO_PROFILE_HSP))
33+ hsp = info->profiles2[i];
34+ else if (!strcmp(info->profiles2[i]->name, PULSEAUDIO_PROFILE_A2DP) &&
35+ info->profiles2[i]->available != 0) {
36+ qDebug("Found a2dp");
37+ a2dp = info->profiles2[i];
38+ }
39+ qDebug("%s", info->profiles2[i]->name);
40+ }
41+
42+ if ((!info->active_profile || !strcmp(info->active_profile->name, "off")) && a2dp) {
43+ qDebug("No profile set");
44+ m_default_bt_card_fallback = info->name;
45+ }
46+
47 /* We only care about BT (HSP) devices, and if one is not already available */
48 if ((m_callstatus != CallEnded) && ((m_bt_hsp == "") || (m_bt_hsp_a2dp == ""))) {
49- /* Check if it's indeed a BT device (with at least one hsp profile) */
50- pa_card_profile_info *hsp = NULL;
51- for (int i = 0; i < info->n_profiles; i++) {
52- if (!strcmp(info->profiles[i].name, PULSEAUDIO_PROFILE_HSP))
53- hsp = &info->profiles[i];
54- }
55 if (hsp)
56 m_handleevent = true;
57 }
58@@ -675,6 +688,25 @@
59 {
60 qDebug("Notified about card (%s) changes event from PulseAudio", info->name);
61
62+ /* Check if it's indeed a BT device (with at least one hsp profile) */
63+ pa_card_profile_info2 *hsp = NULL, *a2dp = NULL;
64+ for (int i = 0; i < info->n_profiles; i++) {
65+ if (!strcmp(info->profiles2[i]->name, PULSEAUDIO_PROFILE_HSP))
66+ hsp = info->profiles2[i];
67+ else if (!strcmp(info->profiles2[i]->name, PULSEAUDIO_PROFILE_A2DP) &&
68+ info->profiles2[i]->available != 0) {
69+ qDebug("Found a2dp");
70+ a2dp = info->profiles2[i];
71+ }
72+ qDebug("%s", info->profiles2[i]->name);
73+ }
74+
75+ if ((!info->active_profile || !strcmp(info->active_profile->name, "off")) && a2dp) {
76+ qDebug("No profile set");
77+ m_default_bt_card_fallback = info->name;
78+ }
79+
80+
81 /* We only care if the card event for the voicecall capable card */
82 if ((m_callstatus == CallActive) && (!strcmp(info->name, m_voicecallcard.c_str()))) {
83 if (m_audiomode == AudioModeWiredHeadset) {
84@@ -718,6 +750,15 @@
85 o = pa_context_get_card_info_by_index(m_context, idx, plug_card_cb, this);
86 if (!handleOperation(o, "pa_context_get_card_info_by_index"))
87 return;
88+
89+ if (m_default_bt_card_fallback != "") {
90+ o = pa_context_set_card_profile_by_name(m_context,
91+ m_default_bt_card_fallback.c_str(), PULSEAUDIO_PROFILE_A2DP, success_cb, this);
92+ if (!handleOperation(o, "pa_context_set_card_profile_by_name"))
93+ return;
94+ m_default_bt_card_fallback = "";
95+ }
96+
97 if (m_handleevent) {
98 qDebug("Adding new BT-HSP capable device");
99 /* In case A2DP is available, switch to HSP */
100@@ -730,6 +771,15 @@
101 o = pa_context_get_card_info_by_index(m_context, idx, update_card_cb, this);
102 if (!handleOperation(o, "pa_context_get_card_info_by_index"))
103 return;
104+
105+ if (m_default_bt_card_fallback != "") {
106+ o = pa_context_set_card_profile_by_name(m_context,
107+ m_default_bt_card_fallback.c_str(), PULSEAUDIO_PROFILE_A2DP, success_cb, this);
108+ if (!handleOperation(o, "pa_context_set_card_profile_by_name"))
109+ return;
110+ m_default_bt_card_fallback = "";
111+ }
112+
113 if (m_handleevent) {
114 /* In this case it means the handset state changed */
115 qDebug("Notifying card changes for the voicecall capable card");
116
117=== modified file 'qpulseaudioengine.h'
118--- qpulseaudioengine.h 2015-07-28 18:10:10 +0000
119+++ qpulseaudioengine.h 2015-11-27 15:56:01 +0000
120@@ -32,7 +32,8 @@
121 AudioModeBluetooth = 0x0008,
122 AudioModeBtOrWiredOrEarpiece = AudioModeBluetooth | AudioModeWiredHeadset | AudioModeEarpiece,
123 AudioModeWiredOrEarpiece = AudioModeWiredHeadset | AudioModeEarpiece,
124- AudioModeWiredOrSpeaker = AudioModeWiredHeadset | AudioModeSpeaker
125+ AudioModeWiredOrSpeaker = AudioModeWiredHeadset | AudioModeSpeaker,
126+ AudioModeBtOrWiredOrSpeaker = AudioModeBluetooth | AudioModeWiredOrSpeaker
127 };
128
129 Q_DECLARE_METATYPE(AudioMode)
130@@ -94,6 +95,7 @@
131 std::string m_nametoset, m_valuetoset;
132 std::string m_defaultsink, m_defaultsource;
133 std::string m_bt_hsp, m_bt_hsp_a2dp;
134+ std::string m_default_bt_card_fallback;
135 std::string m_voicecallcard, m_voicecallhighest, m_voicecallprofile;
136
137 bool handleOperation(pa_operation *operation, const char *func_name);

Subscribers

People subscribed via source and target branches