diff options
author | Andreas Huber <andih@google.com> | 2010-08-31 10:43:47 -0700 |
---|---|---|
committer | Andreas Huber <andih@google.com> | 2010-08-31 11:13:51 -0700 |
commit | e7d3e90d8761f52a6acfdcd926f0392aca8ebb52 (patch) | |
tree | fe646be124e6f91f7b5106f06616e7f56e0c99ac | |
parent | 5edae619a6ad7337a3d14b53f7665ff17ec3ee84 (diff) | |
download | frameworks_av-e7d3e90d8761f52a6acfdcd926f0392aca8ebb52.zip frameworks_av-e7d3e90d8761f52a6acfdcd926f0392aca8ebb52.tar.gz frameworks_av-e7d3e90d8761f52a6acfdcd926f0392aca8ebb52.tar.bz2 |
Better detection of connection problems - timeout if no rtcp packets arrive within a certain time, not a final frame (which may take longer)
Change-Id: I3c1ae79bb9342770e959ebdcdc6b748549b76330
related-to-bug: 2556656
-rw-r--r-- | media/libstagefright/rtsp/ARTPConnection.cpp | 8 | ||||
-rw-r--r-- | media/libstagefright/rtsp/MyHandler.h | 102 |
2 files changed, 67 insertions, 43 deletions
diff --git a/media/libstagefright/rtsp/ARTPConnection.cpp b/media/libstagefright/rtsp/ARTPConnection.cpp index 12f8f32..10c9e02 100644 --- a/media/libstagefright/rtsp/ARTPConnection.cpp +++ b/media/libstagefright/rtsp/ARTPConnection.cpp @@ -362,7 +362,6 @@ status_t ARTPConnection::receive(StreamInfo *s, bool receiveRTP) { if (receiveRTP) { err = parseRTP(s, buffer); } else { - ++s->mNumRTCPPacketsReceived; err = parseRTCP(s, buffer); } @@ -456,6 +455,12 @@ status_t ARTPConnection::parseRTP(StreamInfo *s, const sp<ABuffer> &buffer) { } status_t ARTPConnection::parseRTCP(StreamInfo *s, const sp<ABuffer> &buffer) { + if (s->mNumRTCPPacketsReceived++ == 0) { + sp<AMessage> notify = s->mNotifyMsg->dup(); + notify->setInt32("first-rtcp", true); + notify->post(); + } + const uint8_t *data = buffer->data(); size_t size = buffer->size(); @@ -626,7 +631,6 @@ void ARTPConnection::onInjectPacket(const sp<AMessage> &msg) { if (it->mRTPSocket == index) { err = parseRTP(s, buffer); } else { - ++s->mNumRTCPPacketsReceived; err = parseRTCP(s, buffer); } } diff --git a/media/libstagefright/rtsp/MyHandler.h b/media/libstagefright/rtsp/MyHandler.h index ee6f65a..b849117 100644 --- a/media/libstagefright/rtsp/MyHandler.h +++ b/media/libstagefright/rtsp/MyHandler.h @@ -82,7 +82,8 @@ struct MyHandler : public AHandler { mFirstAccessUnitNTP(0), mNumAccessUnitsReceived(0), mCheckPending(false), - mTryTCPInterleaving(false) { + mTryTCPInterleaving(false), + mReceivedFirstRTCPPacket(false) { mNetLooper->setName("rtsp net"); mNetLooper->start(false /* runOnCallingThread */, false /* canCallJava */, @@ -199,31 +200,35 @@ struct MyHandler : public AHandler { break; } - CHECK_EQ(response->mStatusCode, 200u); - - mSessionDesc = new ASessionDescription; + if (response->mStatusCode != 200) { + result = UNKNOWN_ERROR; + } else { + mSessionDesc = new ASessionDescription; - mSessionDesc->setTo( - response->mContent->data(), - response->mContent->size()); + mSessionDesc->setTo( + response->mContent->data(), + response->mContent->size()); - CHECK(mSessionDesc->isValid()); + CHECK(mSessionDesc->isValid()); - ssize_t i = response->mHeaders.indexOfKey("content-base"); - if (i >= 0) { - mBaseURL = response->mHeaders.valueAt(i); - } else { - i = response->mHeaders.indexOfKey("content-location"); + ssize_t i = response->mHeaders.indexOfKey("content-base"); if (i >= 0) { mBaseURL = response->mHeaders.valueAt(i); } else { - mBaseURL = mSessionURL; + i = response->mHeaders.indexOfKey("content-location"); + if (i >= 0) { + mBaseURL = response->mHeaders.valueAt(i); + } else { + mBaseURL = mSessionURL; + } } + + CHECK_GT(mSessionDesc->countTracks(), 1u); + setupTrack(1); } + } - CHECK_GT(mSessionDesc->countTracks(), 1u); - setupTrack(1); - } else { + if (result != OK) { sp<AMessage> reply = new AMessage('disc', id()); mConn->disconnect(reply); } @@ -247,16 +252,7 @@ struct MyHandler : public AHandler { LOG(INFO) << "SETUP(" << index << ") completed with result " << result << " (" << strerror(-result) << ")"; - if (result != OK) { - if (track) { - if (!track->mUsingInterleavedTCP) { - close(track->mRTPSocket); - close(track->mRTCPSocket); - } - - mTracks.removeItemsAt(trackIndex); - } - } else { + if (result == OK) { CHECK(track != NULL); sp<RefBase> obj; @@ -264,29 +260,40 @@ struct MyHandler : public AHandler { sp<ARTSPResponse> response = static_cast<ARTSPResponse *>(obj.get()); - CHECK_EQ(response->mStatusCode, 200u); - - ssize_t i = response->mHeaders.indexOfKey("session"); - CHECK_GE(i, 0); + if (response->mStatusCode != 200) { + result = UNKNOWN_ERROR; + } else { + ssize_t i = response->mHeaders.indexOfKey("session"); + CHECK_GE(i, 0); - if (index == 1) { mSessionID = response->mHeaders.valueAt(i); i = mSessionID.find(";"); if (i >= 0) { // Remove options, i.e. ";timeout=90" mSessionID.erase(i, mSessionID.size() - i); } - } - sp<AMessage> notify = new AMessage('accu', id()); - notify->setSize("track-index", trackIndex); + sp<AMessage> notify = new AMessage('accu', id()); + notify->setSize("track-index", trackIndex); - mRTPConn->addStream( - track->mRTPSocket, track->mRTCPSocket, - mSessionDesc, index, - notify, track->mUsingInterleavedTCP); + mRTPConn->addStream( + track->mRTPSocket, track->mRTCPSocket, + mSessionDesc, index, + notify, track->mUsingInterleavedTCP); - mSetupTracksSuccessful = true; + mSetupTracksSuccessful = true; + } + } + + if (result != OK) { + if (track) { + if (!track->mUsingInterleavedTCP) { + close(track->mRTPSocket); + close(track->mRTCPSocket); + } + + mTracks.removeItemsAt(trackIndex); + } } ++index; @@ -355,6 +362,12 @@ struct MyHandler : public AHandler { } } mTracks.clear(); + mSetupTracksSuccessful = false; + mSeekPending = false; + mFirstAccessUnit = true; + mFirstAccessUnitNTP = 0; + mNumAccessUnitsReceived = 0; + mReceivedFirstRTCPPacket = false; sp<AMessage> reply = new AMessage('tear', id()); @@ -424,6 +437,12 @@ struct MyHandler : public AHandler { case 'accu': { + int32_t firstRTCP; + if (msg->findInt32("first-rtcp", &firstRTCP)) { + mReceivedFirstRTCPPacket = true; + break; + } + ++mNumAccessUnitsReceived; if (!mCheckPending) { @@ -612,7 +631,7 @@ struct MyHandler : public AHandler { case 'tiou': { - if (mFirstAccessUnit) { + if (!mReceivedFirstRTCPPacket) { if (mTryTCPInterleaving) { LOG(WARNING) << "Never received any data, disconnecting."; (new AMessage('abor', id()))->post(); @@ -747,6 +766,7 @@ private: int64_t mNumAccessUnitsReceived; bool mCheckPending; bool mTryTCPInterleaving; + bool mReceivedFirstRTCPPacket; struct TrackInfo { AString mURL; |