~ci-train-bot/media-hub/media-hub-ubuntu-yakkety-landing-051

« back to all changes in this revision

Viewing changes to src/core/media/player_implementation.cpp

  • Committer: CI Train Bot
  • Author(s): Jim Hodapp, Konrad Zapałowicz
  • Date: 2016-05-04 13:13:15 UTC
  • mfrom: (177.3.23 media-hub-take2)
  • Revision ID: ci-train-bot@canonical.com-20160504131315-6qbj1krz2y0751qg
A rewrite of how the current player is set which is what the MPRIS control interface actively uses. Fixes: #1538703
Approved by: Alfonso Sanchez-Beato, Konrad Zapałowicz, PS Jenkins bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *              Jim Hodapp <jim.hodapp@canonical.com>
18
18
 */
19
19
 
 
20
#include <core/media/service.h>
 
21
 
20
22
#include "player_implementation.h"
 
23
#include "service_skeleton.h"
21
24
#include "util/timeout.h"
22
25
 
23
26
#include <unistd.h>
301
304
        }
302
305
    }
303
306
 
304
 
    void update_mpris_properties(void)
 
307
    void update_mpris_properties()
305
308
    {
306
 
        bool has_previous =    track_list->has_previous()
 
309
        const bool has_previous = track_list->has_previous()
307
310
                            or parent->Parent::loop_status() != Player::LoopStatus::none;
308
 
        bool has_next =    track_list->has_next()
 
311
        const bool has_next = track_list->has_next()
309
312
                        or parent->Parent::loop_status() != Player::LoopStatus::none;
310
 
        auto n_tracks = track_list->tracks()->size();
311
 
        bool has_tracks = (n_tracks > 0) ? true : false;
 
313
        const auto n_tracks = track_list->tracks()->size();
 
314
        const bool has_tracks = (n_tracks > 0) ? true : false;
312
315
 
313
316
        MH_INFO("Updating MPRIS TrackList properties:");
314
317
        MH_INFO("\tTracks: %d", n_tracks);
322
325
        parent->can_go_next().set(has_next);
323
326
    }
324
327
 
 
328
    bool pause_other_players(media::Player::PlayerKey key)
 
329
    {
 
330
        if (not config.parent.player_service)
 
331
            return false;
 
332
 
 
333
        media::ServiceSkeleton* skel {
 
334
            reinterpret_cast<media::ServiceSkeleton*>(config.parent.player_service)
 
335
        };
 
336
        skel->pause_other_sessions(key);
 
337
        return true;
 
338
    }
 
339
 
 
340
    bool update_current_player(media::Player::PlayerKey key)
 
341
    {
 
342
        if (not config.parent.player_service)
 
343
            return false;
 
344
 
 
345
        media::ServiceSkeleton* skel {
 
346
            reinterpret_cast<media::ServiceSkeleton*>(config.parent.player_service)
 
347
        };
 
348
        skel->set_current_player(key);
 
349
        return true;
 
350
    }
 
351
 
 
352
    bool is_current_player() const
 
353
    {
 
354
        if (not config.parent.player_service)
 
355
            return false;
 
356
 
 
357
        media::ServiceSkeleton* skel {
 
358
            reinterpret_cast<media::ServiceSkeleton*>(config.parent.player_service)
 
359
        };
 
360
        return skel->is_current_player(parent->key());
 
361
    }
 
362
 
 
363
    bool is_multimedia_role() const
 
364
    {
 
365
        return parent->audio_stream_role() == media::Player::AudioStreamRole::multimedia;
 
366
    }
 
367
 
 
368
    bool reset_current_player()
 
369
    {
 
370
        if (not config.parent.player_service)
 
371
            return false;
 
372
 
 
373
        media::ServiceSkeleton* skel {
 
374
            reinterpret_cast<media::ServiceSkeleton*>(config.parent.player_service)
 
375
        };
 
376
        skel->reset_current_player();
 
377
        return true;
 
378
    }
 
379
 
325
380
    // Our link back to our parent.
326
381
    media::PlayerImplementation<Parent>* parent;
327
382
    // We just store the parameters passed on construction.
478
533
        // are cleared
479
534
        d->clear_wakelocks();
480
535
        d->track_list->reset();
 
536
 
 
537
        // This is not a fatal error but merely a warning that should
 
538
        // be logged
 
539
        if (d->is_multimedia_role() and d->is_current_player())
 
540
        {
 
541
            MH_DEBUG("==== Resetting current player");
 
542
            if (not d->reset_current_player())
 
543
                MH_WARNING("Failed to reset current player");
 
544
        }
 
545
 
481
546
        // And tell the outside world that the client has gone away
482
547
        d->on_client_disconnected();
483
548
    });
687
752
    d->track_list->reset();
688
753
 
689
754
    // If empty uri, give the same meaning as QMediaPlayer::setMedia("")
690
 
    if (uri.empty()) {
 
755
    if (uri.empty())
 
756
    {
691
757
        MH_DEBUG("Resetting current media");
692
758
        return true;
693
759
    }
697
763
    // Don't set new track as the current track to play since we're calling open_resource_for_uri above
698
764
    static const bool make_current = false;
699
765
    d->track_list->add_track_with_uri_at(uri, media::TrackList::after_empty_track(), make_current);
 
766
 
700
767
    return ret;
701
768
}
702
769
 
722
789
void media::PlayerImplementation<Parent>::play()
723
790
{
724
791
    MH_TRACE("");
 
792
    if (d->is_multimedia_role())
 
793
    {
 
794
        MH_DEBUG("==== Pausing all other multimedia player sessions");
 
795
        if (not d->pause_other_players(d->config.key))
 
796
            MH_WARNING("Failed to pause other player sessions");
 
797
 
 
798
        MH_DEBUG("==== Updating the current player");
 
799
        // This player will begin playing so make sure it's the current player. If
 
800
        // this operation fails it is not a fatal condition but should be logged
 
801
        if (not d->update_current_player(d->config.key))
 
802
            MH_WARNING("Failed to update current player");
 
803
    }
 
804
 
725
805
    d->engine->play();
726
806
}
727
807