Bug 1172264 - Route mExplicitDuration directly from the mediasource code to MediaDecoder, and stop passing an argument to DurationChanged. r=pending=jww

This commit is contained in:
Bobby Holley 2015-06-09 15:16:27 -07:00
parent 56a6ea9edb
commit a1ebe95511
4 changed files with 39 additions and 15 deletions

View File

@ -304,10 +304,6 @@ void MediaDecoder::AddOutputStream(ProcessedMediaStream* aStream,
double MediaDecoder::GetDuration()
{
MOZ_ASSERT(NS_IsMainThread());
if (mInfiniteStream) {
return std::numeric_limits<double>::infinity();
}
return mDuration;
}
@ -322,6 +318,7 @@ void MediaDecoder::SetInfinite(bool aInfinite)
{
MOZ_ASSERT(NS_IsMainThread());
mInfiniteStream = aInfinite;
DurationChanged();
}
bool MediaDecoder::IsInfinite()
@ -366,6 +363,7 @@ MediaDecoder::MediaDecoder() :
mPausedForPlaybackRateNull(false),
mMinimizePreroll(false),
mMediaTracksConstructed(false),
mFiredMetadataLoaded(false),
mIsDormant(false),
mWasEndedWhenEnteredDormant(false),
mIsHeuristicDormantSupported(
@ -669,6 +667,7 @@ void MediaDecoder::MetadataLoaded(nsAutoPtr<MediaInfo> aInfo,
// our new size.
Invalidate();
if (aEventVisibility != MediaDecoderEventVisibility::Suppressed) {
mFiredMetadataLoaded = true;
mOwner->MetadataLoaded(mInfo, nsAutoPtr<const MetadataTags>(aTags.forget()));
}
}
@ -1078,22 +1077,38 @@ void MediaDecoder::UpdateLogicalPosition(MediaDecoderEventVisibility aEventVisib
}
}
void MediaDecoder::DurationChanged(TimeUnit aNewDuration)
void MediaDecoder::DurationChanged()
{
MOZ_ASSERT(NS_IsMainThread());
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
double oldDuration = mDuration;
mDuration = aNewDuration.ToSeconds();
if (IsInfinite()) {
mDuration = std::numeric_limits<double>::infinity();
} else if (mExplicitDuration.Ref().isSome()) {
mDuration = mExplicitDuration.Ref().ref();
} else if (mStateMachineDuration.Ref().isSome()) {
mDuration = mStateMachineDuration.Ref().ref().ToSeconds();
}
if (mDuration == oldDuration || IsNaN(mDuration)) {
return;
}
DECODER_LOG("Duration changed to %f", mDuration);
// Duration has changed so we should recompute playback rate
UpdatePlaybackRate();
if (mOwner && oldDuration != mDuration && !IsInfinite()) {
DECODER_LOG("Duration changed to %f", mDuration);
// See https://www.w3.org/Bugs/Public/show_bug.cgi?id=28822 for a discussion
// of whether we should fire durationchange on explicit infinity.
if (mOwner && mFiredMetadataLoaded &&
(!mozilla::IsInfinite<double>(mDuration) || mExplicitDuration.Ref().isSome())) {
mOwner->DispatchAsyncEvent(NS_LITERAL_STRING("durationchange"));
}
if (CurrentPosition() > aNewDuration.ToMicroseconds()) {
Seek(aNewDuration.ToSeconds(), SeekTarget::Accurate);
if (CurrentPosition() > TimeUnit::FromSeconds(mDuration).ToMicroseconds()) {
Seek(mDuration, SeekTarget::Accurate);
}
}

View File

@ -512,7 +512,7 @@ public:
// Called by the state machine to notify the decoder that the duration
// has changed.
void DurationChanged(media::TimeUnit aNewDuration);
void DurationChanged();
bool OnStateMachineTaskQueue() const override;
@ -996,7 +996,15 @@ protected:
// for MSE.
Canonical<Maybe<double>> mExplicitDuration;
double ExplicitDuration() { return mExplicitDuration.Ref().ref(); }
void SetExplicitDuration(double aValue) { mExplicitDuration.Set(Some(aValue)); }
void SetExplicitDuration(double aValue)
{
mExplicitDuration.Set(Some(aValue));
// We Invoke DurationChanged explicitly, rather than using a watcher, so
// that it takes effect immediately, rather than at the end of the current task.
DurationChanged();
}
public:
AbstractCanonical<Maybe<double>>* CanonicalExplicitDuration() { return &mExplicitDuration; }
protected:
@ -1088,6 +1096,9 @@ protected:
// track list, false if all tracks are removed from the track list.
bool mMediaTracksConstructed;
// True if we've already fired metadataloaded.
bool mFiredMetadataLoaded;
// Stores media info, including info of audio tracks and video tracks, should
// only be accessed from main thread.
nsAutoPtr<MediaInfo> mInfo;

View File

@ -1420,8 +1420,7 @@ void MediaDecoderStateMachine::RecomputeDuration()
mDuration = Some(duration);
if (fireDurationChanged) {
nsCOMPtr<nsIRunnable> event =
NS_NewRunnableMethodWithArg<TimeUnit>(mDecoder, &MediaDecoder::DurationChanged, duration);
nsCOMPtr<nsIRunnable> event = NS_NewRunnableMethod(mDecoder, &MediaDecoder::DurationChanged);
AbstractThread::MainThread()->Dispatch(event.forget());
}
}

View File

@ -221,7 +221,6 @@ MediaSourceDecoder::SetMediaSourceDuration(double aDuration, MSRangeRemovalActio
GetReader()->SetMediaSourceDuration(ExplicitDuration());
}
MediaDecoder::DurationChanged(TimeUnit::FromSeconds(ExplicitDuration()));
if (mMediaSource && aAction != MSRangeRemovalAction::SKIP) {
mMediaSource->DurationChange(oldDuration, aDuration);
}