Changeset 247118 in webkit


Ignore:
Timestamp:
Jul 3, 2019 5:08:00 PM (5 years ago)
Author:
jer.noble@apple.com
Message:

HTMLMediaElement can hold onto display sleep assertion while process is suspended.
https://bugs.webkit.org/show_bug.cgi?id=199471
<rdar://problem/52124320>

If the WebContent process is suspended before HTMLMediaElement gets a callback telling it
that the MediaPlayer has stopped playing, the SleepDisabler may stay set (and hold a display
or system sleep assertion) for the entire duration the process is suspended, causing excess
power drain.

Add a PlatformMediaSessionClient method (and an implementation in HTMLMediaElement) which will
be called during the preperation for process suspension, and in this callback, clear the
SleepDisabler token.

Reviewed by Eric Carlson.

  • html/HTMLMediaElement.cpp:

(WebCore::HTMLMediaElement::shouldDisableSleep const):
(WebCore::HTMLMediaElement::processIsSuspendedChanged):

  • html/HTMLMediaElement.h:
  • platform/audio/PlatformMediaSession.h:

(WebCore::PlatformMediaSessionClient::processIsSuspendedChanged):

  • platform/audio/PlatformMediaSessionManager.cpp:

(WebCore::PlatformMediaSessionManager::processWillSuspend):
(WebCore::PlatformMediaSessionManager::processDidResume):

  • platform/audio/PlatformMediaSessionManager.h:

(WebCore::PlatformMediaSessionManager::processIsSuspended const):

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r247117 r247118  
     12019-07-03  Jer Noble  <jer.noble@apple.com>
     2
     3        HTMLMediaElement can hold onto display sleep assertion while process is suspended.
     4        https://bugs.webkit.org/show_bug.cgi?id=199471
     5        <rdar://problem/52124320>
     6
     7        If the WebContent process is suspended before HTMLMediaElement gets a callback telling it
     8        that the MediaPlayer has stopped playing, the SleepDisabler may stay set (and hold a display
     9        or system sleep assertion) for the entire duration the process is suspended, causing excess
     10        power drain.
     11
     12        Add a PlatformMediaSessionClient method (and an implementation in HTMLMediaElement) which will
     13        be called during the preperation for process suspension, and in this callback, clear the
     14        SleepDisabler token.
     15
     16        Reviewed by Eric Carlson.
     17
     18        * html/HTMLMediaElement.cpp:
     19        (WebCore::HTMLMediaElement::shouldDisableSleep const):
     20        (WebCore::HTMLMediaElement::processIsSuspendedChanged):
     21        * html/HTMLMediaElement.h:
     22        * platform/audio/PlatformMediaSession.h:
     23        (WebCore::PlatformMediaSessionClient::processIsSuspendedChanged):
     24        * platform/audio/PlatformMediaSessionManager.cpp:
     25        (WebCore::PlatformMediaSessionManager::processWillSuspend):
     26        (WebCore::PlatformMediaSessionManager::processDidResume):
     27        * platform/audio/PlatformMediaSessionManager.h:
     28        (WebCore::PlatformMediaSessionManager::processIsSuspended const):
     29
    1302019-07-03  Jonathan Bedard  <jbedard@apple.com>
    231
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r246490 r247118  
    69246924#endif
    69256925
     6926    if (PlatformMediaSessionManager::sharedManager().processIsSuspended())
     6927        return SleepType::None;
     6928
    69266929    bool shouldBeAbleToSleep = !hasVideo() || !hasAudio();
    69276930#if ENABLE(MEDIA_STREAM)
     
    77437746    return document().processingUserGestureForMedia();
    77447747}
     7748
     7749void HTMLMediaElement::processIsSuspendedChanged()
     7750{
     7751    updateSleepDisabling();
     7752}
     7753
    77457754#if ENABLE(WIRELESS_PLAYBACK_TARGET)
    77467755
  • trunk/Source/WebCore/html/HTMLMediaElement.h

    r246490 r247118  
    895895    bool processingUserGestureForMedia() const final;
    896896    bool hasMediaStreamSource() const final;
     897    void processIsSuspendedChanged() final;
    897898
    898899    void pageMutedStateDidChange() override;
  • trunk/Source/WebCore/platform/audio/PlatformMediaSession.h

    r245712 r247118  
    260260    virtual bool hasMediaStreamSource() const { return false; }
    261261
     262    virtual void processIsSuspendedChanged() { }
     263
    262264protected:
    263265    virtual ~PlatformMediaSessionClient() = default;
  • trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp

    r245947 r247118  
    369369    m_processIsSuspended = true;
    370370
     371    forEachSession([&] (auto& session) {
     372        session.client().processIsSuspendedChanged();
     373    });
     374
    371375#if USE(AUDIO_SESSION)
    372376    if (m_becameActive && shouldDeactivateAudioSession()) {
     
    384388    m_processIsSuspended = false;
    385389
     390    forEachSession([&] (auto& session) {
     391        session.client().processIsSuspendedChanged();
     392    });
     393
    386394#if USE(AUDIO_SESSION)
    387395    if (!m_becameActive && activeAudioSessionRequired()) {
  • trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.h

    r245947 r247118  
    135135    void forEachMatchingSession(const Function<bool(const PlatformMediaSession&)>& predicate, const Function<void(PlatformMediaSession&)>& matchingCallback);
    136136
     137    bool processIsSuspended() const { return m_processIsSuspended; }
     138
    137139protected:
    138140    friend class PlatformMediaSession;
     
    147149
    148150    AudioHardwareListener* audioHardwareListener() { return m_audioHardwareListener.get(); }
    149 
    150     bool processIsSuspended() const { return m_processIsSuspended; }
    151151
    152152#if !RELEASE_LOG_DISABLED
Note: See TracChangeset for help on using the changeset viewer.