diff options
Diffstat (limited to 'media/libstagefright/rtsp/MyHandler.h')
-rw-r--r-- | media/libstagefright/rtsp/MyHandler.h | 71 |
1 files changed, 62 insertions, 9 deletions
diff --git a/media/libstagefright/rtsp/MyHandler.h b/media/libstagefright/rtsp/MyHandler.h index 0d0baf3..70063b1 100644 --- a/media/libstagefright/rtsp/MyHandler.h +++ b/media/libstagefright/rtsp/MyHandler.h @@ -18,7 +18,9 @@ #define MY_HANDLER_H_ +#ifndef LOG_NDEBUG //#define LOG_NDEBUG 0 +#endif #ifndef LOG_TAG #define LOG_TAG "MyHandler" @@ -32,6 +34,7 @@ #include "ASessionDescription.h" #include <ctype.h> +#include <cutils/properties.h> #include <media/stagefright/foundation/ABuffer.h> #include <media/stagefright/foundation/ADebug.h> @@ -39,6 +42,7 @@ #include <media/stagefright/foundation/AMessage.h> #include <media/stagefright/MediaErrors.h> #include <media/stagefright/Utils.h> +#include <mediaplayerservice/AVMediaServiceExtensions.h> #include <arpa/inet.h> #include <sys/socket.h> @@ -64,6 +68,8 @@ static int64_t kDefaultKeepAliveTimeoutUs = 60000000ll; static int64_t kPauseDelayUs = 3000000ll; +static int64_t kTearDownTimeoutUs = 3000000ll; + namespace android { static bool GetAttribute(const char *s, const char *key, AString *value) { @@ -105,6 +111,8 @@ struct MyHandler : public AHandler { kWhatEOS = 'eos!', kWhatSeekDiscontinuity = 'seeD', kWhatNormalPlayTimeMapping = 'nptM', + kWhatCancelCheck = 'canC', + kWhatByeReceived = 'byeR', }; MyHandler( @@ -115,8 +123,6 @@ struct MyHandler : public AHandler { mUIDValid(uidValid), mUID(uid), mNetLooper(new ALooper), - mConn(new ARTSPConnection(mUIDValid, mUID)), - mRTPConn(new ARTPConnection), mOriginalSessionURL(url), mSessionURL(url), mSetupTracksSuccessful(false), @@ -140,11 +146,22 @@ struct MyHandler : public AHandler { mPausing(false), mPauseGeneration(0), mPlayResponseParsed(false) { + mConn = AVMediaServiceFactory::get()->createARTSPConnection( + mUIDValid, uid); + mRTPConn = AVMediaServiceFactory::get()->createARTPConnection(); mNetLooper->setName("rtsp net"); mNetLooper->start(false /* runOnCallingThread */, false /* canCallJava */, PRIORITY_HIGHEST); + char value[PROPERTY_VALUE_MAX] = {0}; + property_get("rtsp.transport.TCP", value, "false"); + if (!strcasecmp(value, "true")) { + mTryTCPInterleaving = true; + } else { + mTryTCPInterleaving = false; + } + // Strip any authentication info from the session url, we don't // want to transmit user/pass in cleartext. AString host, path, user, pass; @@ -244,6 +261,11 @@ struct MyHandler : public AHandler { msg->post(); } + void cancelTimeoutCheck() { + sp<AMessage> msg = new AMessage('canC', this); + msg->post(); + } + static void addRR(const sp<ABuffer> &buf) { uint8_t *ptr = buf->data() + buf->size(); ptr[0] = 0x80 | 0; @@ -703,6 +725,7 @@ struct MyHandler : public AHandler { timeoutSecs); } } + AVMediaServiceUtils::get()->setServerTimeoutUs(mKeepAliveTimeoutUs); i = mSessionID.find(";"); if (i >= 0) { @@ -722,16 +745,19 @@ struct MyHandler : public AHandler { // We are going to continue even if we were // unable to poke a hole into the firewall... - pokeAHole( + AVMediaServiceUtils::get()->pokeAHole( + this, track->mRTPSocket, track->mRTCPSocket, - transport); + transport, + mSessionHost); } mRTPConn->addStream( track->mRTPSocket, track->mRTCPSocket, mSessionDesc, index, - notify, track->mUsingInterleavedTCP); + notify, track->mUsingInterleavedTCP, + mConn->isIPV6()); mSetupTracksSuccessful = true; } else { @@ -774,6 +800,7 @@ struct MyHandler : public AHandler { request.append(mSessionID); request.append("\r\n"); + AVMediaServiceUtils::get()->appendRange(&request); request.append("\r\n"); sp<AMessage> reply = new AMessage('play', this); @@ -922,6 +949,15 @@ struct MyHandler : public AHandler { request.append("\r\n"); mConn->sendRequest(request.c_str(), reply); + + // If the response of teardown hasn't been received in 3 seconds, + // post 'tear' message to avoid ANR. + if (!msg->findInt32("reconnect", &reconnect) || !reconnect) { + sp<AMessage> teardown = new AMessage('tear', this); + teardown->setInt32("result", -ECONNABORTED); + teardown->post(kTearDownTimeoutUs); + } + break; } @@ -1020,6 +1056,13 @@ struct MyHandler : public AHandler { int32_t eos; if (msg->findInt32("eos", &eos)) { ALOGI("received BYE on track index %zu", trackIndex); + char value[PROPERTY_VALUE_MAX] = {0}; + if (property_get("rtcp.bye.notify", value, "false") + && !strcasecmp(value, "true")) { + sp<AMessage> msg = mNotify->dup(); + msg->setInt32("what", kWhatByeReceived); + msg->post(); + } if (!mAllTracksHaveTime && dataReceivedOnAllChannels()) { ALOGI("No time established => fake existing data"); @@ -1386,6 +1429,13 @@ struct MyHandler : public AHandler { break; } + case 'canC': + { + ALOGV("cancel checking timeout"); + mCheckGeneration++; + break; + } + default: TRESPASS(); break; @@ -1471,7 +1521,9 @@ struct MyHandler : public AHandler { size_t trackIndex = 0; while (trackIndex < mTracks.size() - && !(val == mTracks.editItemAt(trackIndex).mURL)) { + && !(AVMediaServiceUtils::get()->parseTrackURL( + mTracks.editItemAt(trackIndex).mURL, val) + || val == mTracks.editItemAt(trackIndex).mURL)) { ++trackIndex; } CHECK_LT(trackIndex, mTracks.size()); @@ -1648,8 +1700,9 @@ private: request.append(interleaveIndex + 1); } else { unsigned rtpPort; - ARTPConnection::MakePortPair( - &info->mRTPSocket, &info->mRTCPSocket, &rtpPort); + AVMediaServiceUtils::get()->makePortPair( + &info->mRTPSocket, &info->mRTCPSocket, &rtpPort, + mConn->isIPV6()); if (mUIDValid) { HTTPBase::RegisterSocketUserTag(info->mRTPSocket, mUID, @@ -1860,7 +1913,7 @@ private: mLastMediaTimeUs = mediaTimeUs; } - if (mediaTimeUs < 0) { + if (mediaTimeUs < 0 && !mSeekable) { ALOGV("dropping early accessUnit."); return false; } |