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

Commit ea8c9b1b authored by Andreas Huber's avatar Andreas Huber
Browse files

Discontinuities are only signalled on streams that have been identified, i.e.

those that have a queue. This ensures that the player doesn't observe discontinuities
that don't match up across streams.

Also, make sure output buffers arriving from the decoder to be rendered are sent
back to the decoder if we started flushing.

Finally, don't parse TS packets for streams we don't support. And don't allocate
memory for them.

Change-Id: I708e0de4cba8110a62e4c8ceb1e5702430d5d2bb
parent 49fb943d
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -663,6 +663,19 @@ void NuPlayer::renderBuffer(bool audio, const sp<AMessage> &msg) {
    sp<AMessage> reply;
    CHECK(msg->findMessage("reply", &reply));

    if (IsFlushingState(audio ? mFlushingAudio : mFlushingVideo)) {
        // We're currently attempting to flush the decoder, in order
        // to complete this, the decoder wants all its buffers back,
        // so we don't want any output buffers it sent us (from before
        // we initiated the flush) to be stuck in the renderer's queue.

        LOGV("we're still flushing the %s decoder, sending its output buffer"
             " right back.", audio ? "audio" : "video");

        reply->post();
        return;
    }

    sp<RefBase> obj;
    CHECK(msg->findObject("buffer", &obj));

+13 −32
Original line number Diff line number Diff line
@@ -111,8 +111,6 @@ private:
    sp<ABuffer> mBuffer;
    sp<AnotherPacketSource> mSource;
    bool mPayloadStarted;
    DiscontinuityType mPendingDiscontinuity;
    sp<AMessage> mPendingDiscontinuityExtra;

    ElementaryStreamQueue *mQueue;

@@ -125,9 +123,6 @@ private:

    void extractAACFrames(const sp<ABuffer> &buffer);

    void deferDiscontinuity(
            DiscontinuityType type, const sp<AMessage> &extra);

    DISALLOW_EVIL_CONSTRUCTORS(Stream);
};

@@ -347,12 +342,8 @@ ATSParser::Stream::Stream(
    : mProgram(program),
      mElementaryPID(elementaryPID),
      mStreamType(streamType),
      mBuffer(new ABuffer(192 * 1024)),
      mPayloadStarted(false),
      mPendingDiscontinuity(DISCONTINUITY_NONE),
      mQueue(NULL) {
    mBuffer->setRange(0, 0);

    switch (mStreamType) {
        case STREAMTYPE_H264:
            mQueue = new ElementaryStreamQueue(ElementaryStreamQueue::H264);
@@ -382,6 +373,11 @@ ATSParser::Stream::Stream(
    }

    LOGV("new stream PID 0x%02x, type 0x%02x", elementaryPID, streamType);

    if (mQueue != NULL) {
        mBuffer = new ABuffer(192 * 1024);
        mBuffer->setRange(0, 0);
    }
}

ATSParser::Stream::~Stream() {
@@ -391,6 +387,10 @@ ATSParser::Stream::~Stream() {

void ATSParser::Stream::parse(
        unsigned payload_unit_start_indicator, ABitReader *br) {
    if (mQueue == NULL) {
        return;
    }

    if (payload_unit_start_indicator) {
        if (mPayloadStarted) {
            // Otherwise we run the danger of receiving the trailing bytes
@@ -429,6 +429,10 @@ void ATSParser::Stream::parse(

void ATSParser::Stream::signalDiscontinuity(
        DiscontinuityType type, const sp<AMessage> &extra) {
    if (mQueue == NULL) {
        return;
    }

    mPayloadStarted = false;
    mBuffer->setRange(0, 0);

@@ -453,8 +457,6 @@ void ATSParser::Stream::signalDiscontinuity(

            if (mSource != NULL) {
                mSource->queueDiscontinuity(type, extra);
            } else {
                deferDiscontinuity(type, extra);
            }
            break;
        }
@@ -465,15 +467,6 @@ void ATSParser::Stream::signalDiscontinuity(
    }
}

void ATSParser::Stream::deferDiscontinuity(
        DiscontinuityType type, const sp<AMessage> &extra) {
    if (type > mPendingDiscontinuity) {
        // Only upgrade discontinuities.
        mPendingDiscontinuity = type;
        mPendingDiscontinuityExtra = extra;
    }
}

void ATSParser::Stream::signalEOS(status_t finalResult) {
    if (mSource != NULL) {
        mSource->signalEOS(finalResult);
@@ -658,10 +651,6 @@ void ATSParser::Stream::onPayloadData(
        const uint8_t *data, size_t size) {
    LOGV("onPayloadData mStreamType=0x%02x", mStreamType);

    if (mQueue == NULL) {
        return;
    }

    CHECK(PTS_DTS_flags == 2 || PTS_DTS_flags == 3);
    int64_t timeUs = mProgram->convertPTSToTimestamp(PTS);

@@ -681,14 +670,6 @@ void ATSParser::Stream::onPayloadData(
                     mElementaryPID, mStreamType);

                mSource = new AnotherPacketSource(meta);

                if (mPendingDiscontinuity != DISCONTINUITY_NONE) {
                    mSource->queueDiscontinuity(
                            mPendingDiscontinuity, mPendingDiscontinuityExtra);
                    mPendingDiscontinuity = DISCONTINUITY_NONE;
                    mPendingDiscontinuityExtra.clear();
                }

                mSource->queueAccessUnit(accessUnit);
            }
        } else if (mQueue->getFormat() != NULL) {