Changeset 207338 in webkit


Ignore:
Timestamp:
Oct 14, 2016 7:56:05 AM (8 years ago)
Author:
Chris Dumez
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:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r207337 r207338  
     12016-10-14  Chris Dumez  <cdumez@apple.com>
     2
     3        [Mac] Allow throttling of background tabs that have media elements with no audible audio
     4        https://bugs.webkit.org/show_bug.cgi?id=163402
     5        <rdar://problem/28056151>
     6
     7        Reviewed by Gavin Barraclough.
     8
     9        Allow throttling of background tabs that have media elements with no audible audio.
     10        We were taking an media assertion from the PageThrottler as soon as there was a
     11        media element playing on the page. This prevented throttling of background tabs
     12        even if those media elements had no audible audio, which was unfortunate.
     13
     14        We now have more fine-grained rules for when HTMLMediaElement should take an
     15        assertion. I also added release logging to help debug such issues in the
     16        future.
     17
     18        * html/HTMLMediaElement.cpp:
     19        (WebCore::HTMLMediaElement::setMuted):
     20        (WebCore::HTMLMediaElement::updateVolume):
     21        (WebCore::HTMLMediaElement::updatePlayState):
     22        (WebCore::HTMLMediaElement::updateAudioAssertionState):
     23        (WebCore::HTMLMediaElement::effectiveMuted): Deleted.
     24        * html/HTMLMediaElement.h:
     25
    1262016-10-14  Romain Bellessort  <romain.bellessort@crf.canon.fr>
    227
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r207159 r207338  
    33343334
    33353335    scheduleUpdatePlaybackControlsManager();
     3336    updateAudioAssertionState();
    33363337}
    33373338
     
    48534854        mediaControls()->changedVolume();
    48544855#endif
     4856
     4857    updateAudioAssertionState();
    48554858}
    48564859
     
    48724875        if (hasMediaControls())
    48734876            mediaControls()->playbackStopped();
    4874         m_activityToken = nullptr;
     4877        updateAudioAssertionState();
    48754878        return;
    48764879    }
     
    49104913        if (hasMediaControls())
    49114914            mediaControls()->playbackStarted();
    4912         if (document().page())
    4913             m_activityToken = document().page()->pageThrottler().mediaActivityToken();
    49144915
    49154916        startPlaybackProgressTimer();
     
    49334934        if (hasMediaControls())
    49344935            mediaControls()->playbackStopped();
    4935         m_activityToken = nullptr;
    49364936    }
    49374937   
     
    49414941    m_hasEverHadAudio |= hasAudio();
    49424942    m_hasEverHadVideo |= hasVideo();
     4943
     4944    updateAudioAssertionState();
    49434945}
    49444946
     
    70017003}
    70027004
     7005void HTMLMediaElement::updateAudioAssertionState()
     7006{
     7007    auto* page = document().page();
     7008    if (!page) {
     7009        m_audioActivityToken = nullptr;
     7010        return;
     7011    }
     7012
     7013#define RELEASE_AUDIO_TOKEN(REASON) \
     7014    RELEASE_LOG_IF(page->isAlwaysOnLoggingAllowed() && m_audioActivityToken, Media, "%p - HTMLMediaElement releases audio activity token, reason: " REASON, this); \
     7015    m_audioActivityToken = nullptr
     7016
     7017    if (!hasAudio()) {
     7018        RELEASE_AUDIO_TOKEN("No audio");
     7019        return;
     7020    }
     7021    if (!isPlaying()) {
     7022        RELEASE_AUDIO_TOKEN("Not playing");
     7023        return;
     7024    }
     7025    if (effectiveMuted()) {
     7026        RELEASE_AUDIO_TOKEN("Audio is muted");
     7027        return;
     7028    }
     7029    if (!volume()) {
     7030        RELEASE_AUDIO_TOKEN("Volume is 0");
     7031        return;
     7032    }
     7033    if (!m_audioActivityToken) {
     7034        RELEASE_LOG_IF(page->isAlwaysOnLoggingAllowed(), Media, "%p - HTMLMediaElement takes audio activity token because there is audible audio", this);
     7035        m_audioActivityToken = page->pageThrottler().mediaActivityToken();
     7036    }
     7037
     7038#undef RELEASE_AUDIO_TOKEN
     7039}
     7040
    70037041bool HTMLMediaElement::doesHaveAttribute(const AtomicString& attribute, AtomicString* value) const
    70047042{
  • trunk/Source/WebCore/html/HTMLMediaElement.h

    r206983 r207338  
    770770    bool effectiveMuted() const;
    771771
     772    void updateAudioAssertionState();
     773
    772774    void registerWithDocument(Document&);
    773775    void unregisterWithDocument(Document&);
     
    10061008
    10071009    std::unique_ptr<MediaElementSession> m_mediaSession;
    1008     PageActivityAssertionToken m_activityToken;
     1010    PageActivityAssertionToken m_audioActivityToken;
    10091011    size_t m_reportedExtraMemoryCost;
    10101012
Note: See TracChangeset for help on using the changeset viewer.