Relax frame discontinuity detection

This commit is contained in:
trav90
2017-05-04 02:30:01 -05:00
committed by roytam1
parent cc4891fe01
commit d03c8fa0e9
2 changed files with 25 additions and 2 deletions
+23 -2
View File
@@ -263,6 +263,7 @@ TrackBuffersManager::CompleteResetParserState()
// if we have been aborted, we may have pending frames that we are going
// to discard now.
track->mQueuedSamples.Clear();
track->mLongestFrameDuration.reset();
}
// 6. Remove all bytes from the input buffer.
mIncomingBuffers.Clear();
@@ -699,6 +700,9 @@ TrackBuffersManager::OnDemuxerInitDone(nsresult)
// 3. Set the need random access point flag on all track buffers to true.
mVideoTracks.mNeedRandomAccessPoint = true;
mAudioTracks.mNeedRandomAccessPoint = true;
mVideoTracks.mLongestFrameDuration = mVideoTracks.mLastFrameDuration;
mAudioTracks.mLongestFrameDuration = mAudioTracks.mLastFrameDuration;
}
// 4. Let active track flag equal false.
@@ -1047,10 +1051,15 @@ TrackBuffersManager::ProcessFrame(MediaRawData* aSample,
// TODO: Maybe we should be using TimeStamp and TimeDuration instead?
// Some MP4 content may exhibit an extremely short frame duration.
// As such, we can't use the last frame duration as a way to detect
// discontinuities as required per step 6 above.
// Instead we use the biggest duration seen so far in this run (init + media
// segment).
if ((trackBuffer.mLastDecodeTimestamp.isSome() &&
decodeTimestamp < trackBuffer.mLastDecodeTimestamp.ref()) ||
(trackBuffer.mLastDecodeTimestamp.isSome() &&
decodeTimestamp - trackBuffer.mLastDecodeTimestamp.ref() > 2*trackBuffer.mLastFrameDuration.ref())) {
decodeTimestamp - trackBuffer.mLastDecodeTimestamp.ref() > 2*trackBuffer.mLongestFrameDuration.ref())) {
// 1a. If mode equals "segments":
if (mParent->mAppendMode == SourceBufferAppendMode::Segments) {
@@ -1071,6 +1080,8 @@ TrackBuffersManager::ProcessFrame(MediaRawData* aSample,
track->mHighestEndTimestamp.reset();
// 5. Set the need random access point flag on all track buffers to true.
track->mNeedRandomAccessPoint = true;
trackBuffer.mLongestFrameDuration.reset();
}
MSE_DEBUG("Detected discontinuity. Restarting process");
// 6. Jump to the Loop Top step above to restart processing of the current coded frame.
@@ -1201,7 +1212,17 @@ TrackBuffersManager::ProcessFrame(MediaRawData* aSample,
// 17. Set last decode timestamp for track buffer to decode timestamp.
trackBuffer.mLastDecodeTimestamp = Some(decodeTimestamp);
// 18. Set last frame duration for track buffer to frame duration.
trackBuffer.mLastFrameDuration = Some(TimeUnit::FromMicroseconds(aSample->mDuration));
trackBuffer.mLastFrameDuration =
Some(TimeUnit::FromMicroseconds(aSample->mDuration));
if (trackBuffer.mLongestFrameDuration.isNothing()) {
trackBuffer.mLongestFrameDuration = trackBuffer.mLastFrameDuration;
} else {
trackBuffer.mLongestFrameDuration =
Some(std::max(trackBuffer.mLongestFrameDuration.ref(),
trackBuffer.mLastFrameDuration.ref()));
}
// 19. If highest end timestamp for track buffer is unset or frame end timestamp is greater than highest end timestamp, then set highest end timestamp for track buffer to frame end timestamp.
if (trackBuffer.mHighestEndTimestamp.isNothing() ||
frameEndTimestamp > trackBuffer.mHighestEndTimestamp.ref()) {
@@ -171,6 +171,8 @@ private:
Maybe<TimeUnit> mLastDecodeTimestamp;
Maybe<TimeUnit> mLastFrameDuration;
Maybe<TimeUnit> mHighestEndTimestamp;
// Longest frame duration seen in a coded frame group.
Maybe<TimeUnit> mLongestFrameDuration;
bool mNeedRandomAccessPoint;
nsRefPtr<MediaTrackDemuxer> mDemuxer;
TrackBuffer mQueuedSamples;