Bug 1119757 - MSE: handle duration of 0 in metadata as infinity. r=mattwoodrow, a=sledru
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 16 Jan 2015 23:49:01 +1100
changeset 242931 3e5d8c21f3a2
parent 242930 b0c42a7f0dc7
child 242932 2a36e0243edd
push id4342
push userryanvm@gmail.com
push date2015-01-20 16:03 +0000
treeherdermozilla-beta@fae52bd681e0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow, sledru
bugs1119757
milestone36.0
Bug 1119757 - MSE: handle duration of 0 in metadata as infinity. r=mattwoodrow, a=sledru
dom/media/mediasource/MediaSourceDecoder.cpp
dom/media/mediasource/MediaSourceReader.cpp
--- a/dom/media/mediasource/MediaSourceDecoder.cpp
+++ b/dom/media/mediasource/MediaSourceDecoder.cpp
@@ -209,32 +209,40 @@ MediaSourceDecoder::SetDecodedDuration(i
 {
   // Only use the decoded duration if one wasn't already
   // set.
   ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
   if (!mMediaSource || !IsNaN(mMediaSourceDuration)) {
     return;
   }
   double duration = aDuration;
-  duration /= USECS_PER_S;
+  // A duration of -1 is +Infinity.
+  if (aDuration >= 0) {
+    duration /= USECS_PER_S;
+  }
   SetMediaSourceDuration(duration);
 }
 
 void
 MediaSourceDecoder::SetMediaSourceDuration(double aDuration)
 {
   ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
   double oldDuration = mMediaSourceDuration;
-  mMediaSourceDuration = aDuration;
-  mDecoderStateMachine->SetDuration(aDuration * USECS_PER_S);
+  if (aDuration >= 0) {
+    mDecoderStateMachine->SetDuration(aDuration * USECS_PER_S);
+    mMediaSourceDuration = aDuration;
+  } else {
+    mDecoderStateMachine->SetDuration(INT64_MAX);
+    mMediaSourceDuration = PositiveInfinity<double>();
+  }
   if (NS_IsMainThread()) {
-    DurationChanged(oldDuration, aDuration);
+    DurationChanged(oldDuration, mMediaSourceDuration);
   } else {
     nsRefPtr<nsIRunnable> task =
-      new DurationChangedRunnable(this, oldDuration, aDuration);
+      new DurationChangedRunnable(this, oldDuration, mMediaSourceDuration);
     NS_DispatchToMainThread(task);
   }
 }
 
 double
 MediaSourceDecoder::GetMediaSourceDuration()
 {
   ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
--- a/dom/media/mediasource/MediaSourceReader.cpp
+++ b/dom/media/mediasource/MediaSourceReader.cpp
@@ -820,19 +820,21 @@ MediaSourceReader::ReadMetadata(MediaInf
     const MediaInfo& info = mVideoReader->GetMediaInfo();
     MOZ_ASSERT(info.HasVideo());
     mInfo.mVideo = info.mVideo;
     maxDuration = std::max(maxDuration, mVideoReader->GetDecoder()->GetMediaDuration());
     MSE_DEBUG("MediaSourceReader(%p)::ReadMetadata video reader=%p maxDuration=%lld",
               this, mVideoReader.get(), maxDuration);
   }
 
-  if (maxDuration != -1) {
-    static_cast<MediaSourceDecoder*>(mDecoder)->SetDecodedDuration(maxDuration);
+  if (!maxDuration) {
+    // Treat a duration of 0 as infinity
+    maxDuration = -1;
   }
+  static_cast<MediaSourceDecoder*>(mDecoder)->SetDecodedDuration(maxDuration);
 
   *aInfo = mInfo;
   *aTags = nullptr; // TODO: Handle metadata.
 
   return NS_OK;
 }
 
 void