Bug 1128069: [MSE] P6. Call NotifyDataArrived from MediaDecoder. r?gerald
Calling NotifyDataArrived from each sourcebuffer will cause multiple unnecessary NotifyDataArrived to the MediaFormatReader when it could only be done once. Additionally, it ensures that the media duration is updated prior to the reader actioning on the notification.
Extra: mEnded is only ever accessed on the main thread, there's no need to make it atomic.
MozReview-Commit-ID: IKq7IRBbWic
--- a/dom/media/mediasource/MediaSourceDecoder.cpp
+++ b/dom/media/mediasource/MediaSourceDecoder.cpp
@@ -187,17 +187,22 @@ MediaSourceDecoder::DetachMediaSource()
mMediaSource = nullptr;
}
void
MediaSourceDecoder::Ended(bool aEnded)
{
MOZ_ASSERT(NS_IsMainThread());
static_cast<MediaSourceResource*>(GetResource())->SetEnded(aEnded);
- mEnded = true;
+ if (aEnded) {
+ // We want the MediaSourceReader to refresh its buffered range as it may
+ // have been modified (end lined up).
+ NotifyDataArrived();
+ }
+ mEnded = aEnded;
}
void
MediaSourceDecoder::AddSizeOfResources(ResourceSizes* aSizes)
{
MOZ_ASSERT(NS_IsMainThread());
if (GetDemuxer()) {
GetDemuxer()->AddSizeOfResources(aSizes);
@@ -305,16 +310,18 @@ MediaSourceDecoder::CanPlayThrough()
timeAhead,
MediaSourceDemuxer::EOS_FUZZ);
return GetBuffered().Contains(ClampIntervalToEnd(interval));
}
TimeInterval
MediaSourceDecoder::ClampIntervalToEnd(const TimeInterval& aInterval)
{
+ MOZ_ASSERT(NS_IsMainThread());
+
if (!mEnded) {
return aInterval;
}
TimeInterval interval(TimeUnit(), TimeUnit::FromSeconds(GetDuration()));
return aInterval.Intersection(interval);
}
#undef MSE_DEBUG
--- a/dom/media/mediasource/MediaSourceDecoder.h
+++ b/dom/media/mediasource/MediaSourceDecoder.h
@@ -86,14 +86,14 @@ private:
// The owning MediaSource holds a strong reference to this decoder, and
// calls Attach/DetachMediaSource on this decoder to set and clear
// mMediaSource.
dom::MediaSource* mMediaSource;
RefPtr<MediaSourceDemuxer> mDemuxer;
RefPtr<MediaFormatReader> mReader;
- Atomic<bool> mEnded;
+ bool mEnded;
};
} // namespace mozilla
#endif /* MOZILLA_MEDIASOURCEDECODER_H_ */
--- a/dom/media/mediasource/SourceBuffer.cpp
+++ b/dom/media/mediasource/SourceBuffer.cpp
@@ -284,19 +284,16 @@ SourceBuffer::Detach()
void
SourceBuffer::Ended()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(IsAttached());
MSE_DEBUG("Ended");
mTrackBuffersManager->Ended();
- // We want the MediaSourceReader to refresh its buffered range as it may
- // have been modified (end lined up).
- mMediaSource->GetDecoder()->NotifyDataArrived();
}
SourceBuffer::SourceBuffer(MediaSource* aMediaSource, const nsACString& aType)
: DOMEventTargetHelper(aMediaSource->GetParentObject())
, mMediaSource(aMediaSource)
, mCurrentAttributes(aType.LowerCaseEqualsLiteral("audio/mpeg") ||
aType.LowerCaseEqualsLiteral("audio/aac"))
, mUpdating(false)