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

Commit 42c5ae81 authored by Marco Nelissen's avatar Marco Nelissen
Browse files

Prevent onPrepared callback from being called twice

b/10891995

Change-Id: If6845c832d114629282f0b03f904a37c3325208e
parent 6914de6d
Loading
Loading
Loading
Loading
+19 −17
Original line number Diff line number Diff line
@@ -259,6 +259,7 @@ void AwesomePlayer::cancelPlayerEvents(bool keepNotifications) {

        mQueue.cancelEvent(mBufferingEvent->eventID());
        mBufferingEventPending = false;
        mAudioTearDown = false;
    }
}

@@ -2301,6 +2302,7 @@ void AwesomePlayer::abortPrepare(status_t err) {
    modifyFlags((PREPARING|PREPARE_CANCELLED|PREPARING_CONNECTED), CLEAR);
    mAsyncPrepareEvent = NULL;
    mPreparedCondition.broadcast();
    mAudioTearDown = false;
}

// static
@@ -2374,6 +2376,20 @@ void AwesomePlayer::finishAsyncPrepare_l() {
    modifyFlags(PREPARED, SET);
    mAsyncPrepareEvent = NULL;
    mPreparedCondition.broadcast();

    if (mAudioTearDown) {
        if (mPrepareResult == OK) {
            if (mExtractorFlags & MediaExtractor::CAN_SEEK) {
                seekTo_l(mAudioTearDownPosition);
            }

            if (mAudioTearDownWasPlaying) {
                modifyFlags(CACHE_UNDERRUN, CLEAR);
                play_l();
            }
        }
        mAudioTearDown = false;
    }
}

uint32_t AwesomePlayer::flags() const {
@@ -2791,7 +2807,7 @@ void AwesomePlayer::onAudioTearDownEvent() {
    ALOGV("onAudioTearDownEvent");

    // stream info is cleared by reset_l() so copy what we need
    const bool wasPlaying = (mFlags & PLAYING);
    mAudioTearDownWasPlaying = (mFlags & PLAYING);
    KeyedVector<String8, String8> uriHeaders(mUriHeaders);
    sp<DataSource> fileSource(mFileSource);

@@ -2800,8 +2816,7 @@ void AwesomePlayer::onAudioTearDownEvent() {
    mStatsLock.unlock();

    // get current position so we can start recreated stream from here
    int64_t position = 0;
    getPosition(&position);
    getPosition(&mAudioTearDownPosition);

    // Reset and recreate
    reset_l();
@@ -2825,21 +2840,8 @@ void AwesomePlayer::onAudioTearDownEvent() {
    mAudioTearDown = true;
    mIsAsyncPrepare = true;

    // Call parepare for the host decoding
    // Call prepare for the host decoding
    beginPrepareAsync_l();

    if (mPrepareResult == OK) {
        if (mExtractorFlags & MediaExtractor::CAN_SEEK) {
            seekTo_l(position);
        }

        if (wasPlaying) {
            modifyFlags(CACHE_UNDERRUN, CLEAR);
            play_l();
        }
    }

    mAudioTearDown = false;
}

}  // namespace android
+2 −0
Original line number Diff line number Diff line
@@ -342,6 +342,8 @@ private:

    bool    mOffloadAudio;
    bool    mAudioTearDown;
    bool    mAudioTearDownWasPlaying;
    int64_t mAudioTearDownPosition;

    status_t setVideoScalingMode(int32_t mode);
    status_t setVideoScalingMode_l(int32_t mode);