Merge lp:~jhodapp/media-hub/fix-1421620-rtm into lp:~phablet-team/media-hub/media-hub-rtm-14.09

Proposed by Jim Hodapp on 2015-03-31
Status: Merged
Approved by: Ricardo Salveti on 2015-04-01
Approved revision: 88
Merged at revision: 89
Proposed branch: lp:~jhodapp/media-hub/fix-1421620-rtm
Merge into: lp:~phablet-team/media-hub/media-hub-rtm-14.09
Diff against target: 105 lines (+24/-11)
2 files modified
src/core/media/service_implementation.cpp (+23/-10)
src/core/media/service_implementation.h (+1/-1)
To merge this branch: bzr merge lp:~jhodapp/media-hub/fix-1421620-rtm
Reviewer Review Type Date Requested Status
Ricardo Salveti (community) 2015-03-31 Approve on 2015-04-01
Review via email: mp+254842@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.
Ricardo Salveti (rsalveti) wrote :

Looks good, 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 'src/core/media/service_implementation.cpp'
2--- src/core/media/service_implementation.cpp 2015-03-31 20:38:11 +0000
3+++ src/core/media/service_implementation.cpp 2015-03-31 21:23:21 +0000
4@@ -35,6 +35,7 @@
5 #include <map>
6 #include <memory>
7 #include <thread>
8+#include <utility>
9
10 #include <pulse/pulseaudio.h>
11
12@@ -478,7 +479,9 @@
13 // begins.
14 core::Signal<void> pause_playback;
15 std::unique_ptr<CallMonitor> 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() : d(new Private())
23@@ -488,7 +491,9 @@
24 // When the battery level hits 10% or 5%, pause all multimedia sessions.
25 // Playback will resume when the user clears the presented notification.
26 if (level == "low" || level == "very_low")
27- pause_all_multimedia_sessions();
28+ // Whatever player session is currently playing, make sure it is NOT resumed after
29+ // a phonecall is hung up
30+ pause_all_multimedia_sessions(false);
31 });
32
33 d->is_warning->changed().connect([this](const core::IndicatorPower::IsWarning::ValueType &notifying)
34@@ -502,14 +507,18 @@
35 d->pause_playback.connect([this]()
36 {
37 std::cout << "Got pause_playback signal, pausing all multimedia sessions" << std::endl;
38- pause_all_multimedia_sessions();
39+ // Whatever player session is currently playing, make sure it is NOT resumed after
40+ // a phonecall is hung up
41+ pause_all_multimedia_sessions(false);
42 });
43
44 d->call_monitor->on_change([this](CallMonitor::State state) {
45 switch (state) {
46 case CallMonitor::OffHook:
47 std::cout << "Got call started signal, pausing all multimedia sessions" << std::endl;
48- pause_all_multimedia_sessions();
49+ // Whatever player session is currently playing, make sure it gets resumed after
50+ // a phonecall is hung up
51+ pause_all_multimedia_sessions(true);
52 break;
53 case CallMonitor::OnHook:
54 std::cout << "Got call ended signal, resuming paused multimedia sessions" << std::endl;
55@@ -579,14 +588,15 @@
56 });
57 }
58
59-void media::ServiceImplementation::pause_all_multimedia_sessions()
60+void media::ServiceImplementation::pause_all_multimedia_sessions(bool resume_play_after_phonecall)
61 {
62- enumerate_players([this](const media::Player::PlayerKey& key, const std::shared_ptr<media::Player>& player)
63+ enumerate_players([this, resume_play_after_phonecall](const media::Player::PlayerKey& key, const std::shared_ptr<media::Player>& player)
64 {
65 if (player->playback_status() == Player::playing
66 && player->audio_stream_role() == media::Player::multimedia)
67 {
68- d->paused_sessions.push_back(key);
69+ auto paused_player_pair = std::make_pair(key, resume_play_after_phonecall);
70+ d->paused_sessions.push_back(paused_player_pair);
71 std::cout << "Pausing Player with key: " << key << std::endl;
72 player->pause();
73 }
74@@ -595,13 +605,16 @@
75
76 void media::ServiceImplementation::resume_paused_multimedia_sessions(bool resume_video_sessions)
77 {
78- std::for_each(d->paused_sessions.begin(), d->paused_sessions.end(), [this, resume_video_sessions](const media::Player::PlayerKey& key) {
79+ std::for_each(d->paused_sessions.begin(), d->paused_sessions.end(),
80+ [this, resume_video_sessions](const std::pair<media::Player::PlayerKey, bool> &paused_player_pair) {
81+ const media::Player::PlayerKey key = paused_player_pair.first;
82+ const bool resume_play_after_phonecall = paused_player_pair.second;
83 auto player = player_for_key(key);
84 // Only resume video playback if explicitly desired
85- if (resume_video_sessions || player->is_audio_source())
86+ if ((resume_video_sessions || player->is_audio_source()) && resume_play_after_phonecall)
87 player->play();
88 else
89- std::cout << "Not auto-resuming video playback session." << std::endl;
90+ std::cout << "Not auto-resuming video player session or other type of player session." << std::endl;
91 });
92
93 d->paused_sessions.clear();
94
95=== modified file 'src/core/media/service_implementation.h'
96--- src/core/media/service_implementation.h 2015-03-31 20:38:11 +0000
97+++ src/core/media/service_implementation.h 2015-03-31 21:23:21 +0000
98@@ -41,7 +41,7 @@
99 void pause_other_sessions(Player::PlayerKey key);
100
101 private:
102- void pause_all_multimedia_sessions();
103+ void pause_all_multimedia_sessions(bool resume_play_after_phonecall);
104 void resume_paused_multimedia_sessions(bool resume_video_sessions = true);
105 void resume_multimedia_session();
106

Subscribers

People subscribed via source and target branches