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

Commit 4cf0436f authored by Wei Jia's avatar Wei Jia Committed by Android (Google) Code Review
Browse files

Merge "RTSP: add timeout scheme to handle error cases." into nyc-dev

parents c51e05b6 f30460b8
Loading
Loading
Loading
Loading
+24 −7
Original line number Diff line number Diff line
@@ -64,6 +64,10 @@ static int64_t kDefaultKeepAliveTimeoutUs = 60000000ll;

static int64_t kPauseDelayUs = 3000000ll;

// The allowed maximum number of stale access units at the beginning of
// a new sequence.
static int32_t kMaxAllowedStaleAccessUnits = 20;

namespace android {

static bool GetAttribute(const char *s, const char *key, AString *value) {
@@ -1049,16 +1053,26 @@ struct MyHandler : public AHandler {
                }

                if (track->mNewSegment) {
                    // The sequence number from RTP packet has only 16 bits and is adjusted
                    // by the client. Only the low 16 bits of seq in RTP-Info of reply of
                    // RTSP "PLAY" command should be used to detect the first RTP patcket
                    // 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;
@@ -1516,6 +1530,7 @@ struct MyHandler : public AHandler {
            TrackInfo *info = &mTracks.editItemAt(trackIndex);
            info->mFirstSeqNumInSegment = seq;
            info->mNewSegment = true;
            info->mAllowedStaleAccessUnits = kMaxAllowedStaleAccessUnits;

            CHECK(GetAttribute((*it).c_str(), "rtptime", &val));

@@ -1559,6 +1574,7 @@ private:
        bool mUsingInterleavedTCP;
        uint32_t mFirstSeqNumInSegment;
        bool mNewSegment;
        int32_t mAllowedStaleAccessUnits;

        uint32_t mRTPAnchor;
        int64_t mNTPAnchorUs;
@@ -1642,6 +1658,7 @@ private:
        info->mUsingInterleavedTCP = false;
        info->mFirstSeqNumInSegment = 0;
        info->mNewSegment = true;
        info->mAllowedStaleAccessUnits = kMaxAllowedStaleAccessUnits;
        info->mRTPSocket = -1;
        info->mRTCPSocket = -1;
        info->mRTPAnchor = 0;