Merge lp:~phablet-team/media-hub/fix-1479036 into lp:media-hub/stable

Proposed by Jim Hodapp
Status: Merged
Approved by: Alfonso Sanchez-Beato
Approved revision: 173
Merged at revision: 170
Proposed branch: lp:~phablet-team/media-hub/fix-1479036
Merge into: lp:media-hub/stable
Diff against target: 173 lines (+83/-23)
2 files modified
src/core/media/service_implementation.cpp (+38/-7)
src/core/media/service_skeleton.cpp (+45/-16)
To merge this branch: bzr merge lp:~phablet-team/media-hub/fix-1479036
Reviewer Review Type Date Requested Status
Alfonso Sanchez-Beato Approve
Review via email: mp+280872@code.launchpad.net

Commit message

Fix bug #1479036 which prevents the out_of_range exception from causing media-hub-server from crashing when a player key is not found

Description of the change

Fix bug #1479036 which prevents the out_of_range exception from causing media-hub-server from crashing when a player key is not found

To post a comment you must log in.
171. By Jim Hodapp

Fix formatting of 2 lines

Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

Some issues, mostly related to handling this in the caller of these functions instead so errors can be returned in the DBus response. An example where this is already performed is in ServiceSkeleton::handle_set_current_player().

The only exception is probably the handler of player->on_client_disconnected(), as the trigger is not a DBus function in that case.

review: Needs Fixing
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

Ouch, I forgot to save the inline comments. Anyway, the idea is to handle this returning a DBus error where possible, see previous comment.

172. By Jim Hodapp

Make sure to pass on the failed Player key lookup to the client when possible.

Revision history for this message
Jim Hodapp (jhodapp) wrote :

Addressed the review comments.

173. By Jim Hodapp

No need to catch out_of_range in set_current_player since it's handled in handle_set_current_player

Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

