@@ -208,21 +208,32 @@ void NuPlayer::RTSPSource::onMessageReceived(const sp<AMessage> &msg) {
208208 break ;
209209 }
210210
211- const TrackInfo &info = mTracks .editItemAt (trackIndex);
212- sp<AnotherPacketSource> source = info.mSource ;
211+ TrackInfo *info = &mTracks .editItemAt (trackIndex);
212+
213+ sp<AnotherPacketSource> source = info->mSource ;
213214 if (source != NULL ) {
214- #if 1
215215 uint32_t rtpTime;
216216 CHECK (accessUnit->meta ()->findInt32 (" rtp-time" , (int32_t *)&rtpTime));
217217
218+ if (!info->mNPTMappingValid ) {
219+ // This is a live stream, we didn't receive any normal
220+ // playtime mapping. Assume the first packets correspond
221+ // to time 0.
222+
223+ LOGV (" This is a live stream, assuming time = 0" );
224+
225+ info->mRTPTime = rtpTime;
226+ info->mNormalPlaytimeUs = 0ll ;
227+ info->mNPTMappingValid = true ;
228+ }
229+
218230 int64_t nptUs =
219- ((double )rtpTime - (double )info. mRTPTime )
220- / info. mTimeScale
231+ ((double )rtpTime - (double )info-> mRTPTime )
232+ / info-> mTimeScale
221233 * 1000000ll
222- + info. mNormalPlaytimeUs ;
234+ + info-> mNormalPlaytimeUs ;
223235
224236 accessUnit->meta ()->setInt64 (" timeUs" , nptUs);
225- #endif
226237
227238 source->queueAccessUnit (accessUnit);
228239 }
@@ -278,6 +289,7 @@ void NuPlayer::RTSPSource::onMessageReceived(const sp<AMessage> &msg) {
278289 TrackInfo *info = &mTracks .editItemAt (trackIndex);
279290 info->mRTPTime = rtpTime;
280291 info->mNormalPlaytimeUs = nptUs;
292+ info->mNPTMappingValid = true ;
281293 break ;
282294 }
283295
@@ -305,6 +317,7 @@ void NuPlayer::RTSPSource::onConnected() {
305317 info.mTimeScale = timeScale;
306318 info.mRTPTime = 0 ;
307319 info.mNormalPlaytimeUs = 0ll ;
320+ info.mNPTMappingValid = false ;
308321
309322 if ((isAudio && mAudioTrack == NULL )
310323 || (isVideo && mVideoTrack == NULL )) {
0 commit comments