Title: [207338] trunk/Source/WebCore
Revision
207338
Author
cdu...@apple.com
Date
2016-10-14 07:56:05 -0700 (Fri, 14 Oct 2016)

Log Message

[Mac] Allow throttling of background tabs that have media elements with no audible audio
https://bugs.webkit.org/show_bug.cgi?id=163402
<rdar://problem/28056151>

Reviewed by Gavin Barraclough.

Allow throttling of background tabs that have media elements with no audible audio.
We were taking an media assertion from the PageThrottler as soon as there was a
media element playing on the page. This prevented throttling of background tabs
even if those media elements had no audible audio, which was unfortunate.

We now have more fine-grained rules for when HTMLMediaElement should take an
assertion. I also added release logging to help debug such issues in the
future.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::setMuted):
(WebCore::HTMLMediaElement::updateVolume):
(WebCore::HTMLMediaElement::updatePlayState):
(WebCore::HTMLMediaElement::updateAudioAssertionState):
(WebCore::HTMLMediaElement::effectiveMuted): Deleted.
* html/HTMLMediaElement.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (207337 => 207338)


--- trunk/Source/WebCore/ChangeLog	2016-10-14 14:09:45 UTC (rev 207337)
+++ trunk/Source/WebCore/ChangeLog	2016-10-14 14:56:05 UTC (rev 207338)
@@ -1,3 +1,28 @@
+2016-10-14  Chris Dumez  <cdu...@apple.com>
+
+        [Mac] Allow throttling of background tabs that have media elements with no audible audio
+        https://bugs.webkit.org/show_bug.cgi?id=163402
+        <rdar://problem/28056151>
+
+        Reviewed by Gavin Barraclough.
+
+        Allow throttling of background tabs that have media elements with no audible audio.
+        We were taking an media assertion from the PageThrottler as soon as there was a
+        media element playing on the page. This prevented throttling of background tabs
+        even if those media elements had no audible audio, which was unfortunate.
+
+        We now have more fine-grained rules for when HTMLMediaElement should take an
+        assertion. I also added release logging to help debug such issues in the
+        future.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::setMuted):
+        (WebCore::HTMLMediaElement::updateVolume):
+        (WebCore::HTMLMediaElement::updatePlayState):
+        (WebCore::HTMLMediaElement::updateAudioAssertionState):
+        (WebCore::HTMLMediaElement::effectiveMuted): Deleted.
+        * html/HTMLMediaElement.h:
+
 2016-10-14  Romain Bellessort  <romain.belless...@crf.canon.fr>
 
         [Readable Streams API] Cleanup patch, fix small inconsistencies

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (207337 => 207338)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2016-10-14 14:09:45 UTC (rev 207337)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2016-10-14 14:56:05 UTC (rev 207338)
@@ -3333,6 +3333,7 @@
     }
 
     scheduleUpdatePlaybackControlsManager();
+    updateAudioAssertionState();
 }
 
 void HTMLMediaElement::togglePlayState()
@@ -4852,6 +4853,8 @@
     if (hasMediaControls())
         mediaControls()->changedVolume();
 #endif
+
+    updateAudioAssertionState();
 }
 
 void HTMLMediaElement::updatePlayState(UpdateState updateState)
@@ -4871,7 +4874,7 @@
         m_playbackProgressTimer.stop();
         if (hasMediaControls())
             mediaControls()->playbackStopped();
-        m_activityToken = nullptr;
+        updateAudioAssertionState();
         return;
     }
     
@@ -4909,8 +4912,6 @@
 
         if (hasMediaControls())
             mediaControls()->playbackStarted();
-        if (document().page())
-            m_activityToken = document().page()->pageThrottler().mediaActivityToken();
 
         startPlaybackProgressTimer();
         setPlaying(true);
@@ -4932,7 +4933,6 @@
 
         if (hasMediaControls())
             mediaControls()->playbackStopped();
-        m_activityToken = nullptr;
     }
     
     updateMediaController();
@@ -4940,6 +4940,8 @@
 
     m_hasEverHadAudio |= hasAudio();
     m_hasEverHadVideo |= hasVideo();
+
+    updateAudioAssertionState();
 }
 
 void HTMLMediaElement::setPlaying(bool playing)
@@ -7000,6 +7002,42 @@
     return muted() || (document().page() && document().page()->isMuted());
 }
 
+void HTMLMediaElement::updateAudioAssertionState()
+{
+    auto* page = document().page();
+    if (!page) {
+        m_audioActivityToken = nullptr;
+        return;
+    }
+
+#define RELEASE_AUDIO_TOKEN(REASON) \
+    RELEASE_LOG_IF(page->isAlwaysOnLoggingAllowed() && m_audioActivityToken, Media, "%p - HTMLMediaElement releases audio activity token, reason: " REASON, this); \
+    m_audioActivityToken = nullptr
+
+    if (!hasAudio()) {
+        RELEASE_AUDIO_TOKEN("No audio");
+        return;
+    }
+    if (!isPlaying()) {
+        RELEASE_AUDIO_TOKEN("Not playing");
+        return;
+    }
+    if (effectiveMuted()) {
+        RELEASE_AUDIO_TOKEN("Audio is muted");
+        return;
+    }
+    if (!volume()) {
+        RELEASE_AUDIO_TOKEN("Volume is 0");
+        return;
+    }
+    if (!m_audioActivityToken) {
+        RELEASE_LOG_IF(page->isAlwaysOnLoggingAllowed(), Media, "%p - HTMLMediaElement takes audio activity token because there is audible audio", this);
+        m_audioActivityToken = page->pageThrottler().mediaActivityToken();
+    }
+
+#undef RELEASE_AUDIO_TOKEN
+}
+
 bool HTMLMediaElement::doesHaveAttribute(const AtomicString& attribute, AtomicString* value) const
 {
     QualifiedName attributeName(nullAtom, attribute, nullAtom);

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (207337 => 207338)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2016-10-14 14:09:45 UTC (rev 207337)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2016-10-14 14:56:05 UTC (rev 207338)
@@ -769,6 +769,8 @@
 
     bool effectiveMuted() const;
 
+    void updateAudioAssertionState();
+
     void registerWithDocument(Document&);
     void unregisterWithDocument(Document&);
 
@@ -1005,7 +1007,7 @@
 #endif
 
     std::unique_ptr<MediaElementSession> m_mediaSession;
-    PageActivityAssertionToken m_activityToken;
+    PageActivityAssertionToken m_audioActivityToken;
     size_t m_reportedExtraMemoryCost;
 
 #if ENABLE(MEDIA_CONTROLS_SCRIPT)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to