Bug 1245463: [MSE] P2. Remove MediaSource's duration mirror. r?gerald
It served no purpose other than implementing the MSE spec by the letter. The spirit is preserved.
This allows to disable tail dispatching on the MediaSourceDemuxer's TaskQueue which prevents us from performing synchronous operation on the main thread.
MozReview-Commit-ID: G7aqfvGsf1e
--- a/dom/media/mediasource/MediaSourceDemuxer.cpp
+++ b/dom/media/mediasource/MediaSourceDemuxer.cpp
@@ -17,17 +17,17 @@
namespace mozilla {
typedef TrackInfo::TrackType TrackType;
using media::TimeUnit;
using media::TimeIntervals;
MediaSourceDemuxer::MediaSourceDemuxer()
: mTaskQueue(new TaskQueue(GetMediaThreadPool(MediaThreadType::PLAYBACK),
- /* aSupportsTailDispatch = */ true))
+ /* aSupportsTailDispatch = */ false))
, mMonitor("MediaSourceDemuxer")
{
MOZ_ASSERT(NS_IsMainThread());
}
// Due to inaccuracies in determining buffer end
// frames (Bug 1065207). This value is based on the end of frame
// default value used in Blink, kDefaultBufferDurationInMs.
--- a/dom/media/mediasource/TrackBuffersManager.cpp
+++ b/dom/media/mediasource/TrackBuffersManager.cpp
@@ -95,30 +95,23 @@ TrackBuffersManager::TrackBuffersManager
, mActiveTrack(false)
, mType(aType)
, mParser(ContainerParser::CreateForMIMEType(aType))
, mProcessedInput(0)
, mAppendRunning(false)
, mTaskQueue(aParentDecoder->GetDemuxer()->GetTaskQueue())
, mSourceBufferAttributes(aAttributes)
, mParentDecoder(new nsMainThreadPtrHolder<MediaSourceDecoder>(aParentDecoder, false /* strict */))
- , mMediaSourceDuration(mTaskQueue, Maybe<double>(), "TrackBuffersManager::mMediaSourceDuration (Mirror)")
, mAbort(false)
, mEvictionThreshold(Preferences::GetUint("media.mediasource.eviction_threshold",
100 * (1 << 20)))
, mEvictionOccurred(false)
, mMonitor("TrackBuffersManager")
{
MOZ_ASSERT(NS_IsMainThread(), "Must be instanciated on the main thread");
- RefPtr<TrackBuffersManager> self = this;
- nsCOMPtr<nsIRunnable> task =
- NS_NewRunnableFunction([self] () {
- self->mMediaSourceDuration.Connect(self->mParentDecoder->CanonicalExplicitDuration());
- });
- GetTaskQueue()->Dispatch(task.forget());
}
TrackBuffersManager::~TrackBuffersManager()
{
ShutdownDemuxers();
}
bool
@@ -316,17 +309,16 @@ TrackBuffersManager::Detach()
RefPtr<TrackBuffersManager> self = this;
nsCOMPtr<nsIRunnable> task =
NS_NewRunnableFunction([self] () {
// Clear our sourcebuffer
self->CodedFrameRemoval(TimeInterval(TimeUnit::FromSeconds(0),
TimeUnit::FromInfinity()));
self->mProcessingPromise.RejectIfExists(NS_ERROR_ABORT, __func__);
self->mAppendPromise.RejectIfExists(NS_ERROR_ABORT, __func__);
- self->mMediaSourceDuration.DisconnectIfConnected();
});
GetTaskQueue()->Dispatch(task.forget());
}
#if defined(DEBUG)
void
TrackBuffersManager::Dump(const char* aPath)
{
@@ -491,25 +483,17 @@ TrackBuffersManager::CodedFrameRemovalWi
bool
TrackBuffersManager::CodedFrameRemoval(TimeInterval aInterval)
{
MOZ_ASSERT(OnTaskQueue());
MOZ_ASSERT(!mAppendRunning, "Logic error: Append in progress");
MSE_DEBUG("From %.2fs to %.2f",
aInterval.mStart.ToSeconds(), aInterval.mEnd.ToSeconds());
- if (mMediaSourceDuration.Ref().isNothing() ||
- IsNaN(mMediaSourceDuration.Ref().ref())) {
- MSE_DEBUG("Nothing to remove, aborting");
- return false;
- }
- TimeUnit duration{TimeUnit::FromSeconds(mMediaSourceDuration.Ref().ref())};
-
#if DEBUG
- MSE_DEBUG("duration:%.2f", duration.ToSeconds());
if (HasVideo()) {
MSE_DEBUG("before video ranges=%s",
DumpTimeRanges(mVideoTracks.mBufferedRanges).get());
}
if (HasAudio()) {
MSE_DEBUG("before audio ranges=%s",
DumpTimeRanges(mAudioTracks.mBufferedRanges).get());
}
@@ -522,17 +506,24 @@ TrackBuffersManager::CodedFrameRemoval(T
bool dataRemoved = false;
// 3. For each track buffer in this source buffer, run the following steps:
for (auto track : GetTracksList()) {
MSE_DEBUGV("Processing %s track", track->mInfo->mMimeType.get());
// 1. Let remove end timestamp be the current value of duration
// See bug: https://www.w3.org/Bugs/Public/show_bug.cgi?id=28727
- TimeUnit removeEndTimestamp = std::max(duration, track->mBufferedRanges.GetEnd());
+ // At worse we will remove all frames until the end, unless a key frame is
+ // found between the current interval's end and the trackbuffer's end.
+ TimeUnit removeEndTimestamp = track->mBufferedRanges.GetEnd();
+
+ if (start > removeEndTimestamp) {
+ // Nothing to remove.
+ continue;
+ }
// 2. If this track buffer has a random access point timestamp that is greater than or equal to end,
// then update remove end timestamp to that random access point timestamp.
if (end < track->mBufferedRanges.GetEnd()) {
for (auto& frame : track->mBuffers.LastElement()) {
if (frame->mKeyframe && frame->mTime >= end.ToMicroseconds()) {
removeEndTimestamp = TimeUnit::FromMicroseconds(frame->mTime);
break;
--- a/dom/media/mediasource/TrackBuffersManager.h
+++ b/dom/media/mediasource/TrackBuffersManager.h
@@ -344,19 +344,16 @@ private:
media::TimeUnit mTimestampOffset;
media::TimeUnit mLastTimestampOffset;
void RestoreCachedVariables();
// Strong references to external objects.
RefPtr<dom::SourceBufferAttributes> mSourceBufferAttributes;
nsMainThreadPtrHandle<MediaSourceDecoder> mParentDecoder;
- // MediaSource duration mirrored from MediaDecoder on the main thread..
- Mirror<Maybe<double>> mMediaSourceDuration;
-
// Set to true if abort was called.
Atomic<bool> mAbort;
// Set to true if mediasource state changed to ended.
Atomic<bool> mEnded;
// Global size of this source buffer content.
Atomic<int64_t> mSizeSourceBuffer;
uint32_t mEvictionThreshold;