Skip to content

Commit

Permalink
Bug 1466606 - P2. Re-use code to determine NextGetSample index. r=bryce
Browse files Browse the repository at this point in the history
Previous commit added SetNextGetSampleIndexIfNeeded, let's re-use it for GetSample.
We continue to have an exception code as it caters for the most common code path, which is we retrieve one sample after the other.

MozReview-Commit-ID: HOQ53qwZj7w

--HG--
extra : rebase_source : cc9bc0b41a7085d28554f7ed764a18decfea327d
  • Loading branch information
Jean-Yves Avenard authored and Alex Kontos committed Jun 5, 2019
1 parent 530933a commit bc0a41f
Showing 1 changed file with 11 additions and 28 deletions.
39 changes: 11 additions & 28 deletions dom/media/mediasource/TrackBuffersManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2336,17 +2336,6 @@ TrackBuffersManager::GetSample(TrackInfo::TrackType aTrack,

aResult = NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA;

if (!track.Length()) {
aResult = NS_ERROR_DOM_MEDIA_END_OF_STREAM;
return nullptr;
}

if (trackData.mNextGetSampleIndex.isNothing() &&
trackData.mNextSampleTimecode == TimeUnit()) {
// First demux, get first sample.
trackData.mNextGetSampleIndex = Some(0u);
}

if (trackData.mNextGetSampleIndex.isSome()) {
if (trackData.mNextGetSampleIndex.ref() >= track.Length()) {
aResult = NS_ERROR_DOM_MEDIA_END_OF_STREAM;
Expand Down Expand Up @@ -2393,24 +2382,16 @@ TrackBuffersManager::GetSample(TrackInfo::TrackType aTrack,
return p.forget();
}

if (trackData.mNextSampleTimecode >
track.LastElement()->mTimecode + track.LastElement()->mDuration) {
// The next element is past our last sample. We're done.
trackData.mNextGetSampleIndex = Some(uint32_t(track.Length()));
aResult = NS_ERROR_DOM_MEDIA_END_OF_STREAM;
return nullptr;
}
aResult = SetNextGetSampleIndexIfNeeded(aTrack, aFuzz);

// Our previous index has been overwritten, attempt to find the new one.
int32_t pos = FindCurrentPosition(aTrack, aFuzz);
if (pos < 0) {
MSE_DEBUG("Couldn't find sample (pts:%" PRId64 " dts:%" PRId64 ")",
trackData.mNextSampleTime.ToMicroseconds(),
trackData.mNextSampleTimecode.ToMicroseconds());
if (NS_FAILED(aResult)) {
return nullptr;
}

const RefPtr<MediaRawData>& sample = track[pos];
MOZ_RELEASE_ASSERT(trackData.mNextGetSampleIndex.isSome() &&
trackData.mNextGetSampleIndex.ref() < track.Length());
const RefPtr<MediaRawData>& sample =
track[trackData.mNextGetSampleIndex.ref()];
RefPtr<MediaRawData> p = sample->Clone();
if (!p) {
// OOM
Expand All @@ -2419,15 +2400,14 @@ TrackBuffersManager::GetSample(TrackInfo::TrackType aTrack,
}

// Find the previous keyframe to calculate the evictable amount.
int32_t i = pos;
uint32_t i = trackData.mNextGetSampleIndex.ref();
for (; !track[i]->mKeyframe; i--) {
}
UpdateEvictionIndex(trackData, i);

trackData.mNextGetSampleIndex = Some(uint32_t(pos)+1);
trackData.mNextGetSampleIndex.ref()++;
trackData.mNextSampleTimecode = sample->mTimecode + sample->mDuration;
trackData.mNextSampleTime = sample->GetEndTime();
aResult = NS_OK;
return p.forget();
}

Expand Down Expand Up @@ -2564,6 +2544,9 @@ TrackBuffersManager::SetNextGetSampleIndexIfNeeded(TrackInfo::TrackType aTrack,
int32_t pos = FindCurrentPosition(aTrack, aFuzz);
if (pos < 0) {
// Not found, must wait for more data.
MSE_DEBUG("Couldn't find sample (pts:%" PRId64 " dts:%" PRId64 ")",
trackData.mNextSampleTime.ToMicroseconds(),
trackData.mNextSampleTimecode.ToMicroseconds());
return NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA;
}
trackData.mNextGetSampleIndex = Some(uint32_t(pos));
Expand Down

0 comments on commit bc0a41f

Please sign in to comment.