Clarify the semantics of when we fire DurationChanged

This commit is contained in:
trav90
2017-07-02 04:37:27 -05:00
committed by Roy Tam
parent f319e95fd1
commit cf35cc45a2
+9 -6
View File
@@ -1416,8 +1416,12 @@ void MediaDecoderStateMachine::RecomputeDuration()
MOZ_ASSERT(OnTaskQueue());
ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
TimeUnit duration;
// We dispatch DurationChanged to the MediaDecoder when the duration changes
// sometime after initialization, unless it has already been fired by the code
// that set the new duration.
bool fireDurationChanged = false;
TimeUnit duration;
if (mExplicitDuration.Ref().isSome()) {
double d = mExplicitDuration.Ref().ref();
if (IsNaN(d)) {
@@ -1425,13 +1429,12 @@ void MediaDecoderStateMachine::RecomputeDuration()
// any other duration sources), but the duration isn't ready yet.
return;
}
// We don't fire duration changed for this case because it should have
// already been fired on the main thread when the explicit duration was set.
duration = TimeUnit::FromSeconds(d);
} else if (mEstimatedDuration.Ref().isSome()) {
duration = mEstimatedDuration.Ref().ref();
// Firing the event here is historical, and not necessarily sensical.
if (duration.ToMicroseconds() != GetDuration()) {
fireDurationChanged = true;
}
fireDurationChanged = true;
} else if (mInfo.mMetadataDuration.isSome()) {
duration = mInfo.mMetadataDuration.ref();
} else if (mInfo.mMetadataEndTime.isSome() && mStartTime >= 0) {
@@ -1444,10 +1447,10 @@ void MediaDecoderStateMachine::RecomputeDuration()
if (duration < mObservedDuration.Ref()) {
duration = mObservedDuration;
// Firing the event here is historical, and not necessarily sensical.
fireDurationChanged = true;
}
fireDurationChanged = fireDurationChanged && duration.ToMicroseconds() != GetDuration();
SetDuration(duration);
if (fireDurationChanged) {