⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 276222 in webkit


Ignore:
Timestamp:
Apr 17, 2021, 10:23:02 PM (5 years ago)
Author:
Chris Dumez
Message:

GPUConnectionToWebProcess::allowsExitUnderMemoryPressure() should check if libWebRTCCodecsProxy is used
https://bugs.webkit.org/show_bug.cgi?id=224709

Reviewed by Darin Adler.

Source/WebKit:

If the libWebRTCCodecsProxy has either encoders or decoders then the GPUProcess should not
exit under memory pressure, since it is not idle.

  • GPUProcess/GPUConnectionToWebProcess.cpp:

(WebKit::GPUConnectionToWebProcess::allowsExitUnderMemoryPressure const):

  • GPUProcess/webrtc/LibWebRTCCodecsProxy.h:
  • GPUProcess/webrtc/LibWebRTCCodecsProxy.mm:

(WebKit::LibWebRTCCodecsProxy::createH264Decoder):
(WebKit::LibWebRTCCodecsProxy::createH265Decoder):
(WebKit::LibWebRTCCodecsProxy::createVP9Decoder):
(WebKit::LibWebRTCCodecsProxy::releaseDecoder):
(WebKit::LibWebRTCCodecsProxy::createEncoder):
(WebKit::LibWebRTCCodecsProxy::releaseEncoder):
(WebKit::LibWebRTCCodecsProxy::updateHasEncodersOrDecoders):
(WebKit::LibWebRTCCodecsProxy::allowsExitUnderMemoryPressure const):
Use a std::atomic<bool> to determine if the LibWebRTCCodecsProxy has encoders/decoders since
allowsExitUnderMemoryPressure() gets called on the main thread but m_encoders / m_decoders
get updated on a background thread.

Tools:

Add API test coverage.

  • TestWebKitAPI/Tests/WebKitCocoa/GPUProcess.mm:

