Bug 1120282: Do not fire durationchange during call to ReadMetadata. r=mattwoodrow
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 16 Jan 2015 23:49:02 +1100
changeset 224167 797403411392892f0ca64e062bd6543f916a5e84
parent 224166 1532023f986d18b20ae5d163956912c904b68731
child 224168 acc9dcd07546c13e4ddafe04f36b9069b1ed38e9
push id54147
push userjyavenard@mozilla.com
push dateFri, 16 Jan 2015 12:54:44 +0000
treeherdermozilla-inbound@797403411392 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1120282
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1120282: Do not fire durationchange during call to ReadMetadata. r=mattwoodrow
dom/media/mediasource/MediaSourceDecoder.cpp
dom/media/mediasource/MediaSourceDecoder.h
--- a/dom/media/mediasource/MediaSourceDecoder.cpp
+++ b/dom/media/mediasource/MediaSourceDecoder.cpp
@@ -213,46 +213,59 @@ MediaSourceDecoder::SetDecodedDuration(i
   if (!mMediaSource || !IsNaN(mMediaSourceDuration)) {
     return;
   }
   double duration = aDuration;
   // A duration of -1 is +Infinity.
   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
 MediaSourceDecoder::SetMediaSourceDuration(double aDuration, MSRangeRemovalAction aAction)
 {
   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;
   } else {
     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);
     }
   }
 }
 
 double
 MediaSourceDecoder::GetMediaSourceDuration()
 {
--- a/dom/media/mediasource/MediaSourceDecoder.h
+++ b/dom/media/mediasource/MediaSourceDecoder.h
@@ -75,16 +75,21 @@ public:
 
   MediaSourceReader* GetReader() { return mReader; }
 
   // Returns true if aReader is a currently active audio or video
   // reader in this decoders MediaSourceReader.
   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.
   dom::MediaSource* mMediaSource;
   nsRefPtr<MediaSourceReader> mReader;
 
   // Protected by GetReentrantMonitor()
   double mMediaSourceDuration;