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

Commit 0955986e authored by Roger Jönsson's avatar Roger Jönsson Committed by Andreas Huber
Browse files

Avoid rebuffering after RTSP pause

If pausing an RTSP stream, an RTSP Pause request is sent and then
if the stream is immediately resumed again, an RTSP Play request
will be sent to the server.
But the new data after the pause will not be buffered until
Sender Reports have arrived again on both channels.
Meanwhile the player will resume playback and continue consuming
the already existing buffer.
This means that there is a risk that the buffer is emptied while
waiting for sender reports.

This commit simply adds a delay before the RTSP pause request is
sent, allowing some additional RTSP buffering that might be needed
when the stream is resumed again.
Also, if the stream is resumed again before the RTSP pause request
is sent, there is no need for any RTSP pause request, hence it is
omitted.

Change-Id: I928c8bfb5e99a6a146dcda4e51e528973ecbe065
parent 1a37ee3c
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ static int64_t kStartupTimeoutUs = 10000000ll;

static int64_t kDefaultKeepAliveTimeoutUs = 60000000ll;

static int64_t kPauseDelayUs = 3000000ll;

namespace android {

static void MakeUserAgentString(AString *s) {
@@ -137,7 +139,8 @@ struct MyHandler : public AHandler {
          mSeekable(true),
          mKeepAliveTimeoutUs(kDefaultKeepAliveTimeoutUs),
          mKeepAliveGeneration(0),
          mPausing(false) {
          mPausing(false),
          mPauseGeneration(0) {
        mNetLooper->setName("rtsp net");
        mNetLooper->start(false /* runOnCallingThread */,
                          false /* canCallJava */,
@@ -215,6 +218,7 @@ struct MyHandler : public AHandler {
    void seek(int64_t timeUs) {
        sp<AMessage> msg = new AMessage('seek', id());
        msg->setInt64("time", timeUs);
        mPauseGeneration++;
        msg->post();
    }

@@ -224,11 +228,14 @@ struct MyHandler : public AHandler {

    void pause() {
        sp<AMessage> msg = new AMessage('paus', id());
        msg->post();
        mPauseGeneration++;
        msg->setInt32("pausecheck", mPauseGeneration);
        msg->post(kPauseDelayUs);
    }

    void resume() {
        sp<AMessage> msg = new AMessage('resu', id());
        mPauseGeneration++;
        msg->post();
    }

@@ -1024,6 +1031,13 @@ struct MyHandler : public AHandler {

            case 'paus':
            {
                int32_t generation;
                CHECK(msg->findInt32("pausecheck", &generation));
                if (generation != mPauseGeneration) {
                    ALOGV("Ignoring outdated pause message.");
                    break;
                }

                if (!mSeekable) {
                    ALOGW("This is a live stream, ignoring pause request.");
                    break;
@@ -1517,6 +1531,7 @@ private:
    int64_t mKeepAliveTimeoutUs;
    int32_t mKeepAliveGeneration;
    bool mPausing;
    int32_t mPauseGeneration;

    Vector<TrackInfo> mTracks;