Bug 1208316 - A media element should autoplay a MediaStream that becomes active. r?jib draft
authorAndreas Pehrson <pehrsons@gmail.com>
Wed, 14 Sep 2016 10:04:26 +0200
changeset 432210 ab298de858ac460986717d88485189283a441720
parent 432209 02c1dc36a03f05ae8fcba2a8674308ec01d45b65
child 432211 1d634c25a135d37654184fada31440bdfac6def0
push id34233
push userbmo:pehrson@telenordigital.com
push dateTue, 01 Nov 2016 13:21:40 +0000
reviewersjib
bugs1208316
milestone52.0a1
Bug 1208316 - A media element should autoplay a MediaStream that becomes active. r?jib MozReview-Commit-ID: 98H7REtqShI
dom/html/HTMLMediaElement.cpp
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -3991,16 +3991,23 @@ public:
     mElement->NotifyMediaStreamTrackAdded(aTrack);
   }
 
   void NotifyTrackRemoved(const RefPtr<MediaStreamTrack>& aTrack) override
   {
     mElement->NotifyMediaStreamTrackRemoved(aTrack);
   }
 
+  void NotifyActive() override
+  {
+    LOG(LogLevel::Debug, ("%p, mSrcStream %p became active",
+                          mElement, mElement->mSrcStream.get()));
+    mElement->CheckAutoplayDataReady();
+  }
+
   void NotifyInactive() override
   {
     LOG(LogLevel::Debug, ("%p, mSrcStream %p became inactive",
                           mElement, mElement->mSrcStream.get()));
     MOZ_ASSERT(!mElement->mSrcStream->Active());
     if (mElement->mMediaStreamListener) {
       mElement->mMediaStreamListener->Forget();
     }
@@ -4463,16 +4470,22 @@ void HTMLMediaElement::PlaybackEnded()
 
   if (HasAttr(kNameSpaceID_None, nsGkAtoms::loop)) {
     SetCurrentTime(0);
     return;
   }
 
   Pause();
 
+  if (mSrcStream) {
+    // A MediaStream that goes from inactive to active shall be eligible for
+    // autoplay again according to the mediacapture-main spec.
+    mAutoplaying = true;
+  }
+
   FireTimeUpdate(false);
   DispatchAsyncEvent(NS_LITERAL_STRING("ended"));
 }
 
 void HTMLMediaElement::SeekStarted()
 {
   DispatchAsyncEvent(NS_LITERAL_STRING("seeking"));
 }
@@ -4904,19 +4917,20 @@ void HTMLMediaElement::ChangeNetworkStat
   // Changing mNetworkState affects AddRemoveSelfReference().
   AddRemoveSelfReference();
 }
 
 bool HTMLMediaElement::CanActivateAutoplay()
 {
   // For stream inputs, we activate autoplay on HAVE_NOTHING because
   // this element itself might be blocking the stream from making progress by
-  // being paused. We also activate autopaly when playing a media source since
-  // the data download is controlled by the script and there is no way to
-  // evaluate MediaDecoder::CanPlayThrough().
+  // being paused. We only check that it has data by checking its active state.
+  // We also activate autoplay when playing a media source since the data
+  // download is controlled by the script and there is no way to evaluate
+  // MediaDecoder::CanPlayThrough().
 
   if (!HasAttr(kNameSpaceID_None, nsGkAtoms::autoplay) || !mAutoplayEnabled) {
     return false;
   }
 
   if (!mAutoplaying) {
     return false;
   }
@@ -4930,17 +4944,18 @@ bool HTMLMediaElement::CanActivateAutopl
   }
 
   if (mPausedForInactiveDocumentOrChannel) {
     return false;
   }
 
   bool hasData =
     (mDecoder && mReadyState >= nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA) ||
-    mSrcStream || mMediaSource;
+    (mSrcStream && mSrcStream->Active()) ||
+    mMediaSource;
 
   return hasData;
 }
 
 void HTMLMediaElement::CheckAutoplayDataReady()
 {
   if (!CanActivateAutoplay()) {
     return;