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

Commit f6454e6d authored by Robert Shih's avatar Robert Shih Committed by Android (Google) Code Review
Browse files

Merge "LiveSession: re-buffer on under run to avoid stutter" into lmp-dev

parents 61cd63a5 f69c9968
Loading
Loading
Loading
Loading
+35 −1
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ LiveSession::LiveSession(
        mDiscontinuities.add(indexToType(i), new AnotherPacketSource(NULL /* meta */));
        mPacketSources.add(indexToType(i), new AnotherPacketSource(NULL /* meta */));
        mPacketSources2.add(indexToType(i), new AnotherPacketSource(NULL /* meta */));
        mBuffering[i] = false;
    }
}

@@ -133,8 +134,26 @@ status_t LiveSession::dequeueAccessUnit(

    sp<AnotherPacketSource> packetSource = mPacketSources.valueFor(stream);

    ssize_t idx = typeToIndex(stream);
    if (!packetSource->hasBufferAvailable(&finalResult)) {
        return finalResult == OK ? -EAGAIN : finalResult;
        if (finalResult == OK) {
            mBuffering[idx] = true;
            return -EAGAIN;
        } else {
            return finalResult;
        }
    }

    if (mBuffering[idx]) {
        if (mSwitchInProgress
                || packetSource->isFinished(0)
                || packetSource->getEstimatedDurationUs() > 10000000ll) {
            mBuffering[idx] = false;
        }
    }

    if (mBuffering[idx]) {
        return -EAGAIN;
    }

    // wait for counterpart
@@ -567,6 +586,21 @@ LiveSession::StreamType LiveSession::indexToType(int idx) {
    return (StreamType)(1 << idx);
}

// static
ssize_t LiveSession::typeToIndex(int32_t type) {
    switch (type) {
        case STREAMTYPE_AUDIO:
            return 0;
        case STREAMTYPE_VIDEO:
            return 1;
        case STREAMTYPE_SUBTITLES:
            return 2;
        default:
            return -1;
    };
    return -1;
}

void LiveSession::onConnect(const sp<AMessage> &msg) {
    AString url;
    CHECK(msg->findString("url", &url));
+2 −0
Original line number Diff line number Diff line
@@ -153,6 +153,7 @@ private:
    sp<IMediaHTTPService> mHTTPService;

    bool mInPreparationPhase;
    bool mBuffering[kMaxStreams];

    sp<HTTPBase> mHTTPDataSource;
    KeyedVector<String8, String8> mExtraHeaders;
@@ -242,6 +243,7 @@ private:

    static int SortByBandwidth(const BandwidthItem *, const BandwidthItem *);
    static StreamType indexToType(int idx);
    static ssize_t typeToIndex(int32_t type);

    void changeConfiguration(
            int64_t timeUs, size_t bandwidthIndex, bool pickTrack = false);