(runMemoryPressureExitTest):
(waitUntilCaptureState):
(TEST):

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r276221 r276222  
     12021-04-17  Chris Dumez  <cdumez@apple.com>
     2
     3        GPUConnectionToWebProcess::allowsExitUnderMemoryPressure() should check if libWebRTCCodecsProxy is used
     4        https://bugs.webkit.org/show_bug.cgi?id=224709
     5
     6        Reviewed by Darin Adler.
     7
     8        If the libWebRTCCodecsProxy has either encoders or decoders then the GPUProcess should not
     9        exit under memory pressure, since it is not idle.
     10
     11        * GPUProcess/GPUConnectionToWebProcess.cpp:
     12        (WebKit::GPUConnectionToWebProcess::allowsExitUnderMemoryPressure const):
     13        * GPUProcess/webrtc/LibWebRTCCodecsProxy.h:
     14        * GPUProcess/webrtc/LibWebRTCCodecsProxy.mm:
     15        (WebKit::LibWebRTCCodecsProxy::createH264Decoder):
     16        (WebKit::LibWebRTCCodecsProxy::createH265Decoder):
     17        (WebKit::LibWebRTCCodecsProxy::createVP9Decoder):
     18        (WebKit::LibWebRTCCodecsProxy::releaseDecoder):
     19        (WebKit::LibWebRTCCodecsProxy::createEncoder):
     20        (WebKit::LibWebRTCCodecsProxy::releaseEncoder):
     21        (WebKit::LibWebRTCCodecsProxy::updateHasEncodersOrDecoders):
     22        (WebKit::LibWebRTCCodecsProxy::allowsExitUnderMemoryPressure const):
     23        Use a std::atomic<bool> to determine if the LibWebRTCCodecsProxy has encoders/decoders since
     24        allowsExitUnderMemoryPressure() gets called on the main thread but m_encoders / m_decoders
     25        get updated on a background thread.
     26
    1272021-04-17  Kimmo Kinnunen  <kkinnunen@apple.com>
    228
  • trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp

    r276148 r276222  
    308308        return false;
    309309#endif
     310#if PLATFORM(COCOA) && USE(LIBWEBRTC)
     311    if (!m_libWebRTCCodecsProxy->allowsExitUnderMemoryPressure())
     312        return false;
     313#endif
    310314    return true;
    311315}
  • trunk/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.h

    r270573 r276222  
    6060    void close();
    6161
     62    bool allowsExitUnderMemoryPressure() const;
     63
    6264private:
    6365    explicit LibWebRTCCodecsProxy(GPUConnectionToWebProcess&);
     
    8183    void setEncodeRates(RTCEncoderIdentifier, uint32_t bitRate, uint32_t frameRate);
    8284
     85    void updateHasEncodersOrDecoders();
     86
    8387    CFDictionaryRef ioSurfacePixelBufferCreationOptions(IOSurfaceRef);
    8488
     
    8690    HashMap<RTCDecoderIdentifier, webrtc::LocalDecoder> m_decoders;
    8791    HashMap<RTCEncoderIdentifier, webrtc::LocalEncoder> m_encoders;
     92    std::atomic<bool> m_hasEncodersOrDecoders;
    8893
    8994    Ref<WorkQueue> m_queue;
  • trunk/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.mm

    r270905 r276222  
    7979            connection->send(Messages::LibWebRTCCodecs::CompletedDecoding { identifier, timeStamp, *sample }, 0);
    8080    }).get()));
     81    updateHasEncodersOrDecoders();
    8182}
    8283
     
    8889            connection->send(Messages::LibWebRTCCodecs::CompletedDecoding { identifier, timeStamp, *sample }, 0);
    8990    }).get()));
     91    updateHasEncodersOrDecoders();
    9092}
    9193
     
    9799            connection->send(Messages::LibWebRTCCodecs::CompletedDecoding { identifier, timeStamp, *sample }, 0);
    98100    }).get()));
     101    updateHasEncodersOrDecoders();
    99102}
    100103
     
    102105{
    103106    ASSERT(m_decoders.contains(identifier));
    104     if (auto decoder = m_decoders.take(identifier))
     107    if (auto decoder = m_decoders.take(identifier)) {
    105108        webrtc::releaseLocalDecoder(decoder);
     109        updateHasEncodersOrDecoders();
     110    }
    106111}
    107112
     
    140145    webrtc::setLocalEncoderLowLatency(encoder, useLowLatency);
    141146    m_encoders.add(identifier, encoder);
     147    updateHasEncodersOrDecoders();
    142148}
    143149
     
    145151{
    146152    ASSERT(m_encoders.contains(identifier));
    147     if (auto encoder = m_encoders.take(identifier))
     153    if (auto encoder = m_encoders.take(identifier)) {
    148154        webrtc::releaseLocalEncoder(encoder);
     155        updateHasEncodersOrDecoders();
     156    }
    149157}
    150158
     
    200208}
    201209
     210void LibWebRTCCodecsProxy::updateHasEncodersOrDecoders()
     211{
     212    m_hasEncodersOrDecoders = !m_encoders.isEmpty() || !m_decoders.isEmpty();
     213}
     214
     215bool LibWebRTCCodecsProxy::allowsExitUnderMemoryPressure() const
     216{
     217    return !m_hasEncodersOrDecoders;
     218}
     219
    202220}
    203221
  • trunk/Tools/ChangeLog

    r276219 r276222  
     12021-04-17  Chris Dumez  <cdumez@apple.com>
     2
     3        GPUConnectionToWebProcess::allowsExitUnderMemoryPressure() should check if libWebRTCCodecsProxy is used
     4        https://bugs.webkit.org/show_bug.cgi?id=224709
     5
     6        Reviewed by Darin Adler.
     7
     8        Add API test coverage.
     9
     10        * TestWebKitAPI/Tests/WebKitCocoa/GPUProcess.mm:
     11        (runMemoryPressureExitTest):
     12        (waitUntilCaptureState):
     13        (TEST):
     14
    1152021-04-17  Wenson Hsieh  <wenson_hsieh@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/GPUProcess.mm

    r276189 r276222  
    2929#import "TestNavigationDelegate.h"
    3030#import "TestWKWebView.h"
     31#import "UserMediaCaptureUIDelegate.h"
    3132#import <WebKit/WKPreferencesPrivate.h>
    3233#import <WebKit/WKPreferencesRefPrivate.h>
     
    3435#import <WebKit/WKString.h>
    3536#import <WebKit/WKWebViewConfiguration.h>
     37#import <WebKit/WKWebViewConfigurationPrivate.h>
    3638#import <WebKit/WKWebViewPrivate.h>
    3739#import <notify.h>
     
    494496}
    495497
    496 static void runMemoryPressureExitTest(Function<void(WKWebView *)>&& loadTestPageSynchronously)
     498static void runMemoryPressureExitTest(Function<void(WKWebView *)>&& loadTestPageSynchronously, Function<void(WKWebViewConfiguration *)>&& updateConfiguration = [](WKWebViewConfiguration *) { })
    497499{
    498500    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
    499501    WKPreferencesSetBoolValueForKeyForTesting((__bridge WKPreferencesRef)[configuration preferences], true, WKStringCreateWithUTF8CString("UseGPUProcessForMediaEnabled"));
    500502    WKPreferencesSetBoolValueForKeyForTesting((__bridge WKPreferencesRef)[configuration preferences], true, WKStringCreateWithUTF8CString("CaptureVideoInGPUProcessEnabled"));
     503    WKPreferencesSetBoolValueForKeyForTesting((__bridge WKPreferencesRef)[configuration preferences], true, WKStringCreateWithUTF8CString("CaptureAudioInGPUProcessEnabled"));
     504    WKPreferencesSetBoolValueForKeyForTesting((__bridge WKPreferencesRef)[configuration preferences], true, WKStringCreateWithUTF8CString("WebRTCPlatformCodecsInGPUProcessEnabled"));
     505    WKPreferencesSetBoolValueForKeyForTesting((__bridge WKPreferencesRef)[configuration preferences], false, WKStringCreateWithUTF8CString("CaptureAudioInUIProcessEnabled"));
    501506    WKPreferencesSetBoolValueForKeyForTesting((__bridge WKPreferencesRef)[configuration preferences], true, WKStringCreateWithUTF8CString("UseGPUProcessForCanvasRenderingEnabled"));
    502507    WKPreferencesSetBoolValueForKeyForTesting((__bridge WKPreferencesRef)[configuration preferences], false, WKStringCreateWithUTF8CString("UseGPUProcessForDOMRenderingEnabled"));
     508
     509    updateConfiguration(configuration.get());
    503510
    504511    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 400, 400) configuration:configuration.get()]);
     
    566573}
    567574
     575#if ENABLE(MEDIA_STREAM)
     576static bool waitUntilCaptureState(WKWebView *webView, _WKMediaCaptureStateDeprecated expectedState)
     577{
     578    NSTimeInterval end = [[NSDate date] timeIntervalSinceReferenceDate] + 10;
     579    do {
     580        if ([webView _mediaCaptureState] == expectedState)
     581            return true;
     582
     583        TestWebKitAPI::Util::spinRunLoop(1);
     584
     585        if ([[NSDate date] timeIntervalSinceReferenceDate] > end)
     586            break;
     587    } while (true);
     588
     589    return false;
     590}
     591
     592TEST(GPUProcess, ExitsUnderMemoryPressureWebRTCCase)
     593{
     594    runMemoryPressureExitTest([](WKWebView *webView) {
     595        auto delegate = adoptNS([[UserMediaCaptureUIDelegate alloc] init]);
     596        webView.UIDelegate = delegate.get();
     597
     598        [webView loadTestPageNamed:@"getUserMedia"];
     599        EXPECT_TRUE(waitUntilCaptureState(webView, _WKMediaCaptureStateDeprecatedActiveCamera));
     600        [webView stringByEvaluatingJavaScript:@"captureAudioAndVideo(true)"];
     601        [webView stringByEvaluatingJavaScript:@"createConnection()"];
     602    }, [](WKWebViewConfiguration* configuration) {
     603        auto preferences = configuration.preferences;
     604        preferences._mediaCaptureRequiresSecureConnection = NO;
     605        configuration._mediaCaptureEnabled = YES;
     606        preferences._mockCaptureDevicesEnabled = YES;
     607    });
     608}
     609#endif // ENABLE(MEDIA_STREAM)
     610
    568611TEST(GPUProcess, ExitsUnderMemoryPressureWebAudioCase)
    569612{
Note: See TracChangeset for help on using the changeset viewer.