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

Commit 21902a8a authored by Andreas Huber's avatar Andreas Huber
Browse files

Don't perform RTSP seeks right away but queue them for 200ms

and only execute the last one.

Change-Id: I9ab342396ec9c9c03624a4b0306d1e180ceca000
related-to-bug: 5732960
parent a693a4b5
Loading
Loading
Loading
Loading
+26 −4
Original line number Original line Diff line number Diff line
@@ -38,7 +38,8 @@ NuPlayer::RTSPSource::RTSPSource(
      mFlags(0),
      mFlags(0),
      mState(DISCONNECTED),
      mState(DISCONNECTED),
      mFinalResult(OK),
      mFinalResult(OK),
      mDisconnectReplyID(0) {
      mDisconnectReplyID(0),
      mSeekGeneration(0) {
    if (headers) {
    if (headers) {
        mExtraHeaders = *headers;
        mExtraHeaders = *headers;


@@ -146,14 +147,21 @@ status_t NuPlayer::RTSPSource::getDuration(int64_t *durationUs) {
}
}


status_t NuPlayer::RTSPSource::seekTo(int64_t seekTimeUs) {
status_t NuPlayer::RTSPSource::seekTo(int64_t seekTimeUs) {
    sp<AMessage> msg = new AMessage(kWhatPerformSeek, mReflector->id());
    msg->setInt32("generation", ++mSeekGeneration);
    msg->setInt64("timeUs", seekTimeUs);
    msg->post(200000ll);

    return OK;
}

void NuPlayer::RTSPSource::performSeek(int64_t seekTimeUs) {
    if (mState != CONNECTED) {
    if (mState != CONNECTED) {
        return UNKNOWN_ERROR;
        return;
    }
    }


    mState = SEEKING;
    mState = SEEKING;
    mHandler->seek(seekTimeUs);
    mHandler->seek(seekTimeUs);

    return OK;
}
}


bool NuPlayer::RTSPSource::isSeekable() {
bool NuPlayer::RTSPSource::isSeekable() {
@@ -168,6 +176,20 @@ void NuPlayer::RTSPSource::onMessageReceived(const sp<AMessage> &msg) {
        mDisconnectReplyID = replyID;
        mDisconnectReplyID = replyID;
        finishDisconnectIfPossible();
        finishDisconnectIfPossible();
        return;
        return;
    } else if (msg->what() == kWhatPerformSeek) {
        int32_t generation;
        CHECK(msg->findInt32("generation", &generation));

        if (generation != mSeekGeneration) {
            // obsolete.
            return;
        }

        int64_t seekTimeUs;
        CHECK(msg->findInt64("timeUs", &seekTimeUs));

        performSeek(seekTimeUs);
        return;
    }
    }


    CHECK_EQ(msg->what(), (int)kWhatNotify);
    CHECK_EQ(msg->what(), (int)kWhatNotify);
+5 −0
Original line number Original line Diff line number Diff line
@@ -56,6 +56,7 @@ private:
    enum {
    enum {
        kWhatNotify          = 'noti',
        kWhatNotify          = 'noti',
        kWhatDisconnect      = 'disc',
        kWhatDisconnect      = 'disc',
        kWhatPerformSeek     = 'seek',
    };
    };


    enum State {
    enum State {
@@ -95,12 +96,16 @@ private:
    sp<AnotherPacketSource> mAudioTrack;
    sp<AnotherPacketSource> mAudioTrack;
    sp<AnotherPacketSource> mVideoTrack;
    sp<AnotherPacketSource> mVideoTrack;


    int32_t mSeekGeneration;

    sp<AnotherPacketSource> getSource(bool audio);
    sp<AnotherPacketSource> getSource(bool audio);


    void onConnected();
    void onConnected();
    void onDisconnected(const sp<AMessage> &msg);
    void onDisconnected(const sp<AMessage> &msg);
    void finishDisconnectIfPossible();
    void finishDisconnectIfPossible();


    void performSeek(int64_t seekTimeUs);

    DISALLOW_EVIL_CONSTRUCTORS(RTSPSource);
    DISALLOW_EVIL_CONSTRUCTORS(RTSPSource);
};
};