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
=== modified file 'src/core/media/service_implementation.cpp'
--- src/core/media/service_implementation.cpp 2015-03-20 13:16:35 +0000
+++ src/core/media/service_implementation.cpp 2015-04-02 14:48:42 +0000
@@ -41,6 +41,7 @@
41#include <map>41#include <map>
42#include <memory>42#include <memory>
43#include <thread>43#include <thread>
44#include <utility>
4445
45#include <pulse/pulseaudio.h>46#include <pulse/pulseaudio.h>
4647
@@ -83,7 +84,9 @@
83 media::audio::OutputState audio_output_state;84 media::audio::OutputState audio_output_state;
8485
85 media::telephony::CallMonitor::Ptr call_monitor;86 media::telephony::CallMonitor::Ptr call_monitor;
86 std::list<media::Player::PlayerKey> paused_sessions;87 // Holds a pair of a Player key denoting what player to resume playback, and a bool
88 // for if it should be resumed after a phone call is hung up
89 std::list<std::pair<media::Player::PlayerKey, bool>> paused_sessions;
87};90};
8891
89media::ServiceImplementation::ServiceImplementation(const Configuration& configuration)92media::ServiceImplementation::ServiceImplementation(const Configuration& configuration)
@@ -91,13 +94,16 @@
91{94{
92 d->battery_observer->level().changed().connect([this](const media::power::Level& level)95 d->battery_observer->level().changed().connect([this](const media::power::Level& level)
93 {96 {
97 const bool resume_play_after_phonecall = false;
94 // When the battery level hits 10% or 5%, pause all multimedia sessions.98 // When the battery level hits 10% or 5%, pause all multimedia sessions.
95 // Playback will resume when the user clears the presented notification.99 // Playback will resume when the user clears the presented notification.
96 switch (level)100 switch (level)
97 {101 {
98 case media::power::Level::low:102 case media::power::Level::low:
99 case media::power::Level::very_low:103 case media::power::Level::very_low:
100 pause_all_multimedia_sessions();104 // Whatever player session is currently playing, make sure it is NOT resumed after
105 // a phonecall is hung up
106 pause_all_multimedia_sessions(resume_play_after_phonecall);
101 break;107 break;
102 default:108 default:
103 break;109 break;
@@ -114,6 +120,7 @@
114120
115 d->audio_output_observer->external_output_state().changed().connect([this](audio::OutputState state)121 d->audio_output_observer->external_output_state().changed().connect([this](audio::OutputState state)
116 {122 {
123 const bool resume_play_after_phonecall = false;
117 switch (state)124 switch (state)
118 {125 {
119 case audio::OutputState::Earpiece:126 case audio::OutputState::Earpiece:
@@ -121,7 +128,9 @@
121 break;128 break;
122 case audio::OutputState::Speaker:129 case audio::OutputState::Speaker:
123 std::cout << "AudioOutputObserver reports that output is now Speaker." << std::endl;130 std::cout << "AudioOutputObserver reports that output is now Speaker." << std::endl;
124 pause_all_multimedia_sessions();131 // Whatever player session is currently playing, make sure it is NOT resumed after
132 // a phonecall is hung up
133 pause_all_multimedia_sessions(resume_play_after_phonecall);
125 break;134 break;
126 case audio::OutputState::External:135 case audio::OutputState::External:
127 std::cout << "AudioOutputObserver reports that output is now External." << std::endl;136 std::cout << "AudioOutputObserver reports that output is now External." << std::endl;
@@ -132,10 +141,13 @@
132141
133 d->call_monitor->on_call_state_changed().connect([this](media::telephony::CallMonitor::State state)142 d->call_monitor->on_call_state_changed().connect([this](media::telephony::CallMonitor::State state)
134 {143 {
144 const bool resume_play_after_phonecall = true;
135 switch (state) {145 switch (state) {
136 case media::telephony::CallMonitor::State::OffHook:146 case media::telephony::CallMonitor::State::OffHook:
137 std::cout << "Got call started signal, pausing all multimedia sessions" << std::endl;147 std::cout << "Got call started signal, pausing all multimedia sessions" << std::endl;
138 pause_all_multimedia_sessions();148 // Whatever player session is currently playing, make sure it gets resumed after
149 // a phonecall is hung up
150 pause_all_multimedia_sessions(resume_play_after_phonecall);
139 break;151 break;
140 case media::telephony::CallMonitor::State::OnHook:152 case media::telephony::CallMonitor::State::OnHook:
141 std::cout << "Got call ended signal, resuming paused multimedia sessions" << std::endl;153 std::cout << "Got call ended signal, resuming paused multimedia sessions" << std::endl;
@@ -149,7 +161,10 @@
149 if (state == media::RecordingState::started)161 if (state == media::RecordingState::started)
150 {162 {
151 d->display_state_lock->request_acquire(media::power::DisplayState::on);163 d->display_state_lock->request_acquire(media::power::DisplayState::on);
152 pause_all_multimedia_sessions();164 // Whatever player session is currently playing, make sure it is NOT resumed after
165 // a phonecall is hung up
166 const bool resume_play_after_phonecall = false;
167 pause_all_multimedia_sessions(resume_play_after_phonecall);
153 }168 }
154 else if (state == media::RecordingState::stopped)169 else if (state == media::RecordingState::stopped)
155 {170 {
@@ -244,15 +259,17 @@
244 });259 });
245}260}
246261
247void media::ServiceImplementation::pause_all_multimedia_sessions()262void media::ServiceImplementation::pause_all_multimedia_sessions(bool resume_play_after_phonecall)
248{263{
249 d->configuration.player_store->enumerate_players([this](const media::Player::PlayerKey& key, const std::shared_ptr<media::Player>& player)264 d->configuration.player_store->enumerate_players([this, resume_play_after_phonecall](const media::Player::PlayerKey& key, const std::shared_ptr<media::Player>& player)
250 {265 {
251 if (player->playback_status() == Player::playing266 if (player->playback_status() == Player::playing
252 && player->audio_stream_role() == media::Player::multimedia)267 && player->audio_stream_role() == media::Player::multimedia)
253 {268 {
254 d->paused_sessions.push_back(key);269 auto paused_player_pair = std::make_pair(key, resume_play_after_phonecall);
255 std::cout << "Pausing Player with key: " << key << std::endl;270 d->paused_sessions.push_back(paused_player_pair);
271 std::cout << "Pausing Player with key: " << key << ", resuming after phone call? "
272 << (resume_play_after_phonecall ? "yes" : "no") << std::endl;
256 player->pause();273 player->pause();
257 }274 }
258 });275 });
@@ -260,13 +277,16 @@
260277
261void media::ServiceImplementation::resume_paused_multimedia_sessions(bool resume_video_sessions)278void media::ServiceImplementation::resume_paused_multimedia_sessions(bool resume_video_sessions)
262{279{
263 std::for_each(d->paused_sessions.begin(), d->paused_sessions.end(), [this, resume_video_sessions](const media::Player::PlayerKey& key) {280 std::for_each(d->paused_sessions.begin(), d->paused_sessions.end(),
281 [this, resume_video_sessions](const std::pair<media::Player::PlayerKey, bool> &paused_player_pair) {
282 const media::Player::PlayerKey key = paused_player_pair.first;
283 const bool resume_play_after_phonecall = paused_player_pair.second;
264 auto player = d->configuration.player_store->player_for_key(key);284 auto player = d->configuration.player_store->player_for_key(key);
265 // Only resume video playback if explicitly desired285 // Only resume video playback if explicitly desired
266 if (resume_video_sessions || player->is_audio_source())286 if ((resume_video_sessions || player->is_audio_source()) && resume_play_after_phonecall)
267 player->play();287 player->play();
268 else288 else
269 std::cout << "Not auto-resuming video playback session." << std::endl;289 std::cout << "Not auto-resuming video player session or other type of player session." << std::endl;
270 });290 });
271291
272 d->paused_sessions.clear();292 d->paused_sessions.clear();
273293
=== modified file 'src/core/media/service_implementation.h'
--- src/core/media/service_implementation.h 2015-01-26 13:08:02 +0000
+++ src/core/media/service_implementation.h 2015-04-02 14:48:42 +0000
@@ -49,7 +49,7 @@
49 void pause_other_sessions(Player::PlayerKey key);49 void pause_other_sessions(Player::PlayerKey key);
5050
51private:51private:
52 void pause_all_multimedia_sessions();52 void pause_all_multimedia_sessions(bool resume_play_after_phonecall);
53 void resume_paused_multimedia_sessions(bool resume_video_sessions = true);53 void resume_paused_multimedia_sessions(bool resume_video_sessions = true);
54 void resume_multimedia_session();54 void resume_multimedia_session();
5555

Subscribers

People subscribed via source and target branches