Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6cb33759 authored by Haynes Mathew George's avatar Haynes Mathew George Committed by Wei Jia
Browse files

libmediaplayerservice:Fix deadlock on gapless start failure



Return error back to the application if start of next MediaPlayer
instance as part of gapless transition fails.
Test: compiles
authored-by: default avatarAshish Jain <ashishj@codeaurora.org>
Change-Id: I77c570074c7c98c996122e275161ba88298e56fc
(cherry picked from commit 9eadf496fa84603cf3ec5889990b79db8e378400)
parent d7ae0b85
Loading
Loading
Loading
Loading
+21 −4
Original line number Diff line number Diff line
@@ -1318,16 +1318,33 @@ void MediaPlayerService::Client::notify(
    }

    sp<IMediaPlayerClient> c;
    sp<Client> nextClient;
    status_t errStartNext = NO_ERROR;
    {
        Mutex::Autolock l(client->mLock);
        c = client->mClient;
        if (msg == MEDIA_PLAYBACK_COMPLETE && client->mNextClient != NULL) {
            nextClient = client->mNextClient;

            if (client->mAudioOutput != NULL)
                client->mAudioOutput->switchToNextOutput();
            client->mNextClient->start();
            if (client->mNextClient->mClient != NULL) {
                client->mNextClient->mClient->notify(
                        MEDIA_INFO, MEDIA_INFO_STARTED_AS_NEXT, 0, obj);

            errStartNext = nextClient->start();
        }
    }

    if (nextClient != NULL) {
        sp<IMediaPlayerClient> nc;
        {
            Mutex::Autolock l(nextClient->mLock);
            nc = nextClient->mClient;
        }
        if (nc != NULL) {
            if (errStartNext == NO_ERROR) {
                nc->notify(MEDIA_INFO, MEDIA_INFO_STARTED_AS_NEXT, 0, obj);
            } else {
                nc->notify(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN , 0, obj);
                ALOGE("gapless:start playback for next track failed, err(%d)", errStartNext);
            }
        }
    }