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

Commit 1061c9c2 authored by Wei Jia's avatar Wei Jia
Browse files

mediaplayer: display one frame when seek is called before start.

Bug: 18608164
Change-Id: I83252421278aeeb1c1611138994bfdaf86d7a363
parent 2232aee2
Loading
Loading
Loading
Loading
+29 −6
Original line number Diff line number Diff line
@@ -1140,6 +1140,22 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
            ALOGV("kWhatSeek seekTimeUs=%lld us, needNotify=%d",
                    (long long)seekTimeUs, needNotify);

            if (!mStarted) {
                // Seek before the player is started. In order to preview video,
                // need to start the player and pause it. This branch is called
                // only once if needed. After the player is started, any seek
                // operation will go through normal path.
                // All cases, including audio-only, are handled in the same way
                // for the sake of simplicity.
                onStart(seekTimeUs);
                onPause();
                mPausedByClient = true;
                if (needNotify) {
                    notifyDriverSeekComplete();
                }
                break;
            }

            mDeferredActions.push_back(
                    new FlushDecoderAction(FLUSH_CMD_FLUSH /* audio */,
                                           FLUSH_CMD_FLUSH /* video */));
@@ -1233,13 +1249,16 @@ status_t NuPlayer::onInstantiateSecureDecoders() {
    return OK;
}

void NuPlayer::onStart() {
void NuPlayer::onStart(int64_t startPositionUs) {
    mOffloadAudio = false;
    mAudioEOS = false;
    mVideoEOS = false;
    mStarted = true;

    mSource->start();
    if (startPositionUs > 0) {
        performSeek(startPositionUs);
    }

    uint32_t flags = 0;

@@ -1895,6 +1914,11 @@ void NuPlayer::performResumeDecoders(bool needNotify) {
void NuPlayer::finishResume() {
    if (mResumePending) {
        mResumePending = false;
        notifyDriverSeekComplete();
    }
}

void NuPlayer::notifyDriverSeekComplete() {
    if (mDriver != NULL) {
        sp<NuPlayerDriver> driver = mDriver.promote();
        if (driver != NULL) {
@@ -1902,7 +1926,6 @@ void NuPlayer::finishResume() {
        }
    }
}
}

void NuPlayer::onSourceNotify(const sp<AMessage> &msg) {
    int32_t what;
+2 −1
Original line number Diff line number Diff line
@@ -233,7 +233,7 @@ private:
    void handleFlushComplete(bool audio, bool isDecoder);
    void finishFlushIfPossible();

    void onStart();
    void onStart(int64_t startPositionUs = -1);
    void onResume();
    void onPause();

@@ -242,6 +242,7 @@ private:
    void flushDecoder(bool audio, bool needShutdown);

    void finishResume();
    void notifyDriverSeekComplete();

    void postScanSources();

+2 −12
Original line number Diff line number Diff line
@@ -397,23 +397,13 @@ status_t NuPlayerDriver::seekTo(int msec) {
    switch (mState) {
        case STATE_PREPARED:
        case STATE_STOPPED_AND_PREPARED:
        {
        case STATE_PAUSED:
            mStartupSeekTimeUs = seekTimeUs;
            // pretend that the seek completed. It will actually happen when starting playback.
            // TODO: actually perform the seek here, so the player is ready to go at the new
            // location
            notifySeekComplete_l();
            break;
        }

            // fall through.
        case STATE_RUNNING:
        case STATE_PAUSED:
        {
            mAtEOS = false;
            mSeekInProgress = true;
            if (mState == STATE_PAUSED) {
               mStartupSeekTimeUs = seekTimeUs;
            }
            // seeks can take a while, so we essentially paused
            notifyListener_l(MEDIA_PAUSED);
            mPlayer->seekToAsync(seekTimeUs, true /* needNotify */);