Bug 1322087 - a squashed patch for Aurora uplift. r=cpearce a=jcristau
authorJW Wang <jwwang@mozilla.com>
Fri, 09 Dec 2016 10:20:40 -1000
changeset 352984 481d62db5b32534b0ca26fef6656cd9bd8194828
parent 352983 5331812b5027d6f236ab7f62baa801c403bc3962
child 352985 563d1d3d7fef691dd8af0bc07d782e736ccd98ca
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce, jcristau
bugs1322087
milestone52.0a2
Bug 1322087 - a squashed patch for Aurora uplift. r=cpearce a=jcristau MozReview-Commit-ID: 77duxxtEAQP
dom/html/HTMLMediaElement.cpp
dom/media/MediaCache.cpp
dom/media/MediaResource.cpp
testing/web-platform/meta/encrypted-media/clearkey-mp4-playback-temporary-multikey-sequential-readyState.html.ini
testing/web-platform/meta/media-source/mediasource-endofstream.html.ini
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -4870,46 +4870,56 @@ HTMLMediaElement::UpdateReadyStateIntern
     // while we are still playing, we need to revert to HAVE_METADATA until
     // a video frame is available.
     LOG(LogLevel::Debug, ("MediaElement %p UpdateReadyStateInternal() "
                           "Playing video but no video frame; Forcing HAVE_METADATA", this));
     ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_METADATA);
     return;
   }
 
-  if (mDownloadSuspendedByCache &&
-      mDecoder && !mDecoder->IsEnded() &&
-      mFirstFrameLoaded) {
+  if (!mFirstFrameLoaded) {
+    // We haven't yet loaded the first frame, making us unable to determine
+    // if we have enough valid data at the present stage.
+    return;
+  }
+
+  if (nextFrameStatus == NEXT_FRAME_UNAVAILABLE_BUFFERING) {
+    // Force HAVE_CURRENT_DATA when buffering.
+    ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA);
+    return;
+  }
+
+  if (mDownloadSuspendedByCache && mDecoder && !mDecoder->IsEnded()) {
     // The decoder has signaled that the download has been suspended by the
     // media cache. So move readyState into HAVE_ENOUGH_DATA, in case there's
     // script waiting for a "canplaythrough" event; without this forced
     // transition, we will never fire the "canplaythrough" event if the
     // media cache is too small, and scripts are bound to fail. Don't force
     // this transition if the decoder is in ended state; the readyState
     // should remain at HAVE_CURRENT_DATA in this case.
     // Note that this state transition includes the case where we finished
     // downloaded the whole data stream.
     LOG(LogLevel::Debug, ("MediaElement %p UpdateReadyStateInternal() "
                           "Decoder download suspended by cache", this));
     ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA);
     return;
   }
 
+  if (mDecoder && !mDecoder->IsEnded() &&
+      !mDecoder->GetResource()->IsExpectingMoreData()) {
+    LOG(LogLevel::Debug, ("MediaElement %p UpdateReadyStateInternal() "
+                          "Decoder fetched all data for media resource", this));
+    ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA);
+    return;
+  }
+
   if (nextFrameStatus != MediaDecoderOwner::NEXT_FRAME_AVAILABLE) {
     LOG(LogLevel::Debug, ("MediaElement %p UpdateReadyStateInternal() "
                           "Next frame not available", this));
-    if (mFirstFrameLoaded) {
-      ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA);
-    }
-    return;
-  }
-
-  if (!mFirstFrameLoaded) {
-    // We haven't yet loaded the first frame, making us unable to determine
-    // if we have enough valid data at the present stage.
+    ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA);
     return;
   }
 
   if (mSrcStream) {
     LOG(LogLevel::Debug, ("MediaElement %p UpdateReadyStateInternal() "
                           "Stream HAVE_ENOUGH_DATA", this));
     ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA);
     return;
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -2191,18 +2191,16 @@ MediaCacheStream::Seek(int32_t aWhence, 
 
   gMediaCache->QueueUpdate();
   return NS_OK;
 }
 
 int64_t
 MediaCacheStream::Tell()
 {
-  NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread");
-
   ReentrantMonitorAutoEnter mon(gMediaCache->GetReentrantMonitor());
   return mStreamOffset;
 }
 
 nsresult
 MediaCacheStream::Read(char* aBuffer, uint32_t aCount, uint32_t* aBytes)
 {
   NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread");
--- a/dom/media/MediaResource.cpp
+++ b/dom/media/MediaResource.cpp
@@ -702,18 +702,16 @@ ChannelMediaResource::MediaReadAt(int64_
     curr += bytesRead;
   }
   bytes->SetLength(curr - start);
   return bytes.forget();
 }
 
 int64_t ChannelMediaResource::Tell()
 {
-  NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread");
-
   return mCacheStream.Tell();
 }
 
 nsresult ChannelMediaResource::GetCachedRanges(MediaByteRangeSet& aRanges)
 {
   return mCacheStream.GetCachedRanges(aRanges);
 }
 
@@ -1471,18 +1469,16 @@ nsresult FileMediaResource::UnsafeSeek(i
   if (!mSeekable)
     return NS_ERROR_FAILURE;
   EnsureSizeInitialized();
   return mSeekable->Seek(aWhence, aOffset);
 }
 
 int64_t FileMediaResource::Tell()
 {
-  NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread");
-
   MutexAutoLock lock(mLock);
   EnsureSizeInitialized();
 
   int64_t offset = 0;
   // Return mSize as offset (end of stream) in case of error
   if (!mSeekable || NS_FAILED(mSeekable->Tell(&offset)))
     return mSize;
   return offset;
--- a/testing/web-platform/meta/encrypted-media/clearkey-mp4-playback-temporary-multikey-sequential-readyState.html.ini
+++ b/testing/web-platform/meta/encrypted-media/clearkey-mp4-playback-temporary-multikey-sequential-readyState.html.ini
@@ -1,9 +1,11 @@
 [clearkey-mp4-playback-temporary-multikey-sequential-readyState.html]
   type: testharness
+  disabled:
+    if (os == "win"): https://bugzilla.mozilla.org/show_bug.cgi?id=1322087
   [org.w3.clearkey, successful playback, temporary, mp4, multiple keys, sequential, readyState]
     expected:
       if not debug and e10s and (os == "win") and (version == "5.1.2600") and (processor == "x86") and (bits == 32): TIMEOUT
       if debug and not e10s and (os == "win") and (version == "5.1.2600") and (processor == "x86") and (bits == 32): TIMEOUT
       if debug and e10s and (os == "win") and (version == "5.1.2600") and (processor == "x86") and (bits == 32): TIMEOUT
       if not debug and not e10s and (os == "win") and (version == "5.1.2600") and (processor == "x86") and (bits == 32): TIMEOUT
 
--- a/testing/web-platform/meta/media-source/mediasource-endofstream.html.ini
+++ b/testing/web-platform/meta/media-source/mediasource-endofstream.html.ini
@@ -1,9 +1,5 @@
 [mediasource-endofstream.html]
   type: testharness
-  expected: TIMEOUT
-  [MediaSource.endOfStream(): media element notified that it now has all of the media data]
-    expected: TIMEOUT
-
   [MediaSource.endOfStream(): duration and buffered range end time before and after endOfStream]
     expected: FAIL