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

Commit bb6bc849 authored by Insun Kang's avatar Insun Kang
Browse files

Adds resume() function

o Revived resume() function to fix pause/resume bug. (Bug: 6663740)
o Mannually cherry-picked from GTV change.
(commit: ad1197226d1c6745959f0e469f510ca06f99489f)

Change-Id: I77ac90085fb1f1d2e7eb706642978a4fa4d28b49
parent 2f0632f1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ public:

    status_t start();
    status_t pause();
    status_t resume();
    status_t selectTrack(size_t index);
    status_t unselectTrack(size_t index);

+23 −6
Original line number Diff line number Diff line
@@ -76,12 +76,12 @@ status_t TimedTextDriver::start() {
            return OK;
        case PAUSED:
            mPlayer->start();
            break;
            mState = PLAYING;
            return OK;
        default:
            TRESPASS();
    }
    mState = PLAYING;
    return OK;
    return UNKNOWN_ERROR;
}

// TODO: Test if pause() works properly.
@@ -95,14 +95,31 @@ status_t TimedTextDriver::pause() {
            return INVALID_OPERATION;
        case PLAYING:
            mPlayer->pause();
            break;
            mState = PAUSED;
            return OK;
        case PAUSED:
            return OK;
        default:
            TRESPASS();
    }
    mState = PAUSED;
    return UNKNOWN_ERROR;
}

status_t TimedTextDriver::resume() {
    Mutex::Autolock autoLock(mLock);
    switch (mState) {
        case UNINITIALIZED:
            return INVALID_OPERATION;
        case PLAYING:
            return OK;
        case PAUSED:
            mPlayer->resume();
            mState = PLAYING;
            return OK;
        default:
            TRESPASS();
    }
    return UNKNOWN_ERROR;
}

status_t TimedTextDriver::selectTrack(size_t index) {
+26 −7
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ TimedTextPlayer::~TimedTextPlayer() {

void TimedTextPlayer::start() {
    sp<AMessage> msg = new AMessage(kWhatSeek, id());
    msg->setInt64("seekTimeUs", -1);
    msg->setInt64("seekTimeUs", kInvalidTimeUs);
    msg->post();
}

@@ -62,6 +62,10 @@ void TimedTextPlayer::pause() {
    (new AMessage(kWhatPause, id()))->post();
}

void TimedTextPlayer::resume() {
    (new AMessage(kWhatResume, id()))->post();
}

void TimedTextPlayer::seekToAsync(int64_t timeUs) {
    sp<AMessage> msg = new AMessage(kWhatSeek, id());
    msg->setInt64("seekTimeUs", timeUs);
@@ -80,7 +84,17 @@ void TimedTextPlayer::onMessageReceived(const sp<AMessage> &msg) {
            mSendSubtitleGeneration++;
            break;
        }
        case kWhatResume: {
            doRead();
            break;
        }
        case kWhatRetryRead: {
            int32_t generation = -1;
            CHECK(msg->findInt32("generation", &generation));
            if (generation != mSendSubtitleGeneration) {
                // Drop obsolete msg.
                break;
            }
            int64_t seekTimeUs;
            int seekMode;
            if (msg->findInt64("seekTimeUs", &seekTimeUs) &&
@@ -96,9 +110,12 @@ void TimedTextPlayer::onMessageReceived(const sp<AMessage> &msg) {
            break;
        }
        case kWhatSeek: {
            int64_t seekTimeUs = 0;
            mSendSubtitleGeneration++;
            int64_t seekTimeUs = kInvalidTimeUs;
            // Clear a displayed timed text before seeking.
            notifyListener();
            msg->findInt64("seekTimeUs", &seekTimeUs);
            if (seekTimeUs < 0) {
            if (seekTimeUs == kInvalidTimeUs) {
                sp<MediaPlayerBase> listener = mListener.promote();
                if (listener != NULL) {
                    int32_t positionMs = 0;
@@ -178,12 +195,14 @@ void TimedTextPlayer::doRead(MediaSource::ReadOptions* options) {
    if (err == WOULD_BLOCK) {
        sp<AMessage> msg = new AMessage(kWhatRetryRead, id());
        if (options != NULL) {
            int64_t seekTimeUs;
            MediaSource::ReadOptions::SeekMode seekMode;
            int64_t seekTimeUs = kInvalidTimeUs;
            MediaSource::ReadOptions::SeekMode seekMode =
                MediaSource::ReadOptions::SEEK_PREVIOUS_SYNC;
            CHECK(options->getSeekTo(&seekTimeUs, &seekMode));
            msg->setInt64("seekTimeUs", seekTimeUs);
            msg->setInt32("seekMode", seekMode);
        }
        msg->setInt32("generation", mSendSubtitleGeneration);
        msg->post(kWaitTimeUsToRetryRead);
        return;
    } else if (err != OK) {
+2 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ public:

    void start();
    void pause();
    void resume();
    void seekToAsync(int64_t timeUs);
    void setDataSource(sp<TimedTextSource> source);

@@ -50,6 +51,7 @@ private:
    enum {
        kWhatPause = 'paus',
        kWhatSeek = 'seek',
        kWhatResume = 'resm',
        kWhatRetryRead = 'read',
        kWhatSendSubtitle = 'send',
        kWhatSetSource = 'ssrc',