Bug 1091008 - Remove special handling for MSE in HTMLMediaElement::Buffered. r=cajbir

The same code will now be reached by invoking this method on the decoder.
This commit is contained in:
Bobby Holley 2014-11-11 20:50:21 -08:00
parent b3d649c2db
commit 610334a3eb
7 changed files with 39 additions and 54 deletions

View File

@ -3678,9 +3678,7 @@ HTMLMediaElement::Buffered() const
{
nsRefPtr<TimeRanges> ranges = new TimeRanges();
if (mReadyState > nsIDOMHTMLMediaElement::HAVE_NOTHING) {
if (mMediaSource) {
mMediaSource->GetBuffered(ranges);
} else if (mDecoder) {
if (mDecoder) {
// If GetBuffered fails we ignore the error result and just return the
// time ranges we found up till the error.
mDecoder->GetBuffered(ranges);

View File

@ -345,48 +345,6 @@ MediaSource::Detach()
}
}
void
MediaSource::GetBuffered(TimeRanges* aBuffered)
{
ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
MOZ_ASSERT(aBuffered->Length() == 0);
if (mActiveSourceBuffers->IsEmpty()) {
return;
}
double highestEndTime = 0;
nsTArray<nsRefPtr<TimeRanges>> activeRanges;
for (uint32_t i = 0; i < mActiveSourceBuffers->Length(); ++i) {
bool found;
SourceBuffer* sourceBuffer = mActiveSourceBuffers->IndexedGetter(i, found);
ErrorResult dummy;
*activeRanges.AppendElement() = sourceBuffer->GetBuffered(dummy);
highestEndTime = std::max(highestEndTime, activeRanges.LastElement()->GetEndTime());
}
TimeRanges* intersectionRanges = aBuffered;
intersectionRanges->Add(0, highestEndTime);
for (uint32_t i = 0; i < activeRanges.Length(); ++i) {
TimeRanges* sourceRanges = activeRanges[i];
if (mReadyState == MediaSourceReadyState::Ended) {
// Set the end time on the last range to highestEndTime by adding a
// new range spanning the current end time to highestEndTime, which
// Normalize() will then merge with the old last range.
sourceRanges->Add(sourceRanges->GetEndTime(), highestEndTime);
sourceRanges->Normalize();
}
intersectionRanges->Intersection(sourceRanges);
}
MSE_DEBUG("MediaSource(%p)::GetBuffered ranges=%s", this, DumpTimeRanges(intersectionRanges).get());
}
MediaSource::MediaSource(nsPIDOMWindow* aWindow)
: DOMEventTargetHelper(aWindow)
, mDuration(UnspecifiedNaN<double>())

View File

@ -74,8 +74,6 @@ public:
bool Attach(MediaSourceDecoder* aDecoder);
void Detach();
void GetBuffered(TimeRanges* aBuffered);
// Set mReadyState to aState and fire the required events at the MediaSource.
void SetReadyState(MediaSourceReadyState aState);

View File

@ -82,7 +82,7 @@ MediaSourceDecoder::GetSeekable(dom::TimeRanges* aSeekable)
// Return empty range.
} else if (duration > 0 && mozilla::IsInfinite(duration)) {
nsRefPtr<dom::TimeRanges> bufferedRanges = new dom::TimeRanges();
mMediaSource->GetBuffered(bufferedRanges);
mReader->GetBuffered(bufferedRanges);
aSeekable->Add(bufferedRanges->GetStartTime(), bufferedRanges->GetEndTime());
} else {
aSeekable->Add(0, duration);

View File

@ -74,11 +74,6 @@ private:
// mMediaSource.
dom::MediaSource* mMediaSource;
nsRefPtr<MediaSourceReader> mReader;
// XXXbholley - This is to allow the reader to invoke GetBuffered on
// mMediaSource. It goes away in a subsequent patch when that function gets
// hoisted into MediaSourceReader.
friend class MediaSourceReader;
};
} // namespace mozilla

View File

@ -40,6 +40,8 @@ extern PRLogModuleInfo* GetMediaSourceAPILog();
// default value used in Blink, kDefaultBufferDurationInMs.
#define EOS_FUZZ_US 125000
using mozilla::dom::TimeRanges;
namespace mozilla {
MediaSourceReader::MediaSourceReader(MediaSourceDecoder* aDecoder)
@ -547,7 +549,40 @@ MediaSourceReader::AttemptSeek()
nsresult
MediaSourceReader::GetBuffered(dom::TimeRanges* aBuffered)
{
static_cast<MediaSourceDecoder*>(mDecoder)->mMediaSource->GetBuffered(aBuffered);
ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
MOZ_ASSERT(aBuffered->Length() == 0);
if (mTrackBuffers.IsEmpty()) {
return NS_OK;
}
double highestEndTime = 0;
nsTArray<nsRefPtr<TimeRanges>> activeRanges;
for (uint32_t i = 0; i < mTrackBuffers.Length(); ++i) {
nsRefPtr<TimeRanges> r = new TimeRanges();
mTrackBuffers[i]->Buffered(r);
activeRanges.AppendElement(r);
highestEndTime = std::max(highestEndTime, activeRanges.LastElement()->GetEndTime());
}
TimeRanges* intersectionRanges = aBuffered;
intersectionRanges->Add(0, highestEndTime);
for (uint32_t i = 0; i < activeRanges.Length(); ++i) {
TimeRanges* sourceRanges = activeRanges[i];
if (IsEnded()) {
// Set the end time on the last range to highestEndTime by adding a
// new range spanning the current end time to highestEndTime, which
// Normalize() will then merge with the old last range.
sourceRanges->Add(sourceRanges->GetEndTime(), highestEndTime);
sourceRanges->Normalize();
}
intersectionRanges->Intersection(sourceRanges);
}
MSE_DEBUG("MediaSourceReader(%p)::GetBuffered ranges=%s", this, DumpTimeRanges(intersectionRanges).get());
return NS_OK;
}

View File

@ -81,6 +81,7 @@ public:
void Seek(int64_t aTime, int64_t aStartTime, int64_t aEndTime,
int64_t aCurrentTime) MOZ_OVERRIDE;
// Acquires the decoder monitor, and is thus callable on any thread.
nsresult GetBuffered(dom::TimeRanges* aBuffered) MOZ_OVERRIDE;
already_AddRefed<SourceBufferDecoder> CreateSubDecoder(const nsACString& aType);