Bug 1120282: Do not fire durationchange during call to ReadMetadata. r=mattwoodrow

--HG--
extra : rebase_source : cf8bdb932aac0661de21c7fa4eba7d50b14b3dbc
This commit is contained in:
Jean-Yves Avenard 2015-01-16 23:49:02 +11:00
parent eb3a3abff9
commit 59151e0b1c
2 changed files with 24 additions and 6 deletions

View File

@ -218,9 +218,7 @@ MediaSourceDecoder::SetDecodedDuration(int64_t aDuration)
if (aDuration >= 0) {
duration /= USECS_PER_S;
}
// No need to call Range Removal algorithm as this is called following
// ReadMetadata and nothing has been added to the source buffers yet.
SetMediaSourceDuration(duration, MSRangeRemovalAction::SKIP);
DoSetMediaSourceDuration(duration);
}
void
@ -228,6 +226,13 @@ MediaSourceDecoder::SetMediaSourceDuration(double aDuration, MSRangeRemovalActio
{
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
double oldDuration = mMediaSourceDuration;
DoSetMediaSourceDuration(aDuration);
ScheduleDurationChange(oldDuration, aDuration, aAction);
}
void
MediaSourceDecoder::DoSetMediaSourceDuration(double aDuration)
{
if (aDuration >= 0) {
mDecoderStateMachine->SetDuration(aDuration * USECS_PER_S);
mMediaSourceDuration = aDuration;
@ -235,19 +240,27 @@ MediaSourceDecoder::SetMediaSourceDuration(double aDuration, MSRangeRemovalActio
mDecoderStateMachine->SetDuration(INT64_MAX);
mMediaSourceDuration = PositiveInfinity<double>();
}
}
void
MediaSourceDecoder::ScheduleDurationChange(double aOldDuration,
double aNewDuration,
MSRangeRemovalAction aAction)
{
if (aAction == MSRangeRemovalAction::SKIP) {
if (NS_IsMainThread()) {
MediaDecoder::DurationChanged();
} else {
nsCOMPtr<nsIRunnable> task = NS_NewRunnableMethod(this, &MediaDecoder::DurationChanged);
nsCOMPtr<nsIRunnable> task =
NS_NewRunnableMethod(this, &MediaDecoder::DurationChanged);
NS_DispatchToMainThread(task);
}
} else {
if (NS_IsMainThread()) {
DurationChanged(oldDuration, mMediaSourceDuration);
DurationChanged(aOldDuration, aNewDuration);
} else {
nsRefPtr<nsIRunnable> task =
new DurationChangedRunnable(this, oldDuration, mMediaSourceDuration);
new DurationChangedRunnable(this, aOldDuration, aNewDuration);
NS_DispatchToMainThread(task);
}
}

View File

@ -80,6 +80,11 @@ public:
bool IsActiveReader(MediaDecoderReader* aReader);
private:
void DoSetMediaSourceDuration(double aDuration);
void ScheduleDurationChange(double aOldDuration,
double aNewDuration,
MSRangeRemovalAction aAction);
// The owning MediaSource holds a strong reference to this decoder, and
// calls Attach/DetachMediaSource on this decoder to set and clear
// mMediaSource.