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

Commit fc3e047b authored by Robert Shih's avatar Robert Shih Committed by android-build-merger
Browse files

Merge \"rtsp: check seq # after play response is parsed\" into nyc-mr1-dev

am: 43c913b6

Change-Id: I02f32ec88669af26291cc048fc4a4a87b4458cb4
parents c33ece57 43c913b6
Loading
Loading
Loading
Loading
+40 −42
Original line number Diff line number Diff line
@@ -1042,49 +1042,13 @@ struct MyHandler : public AHandler {
                    return;
                }

                sp<ABuffer> accessUnit;
                CHECK(msg->findBuffer("access-unit", &accessUnit));

                uint32_t seqNum = (uint32_t)accessUnit->int32Data();

                if (mSeekPending) {
                    ALOGV("we're seeking, dropping stale packet.");
                    break;
                }

                if (track->mNewSegment) {
                    // The sequence number from RTP packet has only 16 bits and is extended
                    // by ARTPSource. Only the low 16 bits of seq in RTP-Info of reply of
                    // RTSP "PLAY" command should be used to detect the first RTP packet
                    // after seeking.
                    if (track->mAllowedStaleAccessUnits > 0) {
                        if ((((seqNum ^ track->mFirstSeqNumInSegment) & 0xffff) != 0)) {
                            // Not the first rtp packet of the stream after seeking, discarding.
                            track->mAllowedStaleAccessUnits--;
                            ALOGV("discarding stale access unit (0x%x : 0x%x)",
                                 seqNum, track->mFirstSeqNumInSegment);
                            break;
                        }
                    } else { // track->mAllowedStaleAccessUnits <= 0
                        mNumAccessUnitsReceived = 0;
                        ALOGW_IF(track->mAllowedStaleAccessUnits == 0,
                             "Still no first rtp packet after %d stale ones",
                             kMaxAllowedStaleAccessUnits);
                        track->mAllowedStaleAccessUnits = -1;
                        break;
                    }

                    // Now found the first rtp packet of the stream after seeking.
                    track->mFirstSeqNumInSegment = seqNum;
                    track->mNewSegment = false;
                }

                if (seqNum < track->mFirstSeqNumInSegment) {
                    ALOGV("dropping stale access-unit (%d < %d)",
                         seqNum, track->mFirstSeqNumInSegment);
                    break;
                }

                sp<ABuffer> accessUnit;
                CHECK(msg->findBuffer("access-unit", &accessUnit));
                onAccessUnitComplete(trackIndex, accessUnit);
                break;
            }
@@ -1852,17 +1816,16 @@ private:
            int32_t trackIndex, const sp<ABuffer> &accessUnit) {
        ALOGV("onAccessUnitComplete track %d", trackIndex);

        if(!mPlayResponseParsed){
            ALOGI("play response is not parsed, storing accessunit");
        TrackInfo *track = &mTracks.editItemAt(trackIndex);
        if(!mPlayResponseParsed){
            uint32_t seqNum = (uint32_t)accessUnit->int32Data();
            ALOGI("play response is not parsed, storing accessunit %u", seqNum);
            track->mPackets.push_back(accessUnit);
            return;
        }

        handleFirstAccessUnit();

        TrackInfo *track = &mTracks.editItemAt(trackIndex);

        if (!mAllTracksHaveTime) {
            ALOGV("storing accessUnit, no time established yet");
            track->mPackets.push_back(accessUnit);
@@ -1873,6 +1836,41 @@ private:
            sp<ABuffer> accessUnit = *track->mPackets.begin();
            track->mPackets.erase(track->mPackets.begin());

            uint32_t seqNum = (uint32_t)accessUnit->int32Data();
            if (track->mNewSegment) {
                // The sequence number from RTP packet has only 16 bits and is extended
                // by ARTPSource. Only the low 16 bits of seq in RTP-Info of reply of
                // RTSP "PLAY" command should be used to detect the first RTP packet
                // after seeking.
                if (track->mAllowedStaleAccessUnits > 0) {
                    if ((((seqNum ^ track->mFirstSeqNumInSegment) & 0xffff) != 0)) {
                        // Not the first rtp packet of the stream after seeking, discarding.
                        track->mAllowedStaleAccessUnits--;
                        ALOGV("discarding stale access unit (0x%x : 0x%x)",
                             seqNum, track->mFirstSeqNumInSegment);
                        continue;
                    }
                } else { // track->mAllowedStaleAccessUnits <= 0
                    mNumAccessUnitsReceived = 0;
                    ALOGW_IF(track->mAllowedStaleAccessUnits == 0,
                         "Still no first rtp packet after %d stale ones",
                         kMaxAllowedStaleAccessUnits);
                    track->mAllowedStaleAccessUnits = -1;
                    return;
                }

                // Now found the first rtp packet of the stream after seeking.
                track->mFirstSeqNumInSegment = seqNum;
                track->mNewSegment = false;
            }

            if (seqNum < track->mFirstSeqNumInSegment) {
                ALOGV("dropping stale access-unit (%d < %d)",
                     seqNum, track->mFirstSeqNumInSegment);
                continue;
            }


            if (addMediaTimestamp(trackIndex, track, accessUnit)) {
                postQueueAccessUnit(trackIndex, accessUnit);
            }