diff options
Diffstat (limited to 'media/libmediaplayerservice/nuplayer')
-rw-r--r-- | media/libmediaplayerservice/nuplayer/RTSPSource.cpp | 57 | ||||
-rw-r--r-- | media/libmediaplayerservice/nuplayer/RTSPSource.h | 6 |
2 files changed, 52 insertions, 11 deletions
diff --git a/media/libmediaplayerservice/nuplayer/RTSPSource.cpp b/media/libmediaplayerservice/nuplayer/RTSPSource.cpp index e72adc4..6d28298 100644 --- a/media/libmediaplayerservice/nuplayer/RTSPSource.cpp +++ b/media/libmediaplayerservice/nuplayer/RTSPSource.cpp @@ -38,7 +38,8 @@ NuPlayer::RTSPSource::RTSPSource( mFlags(0), mState(DISCONNECTED), mFinalResult(OK), - mDisconnectReplyID(0) { + mDisconnectReplyID(0), + mSeekGeneration(0) { if (headers) { mExtraHeaders = *headers; @@ -146,14 +147,21 @@ status_t NuPlayer::RTSPSource::getDuration(int64_t *durationUs) { } status_t NuPlayer::RTSPSource::seekTo(int64_t seekTimeUs) { + sp<AMessage> msg = new AMessage(kWhatPerformSeek, mReflector->id()); + msg->setInt32("generation", ++mSeekGeneration); + msg->setInt64("timeUs", seekTimeUs); + msg->post(200000ll); + + return OK; +} + +void NuPlayer::RTSPSource::performSeek(int64_t seekTimeUs) { if (mState != CONNECTED) { - return UNKNOWN_ERROR; + return; } mState = SEEKING; mHandler->seek(seekTimeUs); - - return OK; } bool NuPlayer::RTSPSource::isSeekable() { @@ -168,6 +176,20 @@ void NuPlayer::RTSPSource::onMessageReceived(const sp<AMessage> &msg) { mDisconnectReplyID = replyID; finishDisconnectIfPossible(); return; + } else if (msg->what() == kWhatPerformSeek) { + int32_t generation; + CHECK(msg->findInt32("generation", &generation)); + + if (generation != mSeekGeneration) { + // obsolete. + return; + } + + int64_t seekTimeUs; + CHECK(msg->findInt64("timeUs", &seekTimeUs)); + + performSeek(seekTimeUs); + return; } CHECK_EQ(msg->what(), (int)kWhatNotify); @@ -208,21 +230,32 @@ void NuPlayer::RTSPSource::onMessageReceived(const sp<AMessage> &msg) { break; } - const TrackInfo &info = mTracks.editItemAt(trackIndex); - sp<AnotherPacketSource> source = info.mSource; + TrackInfo *info = &mTracks.editItemAt(trackIndex); + + sp<AnotherPacketSource> source = info->mSource; if (source != NULL) { -#if 1 uint32_t rtpTime; CHECK(accessUnit->meta()->findInt32("rtp-time", (int32_t *)&rtpTime)); + if (!info->mNPTMappingValid) { + // This is a live stream, we didn't receive any normal + // playtime mapping. Assume the first packets correspond + // to time 0. + + ALOGV("This is a live stream, assuming time = 0"); + + info->mRTPTime = rtpTime; + info->mNormalPlaytimeUs = 0ll; + info->mNPTMappingValid = true; + } + int64_t nptUs = - ((double)rtpTime - (double)info.mRTPTime) - / info.mTimeScale + ((double)rtpTime - (double)info->mRTPTime) + / info->mTimeScale * 1000000ll - + info.mNormalPlaytimeUs; + + info->mNormalPlaytimeUs; accessUnit->meta()->setInt64("timeUs", nptUs); -#endif source->queueAccessUnit(accessUnit); } @@ -278,6 +311,7 @@ void NuPlayer::RTSPSource::onMessageReceived(const sp<AMessage> &msg) { TrackInfo *info = &mTracks.editItemAt(trackIndex); info->mRTPTime = rtpTime; info->mNormalPlaytimeUs = nptUs; + info->mNPTMappingValid = true; break; } @@ -305,6 +339,7 @@ void NuPlayer::RTSPSource::onConnected() { info.mTimeScale = timeScale; info.mRTPTime = 0; info.mNormalPlaytimeUs = 0ll; + info.mNPTMappingValid = false; if ((isAudio && mAudioTrack == NULL) || (isVideo && mVideoTrack == NULL)) { diff --git a/media/libmediaplayerservice/nuplayer/RTSPSource.h b/media/libmediaplayerservice/nuplayer/RTSPSource.h index 66eab72..59d06ad 100644 --- a/media/libmediaplayerservice/nuplayer/RTSPSource.h +++ b/media/libmediaplayerservice/nuplayer/RTSPSource.h @@ -56,6 +56,7 @@ private: enum { kWhatNotify = 'noti', kWhatDisconnect = 'disc', + kWhatPerformSeek = 'seek', }; enum State { @@ -76,6 +77,7 @@ private: int32_t mTimeScale; uint32_t mRTPTime; int64_t mNormalPlaytimeUs; + bool mNPTMappingValid; }; AString mURL; @@ -95,12 +97,16 @@ private: sp<AnotherPacketSource> mAudioTrack; sp<AnotherPacketSource> mVideoTrack; + int32_t mSeekGeneration; + sp<AnotherPacketSource> getSource(bool audio); void onConnected(); void onDisconnected(const sp<AMessage> &msg); void finishDisconnectIfPossible(); + void performSeek(int64_t seekTimeUs); + DISALLOW_EVIL_CONSTRUCTORS(RTSPSource); }; |