LGTM

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-10-14 20:54:19 +0000
+++ src/core/media/service_implementation.cpp 2015-12-18 16:22:27 +0000
@@ -210,8 +210,17 @@
210 if (!d->configuration.player_store->has_player_for_key(key))210 if (!d->configuration.player_store->has_player_for_key(key))
211 return;211 return;
212212
213 if (d->configuration.player_store->player_for_key(key)->lifetime() == Player::Lifetime::normal)213 try {
214 d->configuration.player_store->remove_player_for_key(key);214 if (d->configuration.player_store->player_for_key(key)->lifetime() == Player::Lifetime::normal)
215 d->configuration.player_store->remove_player_for_key(key);
216 }
217 catch (const std::out_of_range &e) {
218 std::cerr << "Failed to look up Player instance for key " << key
219 << ", no valid Player instance for that key value. Removal of Player from Player store"
220 << " might not have completed. This most likely means that media-hub-server has"
221 << " crashed and restarted." << std::endl;
222 return;
223 }
215 });224 });
216 });225 });
217226
@@ -246,7 +255,7 @@
246 return std::shared_ptr<media::Player>();255 return std::shared_ptr<media::Player>();
247}256}
248257
249void media::ServiceImplementation::set_current_player(Player::PlayerKey key)258void media::ServiceImplementation::set_current_player(Player::PlayerKey)
250{259{
251 // no impl260 // no impl
252}261}
@@ -261,13 +270,15 @@
261 return;270 return;
262 }271 }
263272
264 auto current_player = d->configuration.player_store->player_for_key(key);273 const std::shared_ptr<media::Player> current_player = d->configuration.player_store->player_for_key(key);
265274
266 // We immediately make the player known as new current player.275 // We immediately make the player known as new current player.
267 if (current_player->audio_stream_role() == media::Player::multimedia)276 if (current_player->audio_stream_role() == media::Player::multimedia)
268 d->configuration.player_store->set_current_player_for_key(key);277 d->configuration.player_store->set_current_player_for_key(key);
269278
270 d->configuration.player_store->enumerate_players([current_player, key](const media::Player::PlayerKey& other_key, const std::shared_ptr<media::Player>& other_player)279 d->configuration.player_store->enumerate_players(
280 [current_player, key](const media::Player::PlayerKey& other_key,
281 const std::shared_ptr<media::Player>& other_player)
271 {282 {
272 // Only pause a Player if all of the following criteria are met:283 // Only pause a Player if all of the following criteria are met:
273 // 1) currently playing284 // 1) currently playing
@@ -307,7 +318,17 @@
307 [this, resume_video_sessions](const std::pair<media::Player::PlayerKey, bool> &paused_player_pair) {318 [this, resume_video_sessions](const std::pair<media::Player::PlayerKey, bool> &paused_player_pair) {
308 const media::Player::PlayerKey key = paused_player_pair.first;319 const media::Player::PlayerKey key = paused_player_pair.first;
309 const bool resume_play_after_phonecall = paused_player_pair.second;320 const bool resume_play_after_phonecall = paused_player_pair.second;
310 auto player = d->configuration.player_store->player_for_key(key);321 std::shared_ptr<media::Player> player;
322 try {
323 player = d->configuration.player_store->player_for_key(key);
324 }
325 catch (const std::out_of_range &e) {
326 std::cerr << "Failed to look up Player instance for key " << key
327 << ", no valid Player instance for that key value and cannot automatically resume"
328 << " paused players. This most likely means that media-hub-server has crashed and"
329 << " restarted." << std::endl;
330 return;
331 }
311 // Only resume video playback if explicitly desired332 // Only resume video playback if explicitly desired
312 if ((resume_video_sessions || player->is_audio_source()) && resume_play_after_phonecall)333 if ((resume_video_sessions || player->is_audio_source()) && resume_play_after_phonecall)
313 player->play();334 player->play();
@@ -323,7 +344,17 @@
323 if (not d->configuration.player_store->has_player_for_key(d->resume_key))344 if (not d->configuration.player_store->has_player_for_key(d->resume_key))
324 return;345 return;
325346
326 auto player = d->configuration.player_store->player_for_key(d->resume_key);347 std::shared_ptr<media::Player> player;
348 try {
349 player = d->configuration.player_store->player_for_key(d->resume_key);
350 }
351 catch (const std::out_of_range &e) {
352 std::cerr << "Failed to look up Player instance for key " << d->resume_key
353 << ", no valid Player instance for that key value and cannot automatically resume"
354 << " paused Player. This most likely means that media-hub-server has crashed and"
355 << " restarted." << std::endl;
356 return;
357 }
327358
328 if (player->playback_status() == Player::paused)359 if (player->playback_status() == Player::paused)
329 {360 {
330361
=== modified file 'src/core/media/service_skeleton.cpp'
--- src/core/media/service_skeleton.cpp 2015-11-13 15:26:35 +0000
+++ src/core/media/service_skeleton.cpp 2015-12-18 16:22:27 +0000
@@ -450,27 +450,55 @@
450 msg->reader() >> key;450 msg->reader() >> key;
451451
452 core::dbus::Message::Ptr reply;452 core::dbus::Message::Ptr reply;
453 if (not configuration.player_store->has_player_for_key(key)) {453 if (not configuration.player_store->has_player_for_key(key))
454 cerr << __PRETTY_FUNCTION__ << " player key not found - " << key << endl;454 {
455 std::cerr << __PRETTY_FUNCTION__ << " player key not found - " << key << std::endl;
455 reply = dbus::Message::make_error(456 reply = dbus::Message::make_error(
456 msg,457 msg,
457 mpris::Service::Errors::PlayerKeyNotFound::name(),458 mpris::Service::Errors::PlayerKeyNotFound::name(),
458 "Player key not found");459 "Player key not found");
459 } else {460 }
460 impl->set_current_player(key);461 else
462 {
463 try {
464 impl->set_current_player(key);
465 reply = dbus::Message::make_method_return(msg);
466 }
467 catch (const std::out_of_range &e) {
468 std::cerr << "Failed to look up Player instance for key " << key
469 << ", no valid Player instance for that key value and cannot set current player."
470 << " This most likely means that media-hub-server has crashed and restarted."
471 << std::endl;
472 reply = dbus::Message::make_error(
473 msg,
474 mpris::Service::Errors::PlayerKeyNotFound::name(),
475 "Player key not found");
476 }
477 }
478
479 impl->access_bus()->send(reply);
480 }
481
482 void handle_pause_other_sessions(const core::dbus::Message::Ptr& msg)
483 {
484 Player::PlayerKey key;
485 msg->reader() >> key;
486 core::dbus::Message::Ptr reply;
487 try {
488 impl->pause_other_sessions(key);
461 reply = dbus::Message::make_method_return(msg);489 reply = dbus::Message::make_method_return(msg);
462 }490 }
463491 catch (const std::out_of_range &e) {
464 impl->access_bus()->send(reply);492 std::cerr << "Failed to look up Player instance for key " << key
465 }493 << ", no valid Player instance for that key value and cannot pause other Players."
466494 << " This most likely means that media-hub-server has crashed and restarted."
467 void handle_pause_other_sessions(const core::dbus::Message::Ptr& msg)495 << std::endl;
468 {496 reply = dbus::Message::make_error(
469 Player::PlayerKey key;497 msg,
470 msg->reader() >> key;498 mpris::Service::Errors::PlayerKeyNotFound::name(),
471 impl->pause_other_sessions(key);499 "Player key not found");
472500 }
473 auto reply = dbus::Message::make_method_return(msg);501
474 impl->access_bus()->send(reply);502 impl->access_bus()->send(reply);
475 }503 }
476504
@@ -864,7 +892,8 @@
864892
865void media::ServiceSkeleton::set_current_player(media::Player::PlayerKey key)893void media::ServiceSkeleton::set_current_player(media::Player::PlayerKey key)
866{894{
867 const auto player = d->configuration.player_store->player_for_key(key);895 const std::shared_ptr<media::Player> player =
896 d->configuration.player_store->player_for_key(key);
868 // We only care to allow the MPRIS controls to apply to multimedia player (i.e. audio, video)897 // We only care to allow the MPRIS controls to apply to multimedia player (i.e. audio, video)
869 if (player->audio_stream_role() == media::Player::AudioStreamRole::multimedia)898 if (player->audio_stream_role() == media::Player::AudioStreamRole::multimedia)
870 d->exported.set_current_player(player);899 d->exported.set_current_player(player);

Subscribers

People subscribed via source and target branches

to all changes: