Bug 1262053 - part5 : register audio agent immediately when media element starts playing. r=baku
authorAlastor Wu <alwu@mozilla.com>
Mon, 29 Aug 2016 16:34:31 +0800
changeset 407056 4e9367f90eb392d6dc5eae948b100cd6a5c88cbd
parent 407055 4fcb251723210c0af84f5f952ce9cdbacddaaafa
child 407057 e7a17f7ee53da1765679bcf1629f97a03b41e229
push id27893
push userbmo:gasolin@mozilla.com
push dateTue, 30 Aug 2016 03:41:38 +0000
reviewersbaku
bugs1262053
milestone51.0a1
Bug 1262053 - part5 : register audio agent immediately when media element starts playing. r=baku 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
@@ -5760,47 +5760,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) {
@@ -6251,17 +6241,16 @@ HTMLMediaElement::CannotDecryptWaitingFo
     // No need to explicitly suspend playback, it happens automatically when
     // it's starving for decoded frames.
   }
 }
 
 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;