Merge lp:~jhodapp/media-hub/fix-1421620 into lp:media-hub

Proposed by Jim Hodapp
Status: Merged
Approved by: Ricardo Salveti
Approved revision: 130
Merged at revision: 130
Proposed branch: lp:~jhodapp/media-hub/fix-1421620
Merge into: lp:media-hub
Diff against target: 140 lines (+33/-13)
2 files modified
src/core/media/service_implementation.cpp (+32/-12)
src/core/media/service_implementation.h (+1/-1)
To merge this branch: bzr merge lp:~jhodapp/media-hub/fix-1421620
Reviewer Review Type Date Requested Status
Ricardo Salveti (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+255100@code.launchpad.net

Commit message

Fix the bug which caused music playback to start playing again after a phonecall hung up after being auto-paused by disconnecting a headphone jack.

Description of the change

Fix the bug which caused music playback to start playing again after a phonecall hung up after being auto-paused by disconnecting a headphone jack.

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
Ricardo Salveti (rsalveti) wrote :

Looks good, similar fix already in RTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/core/media/service_implementation.cpp'
2--- src/core/media/service_implementation.cpp 2015-03-20 13:16:35 +0000
3+++ src/core/media/service_implementation.cpp 2015-04-02 14:48:42 +0000
4@@ -41,6 +41,7 @@
5 #include <map>
6 #include <memory>
7 #include <thread>
8+#include <utility>
9
10 #include <pulse/pulseaudio.h>
11
12@@ -83,7 +84,9 @@
13 media::audio::OutputState audio_output_state;
14
15 media::telephony::CallMonitor::Ptr call_monitor;
16- std::list<media::Player::PlayerKey> paused_sessions;
17+ // Holds a pair of a Player key denoting what player to resume playback, and a bool
18+ // for if it should be resumed after a phone call is hung up
19+ std::list<std::pair<media::Player::PlayerKey, bool>> paused_sessions;
20 };
21
22 media::ServiceImplementation::ServiceImplementation(const Configuration& configuration)
23@@ -91,13 +94,16 @@
24 {
25 d->battery_observer->level().changed().connect([this](const media::power::Level& level)
26 {
27+ const bool resume_play_after_phonecall = false;
28 // When the battery level hits 10% or 5%, pause all multimedia sessions.
29 // Playback will resume when the user clears the presented notification.
30 switch (level)
31 {
32 case media::power::Level::low:
33 case media::power::Level::very_low:
34- pause_all_multimedia_sessions();
35+ // Whatever player session is currently playing, make sure it is NOT resumed after
36+ // a phonecall is hung up
37+ pause_all_multimedia_sessions(resume_play_after_phonecall);
38 break;
39 default:
40 break;
41@@ -114,6 +120,7 @@
42
43 d->audio_output_observer->external_output_state().changed().connect([this](audio::OutputState state)
44 {
45+ const bool resume_play_after_phonecall = false;
46 switch (state)
47 {
48 case audio::OutputState::Earpiece:
49@@ -121,7 +128,9 @@
50 break;
51 case audio::OutputState::Speaker:
52 std::cout << "AudioOutputObserver reports that output is now Speaker." << std::endl;
53- pause_all_multimedia_sessions();
54+ // Whatever player session is currently playing, make sure it is NOT resumed after
55+ // a phonecall is hung up
56+ pause_all_multimedia_sessions(resume_play_after_phonecall);
57 break;
58 case audio::OutputState::External:
59 std::cout << "AudioOutputObserver reports that output is now External." << std::endl;
60@@ -132,10 +141,13 @@
61
62 d->call_monitor->on_call_state_changed().connect([this](media::telephony::CallMonitor::State state)
63 {
64+ const bool resume_play_after_phonecall = true;
65 switch (state) {
66 case media::telephony::CallMonitor::State::OffHook:
67 std::cout << "Got call started signal, pausing all multimedia sessions" << std::endl;
68- pause_all_multimedia_sessions();
69+ // Whatever player session is currently playing, make sure it gets resumed after
70+ // a phonecall is hung up
71+ pause_all_multimedia_sessions(resume_play_after_phonecall);
72 break;
73 case media::telephony::CallMonitor::State::OnHook:
74 std::cout << "Got call ended signal, resuming paused multimedia sessions" << std::endl;
75@@ -149,7 +161,10 @@
76 if (state == media::RecordingState::started)
77 {
78 d->display_state_lock->request_acquire(media::power::DisplayState::on);
79- pause_all_multimedia_sessions();
80+ // Whatever player session is currently playing, make sure it is NOT resumed after
81+ // a phonecall is hung up
82+ const bool resume_play_after_phonecall = false;
83+ pause_all_multimedia_sessions(resume_play_after_phonecall);
84 }
85 else if (state == media::RecordingState::stopped)
86 {
87@@ -244,15 +259,17 @@
88 });
89 }
90
91-void media::ServiceImplementation::pause_all_multimedia_sessions()
92+void media::ServiceImplementation::pause_all_multimedia_sessions(bool resume_play_after_phonecall)
93 {
94- d->configuration.player_store->enumerate_players([this](const media::Player::PlayerKey& key, const std::shared_ptr<media::Player>& player)
95+ d->configuration.player_store->enumerate_players([this, resume_play_after_phonecall](const media::Player::PlayerKey& key, const std::shared_ptr<media::Player>& player)
96 {
97 if (player->playback_status() == Player::playing
98 && player->audio_stream_role() == media::Player::multimedia)
99 {
100- d->paused_sessions.push_back(key);
101- std::cout << "Pausing Player with key: " << key << std::endl;
102+ auto paused_player_pair = std::make_pair(key, resume_play_after_phonecall);
103+ d->paused_sessions.push_back(paused_player_pair);
104+ std::cout << "Pausing Player with key: " << key << ", resuming after phone call? "
105+ << (resume_play_after_phonecall ? "yes" : "no") << std::endl;
106 player->pause();
107 }
108 });
109@@ -260,13 +277,16 @@
110
111 void media::ServiceImplementation::resume_paused_multimedia_sessions(bool resume_video_sessions)
112 {
113- std::for_each(d->paused_sessions.begin(), d->paused_sessions.end(), [this, resume_video_sessions](const media::Player::PlayerKey& key) {
114+ std::for_each(d->paused_sessions.begin(), d->paused_sessions.end(),
115+ [this, resume_video_sessions](const std::pair<media::Player::PlayerKey, bool> &paused_player_pair) {
116+ const media::Player::PlayerKey key = paused_player_pair.first;
117+ const bool resume_play_after_phonecall = paused_player_pair.second;
118 auto player = d->configuration.player_store->player_for_key(key);
119 // Only resume video playback if explicitly desired
120- if (resume_video_sessions || player->is_audio_source())
121+ if ((resume_video_sessions || player->is_audio_source()) && resume_play_after_phonecall)
122 player->play();
123 else
124- std::cout << "Not auto-resuming video playback session." << std::endl;
125+ std::cout << "Not auto-resuming video player session or other type of player session." << std::endl;
126 });
127
128 d->paused_sessions.clear();
129
130=== modified file 'src/core/media/service_implementation.h'
131--- src/core/media/service_implementation.h 2015-01-26 13:08:02 +0000
132+++ src/core/media/service_implementation.h 2015-04-02 14:48:42 +0000
133@@ -49,7 +49,7 @@
134 void pause_other_sessions(Player::PlayerKey key);
135
136 private:
137- void pause_all_multimedia_sessions();
138+ void pause_all_multimedia_sessions(bool resume_play_after_phonecall);
139 void resume_paused_multimedia_sessions(bool resume_video_sessions = true);
140 void resume_multimedia_session();
141

Subscribers

People subscribed via source and target branches