Bug 1172264 - Switch MediaDecoder's mDuration represenation to a double. r=jww
authorBobby Holley <bobbyholley@gmail.com>
Tue, 09 Jun 2015 11:40:03 -0700 (2015-06-09)
changeset 249383 3ead3466f84a2f9b7f6b2ddd47ebd93b425b3691
parent 249382 394c85b4a06b268d66a2af4d8dd23a5d2cd6e23c
child 249384 bc8f5c62dbef51c76a6e3a494840d1546f117fe7
push id61234
push userbobbyholley@gmail.com
push dateWed, 17 Jun 2015 16:49:23 +0000 (2015-06-17)
treeherdermozilla-inbound@a5eb0b1fcf39 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjww
bugs1172264
milestone41.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 1172264 - Switch MediaDecoder's mDuration represenation to a double. r=jww
dom/media/MediaDecoder.cpp
dom/media/MediaDecoder.h
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -302,20 +302,18 @@ void MediaDecoder::AddOutputStream(Proce
 }
 
 double MediaDecoder::GetDuration()
 {
   MOZ_ASSERT(NS_IsMainThread());
   if (mInfiniteStream) {
     return std::numeric_limits<double>::infinity();
   }
-  if (mDuration >= 0) {
-     return static_cast<double>(mDuration) / static_cast<double>(USECS_PER_S);
-  }
-  return std::numeric_limits<double>::quiet_NaN();
+
+  return mDuration;
 }
 
 int64_t MediaDecoder::GetMediaDuration()
 {
   NS_ENSURE_TRUE(GetStateMachine(), -1);
   return GetStateMachine()->GetDuration();
 }
 
@@ -338,17 +336,17 @@ MediaDecoder::MediaDecoder() :
                    "MediaDecoder::mNextFrameStatus (Mirror)"),
   mDecoderPosition(0),
   mPlaybackPosition(0),
   mLogicalPosition(0.0),
   mCurrentPosition(AbstractThread::MainThread(), 0, "MediaDecoder::mCurrentPosition (Mirror)"),
   mVolume(AbstractThread::MainThread(), 0.0, "MediaDecoder::mVolume (Canonical)"),
   mPlaybackRate(AbstractThread::MainThread(), 1.0, "MediaDecoder::mPlaybackRate (Canonical)"),
   mPreservesPitch(AbstractThread::MainThread(), true, "MediaDecoder::mPreservesPitch (Canonical)"),
-  mDuration(-1),
+  mDuration(std::numeric_limits<double>::quiet_NaN()),
   mMediaSeekable(true),
   mSameOriginMedia(false),
   mReentrantMonitor("media.decoder"),
   mEstimatedDuration(AbstractThread::MainThread(), NullableTimeUnit(),
                      "MediaDecoder::mEstimatedDuration (Canonical)"),
   mExplicitDuration(AbstractThread::MainThread(), Maybe<double>(),
                    "MediaDecoder::mExplicitDuration (Canonical)"),
   mPlayState(AbstractThread::MainThread(), PLAY_STATE_LOADING,
@@ -646,25 +644,27 @@ void MediaDecoder::MetadataLoaded(nsAuto
   }
 
   DECODER_LOG("MetadataLoaded, channels=%u rate=%u hasAudio=%d hasVideo=%d",
               aInfo->mAudio.mChannels, aInfo->mAudio.mRate,
               aInfo->HasAudio(), aInfo->HasVideo());
 
   {
     ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
-    mDuration = mDecoderStateMachine ? mDecoderStateMachine->GetDuration() : -1;
+    int64_t stateMachineDuration = mDecoderStateMachine ? mDecoderStateMachine->GetDuration() : -1;
+    if (stateMachineDuration == -1) {
+      SetInfinite(true);
+    } else {
+      mDuration = TimeUnit::FromMicroseconds(stateMachineDuration).ToSeconds();
+    }
+
     // Duration has changed so we should recompute playback rate
     UpdatePlaybackRate();
   }
 
-  if (mDuration == -1) {
-    SetInfinite(true);
-  }
-
   mInfo = aInfo.forget();
   ConstructMediaTracks();
 
   if (mOwner) {
     // Make sure the element and the frame (if any) are told about
     // our new size.
     Invalidate();
     if (aEventVisibility != MediaDecoderEventVisibility::Suppressed) {
@@ -863,19 +863,19 @@ MediaDecoder::GetStatistics()
 }
 
 double MediaDecoder::ComputePlaybackRate(bool* aReliable)
 {
   GetReentrantMonitor().AssertCurrentThreadIn();
   MOZ_ASSERT(NS_IsMainThread() || OnStateMachineTaskQueue() || OnDecodeTaskQueue());
 
   int64_t length = mResource ? mResource->GetLength() : -1;
-  if (mDuration >= 0 && length >= 0) {
+  if (!IsNaN(mDuration) && !mozilla::IsInfinite<double>(mDuration) && length >= 0) {
     *aReliable = true;
-    return length * static_cast<double>(USECS_PER_S) / mDuration;
+    return length * mDuration;
   }
   return mPlaybackStatistics->GetRateAtLastStop(aReliable);
 }
 
 void MediaDecoder::UpdatePlaybackRate()
 {
   MOZ_ASSERT(NS_IsMainThread() || OnStateMachineTaskQueue());
   GetReentrantMonitor().AssertCurrentThreadIn();
@@ -1076,25 +1076,23 @@ void MediaDecoder::UpdateLogicalPosition
     FireTimeUpdate();
   }
 }
 
 void MediaDecoder::DurationChanged(TimeUnit aNewDuration)
 {
   MOZ_ASSERT(NS_IsMainThread());
   ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
-  int64_t oldDuration = mDuration;
-  mDuration = aNewDuration.ToMicroseconds();
+  double oldDuration = mDuration;
+  mDuration = aNewDuration.ToSeconds();
   // Duration has changed so we should recompute playback rate
   UpdatePlaybackRate();
 
-  SetInfinite(mDuration == -1);
-
   if (mOwner && oldDuration != mDuration && !IsInfinite()) {
-    DECODER_LOG("Duration changed to %lld", mDuration);
+    DECODER_LOG("Duration changed to %f", mDuration);
     mOwner->DispatchAsyncEvent(NS_LITERAL_STRING("durationchange"));
   }
 
   if (CurrentPosition() > aNewDuration.ToMicroseconds()) {
     Seek(aNewDuration.ToSeconds(), SeekTarget::Accurate);
   }
 }
 
--- a/dom/media/MediaDecoder.h
+++ b/dom/media/MediaDecoder.h
@@ -938,20 +938,18 @@ public:
   AbstractCanonical<double>* CanonicalPlaybackRate() { return &mPlaybackRate; }
 protected:
 
   Canonical<bool> mPreservesPitch;
 public:
   AbstractCanonical<bool>* CanonicalPreservesPitch() { return &mPreservesPitch; }
 protected:
 
-  // Duration of the media resource. Set to -1 if unknown.
-  // Set when the metadata is loaded. Accessed on the main thread
-  // only.
-  int64_t mDuration;
+  // Official duration of the media resource as observed by script.
+  double mDuration;
 
   // True if the media is seekable (i.e. supports random access).
   bool mMediaSeekable;
 
   // True if the media is same-origin with the element. Data can only be
   // passed to MediaStreams when this is true.
   bool mSameOriginMedia;