Bug 1262053 - part5 : register audio agent immediately when media element starts playing. draft
authorAlastor Wu <alwu@mozilla.com>
Tue, 16 Aug 2016 14:52:44 +0800
changeset 401068 57249caf40f51400bfbf43a8a041403d9f878aa7
parent 401067 e9f6333110e6b087a66b89ad5c353bd4e600a911
child 401069 6a4c29c6292ae2e1d588e947e06e8d3a779324ee
push id26351
push useralwu@mozilla.com
push dateTue, 16 Aug 2016 06:57:30 +0000
bugs1262053
milestone51.0a1
Bug 1262053 - part5 : register audio agent immediately when media element starts playing. In ancient degisn, we would only register audio channel after the media element has audio track and enoguh data to playback, that is because the "audio-playback" event would be dispatched with the registration, and then shows the tab audio indicator. However, now the event dispatching doesn't follow with the registration, it would be triggered when the media element has really audible data which would be notified from media decoder. Therefore, the media element without audio track or without enough data can also register audio channel agent, it won't affect the display of tab audio indicator. The reason we need to do that is for blocking autoplay media in the non-visited tab. The autoplay can be adding "autoplay" keyword or playing by the script, and we don't want to dispatch dom event for blocked media. Therefore, we should register audio channel agent to know whether it needs to be blocked immediately even the media element doesn't have any enough data which can let us to distinguish it have any audio track or not (this information can be known from metadata). First, we must check whether the media is blocked which is notified by audio channel agent, and then we can decide whether need to dispatch the event. If we don't register audio channel agent, that we can't get blocking information. MozReview-Commit-ID: HLLkOuecql1
dom/html/HTMLMediaElement.cpp
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -5396,47 +5396,37 @@ HTMLMediaElement::IsPlayingThroughTheAud
     return false;
   }
 
   // If we have an error, we are not playing.
   if (mError) {
     return false;
   }
 
-  // If this element doesn't have any audio tracks.
-  if (!HasAudio()) {
-    return false;
-  }
-
   // We should consider any bfcached page or inactive document as non-playing.
   if (!IsActive()) {
     return false;
   }
 
   // A loop always is playing
   if (HasAttr(kNameSpaceID_None, nsGkAtoms::loop)) {
     return true;
   }
 
-  // If we are actually playing...
-  if (IsCurrentlyPlaying()) {
-    return true;
-  }
-
   // If we are seeking, we consider it as playing
   if (mPlayingThroughTheAudioChannelBeforeSeek) {
     return true;
   }
 
   // If we are playing an external stream.
   if (mSrcAttrStream) {
     return true;
   }
 
-  return false;
+  return true;
 }
 
 void
 HTMLMediaElement::UpdateAudioChannelPlayingState()
 {
   bool playingThroughTheAudioChannel = IsPlayingThroughTheAudioChannel();
 
   if (playingThroughTheAudioChannel != mPlayingThroughTheAudioChannel) {
@@ -5866,17 +5856,16 @@ HTMLMediaElement::GetTopLevelPrincipal()
   principal = doc->NodePrincipal();
   return principal.forget();
 }
 #endif // MOZ_EME
 
 NS_IMETHODIMP HTMLMediaElement::WindowAudioCaptureChanged(bool aCapture)
 {
   MOZ_ASSERT(mAudioChannelAgent);
-  MOZ_ASSERT(HasAudio());
 
   if (!OwnerDoc()->GetInnerWindow()) {
     return NS_OK;
   }
 
   if (aCapture != mAudioCapturedByWindow) {
     if (aCapture) {
       mAudioCapturedByWindow = true;