Changeset 213190 in webkit


Ignore:
Timestamp:
Feb 28, 2017 4:07:23 PM (7 years ago)
Author:
achristensen@apple.com
Message:

LibWebRTCProvider should check existence of libwebrtc.dylib
https://bugs.webkit.org/show_bug.cgi?id=168986
Source/WebCore:

<rdar://problem/30735413>

Reviewed by Youenn Fablet.

Some configurations of the webrtc tests overwrite the availability of WebRTC in order to test it
with MockLibWebRTCPeerConnection. If the dylib can not be found, we can't use it, so we want to
fail these tests rather than crashing calling rtc::LogMessage::LogToDebug.

  • Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:

(WebCore::LibWebRTCMediaEndpoint::doCreateOffer):
(WebCore::LibWebRTCMediaEndpoint::doCreateAnswer):

  • platform/mediastream/libwebrtc/LibWebRTCProvider.cpp:

(WebCore::LibWebRTCProvider::factory):
(WebCore::LibWebRTCProvider::webRTCAvailable):

  • platform/mediastream/libwebrtc/LibWebRTCProvider.h:
  • testing/MockLibWebRTCPeerConnection.cpp:

(WebCore::useMockRTCPeerConnectionFactory):
(WebCore::MockLibWebRTCPeerConnectionFactory::CreatePeerConnection):

Source/WebKit2:

Reviewed by Youenn Fablet.

  • Shared/WebPreferencesDefinitions.h:
  • Shared/WebPreferencesStore.cpp:
  • UIProcess/WebPreferences.cpp:

(WebKit::checkWebRTCAvailability): Deleted.

Location:
trunk/Source
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/CMakeLists.txt

    r213149 r213190  
    23012301    platform/mediastream/SDPProcessorScriptResource.cpp
    23022302
     2303    platform/mediastream/libwebrtc/LibWebRTCProvider.cpp
     2304
    23032305    platform/mock/DeviceOrientationClientMock.cpp
    23042306    platform/mock/GeolocationClientMock.cpp
  • trunk/Source/WebCore/ChangeLog

    r213183 r213190  
     12017-02-28  Alex Christensen  <achristensen@webkit.org>
     2
     3        LibWebRTCProvider should check existence of libwebrtc.dylib
     4        https://bugs.webkit.org/show_bug.cgi?id=168986
     5        <rdar://problem/30735413>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        Some configurations of the webrtc tests overwrite the availability of WebRTC in order to test it
     10        with MockLibWebRTCPeerConnection.  If the dylib can not be found, we can't use it, so we want to
     11        fail these tests rather than crashing calling rtc::LogMessage::LogToDebug.
     12
     13        * Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
     14        (WebCore::LibWebRTCMediaEndpoint::doCreateOffer):
     15        (WebCore::LibWebRTCMediaEndpoint::doCreateAnswer):
     16        * platform/mediastream/libwebrtc/LibWebRTCProvider.cpp:
     17        (WebCore::LibWebRTCProvider::factory):
     18        (WebCore::LibWebRTCProvider::webRTCAvailable):
     19        * platform/mediastream/libwebrtc/LibWebRTCProvider.h:
     20        * testing/MockLibWebRTCPeerConnection.cpp:
     21        (WebCore::useMockRTCPeerConnectionFactory):
     22        (WebCore::MockLibWebRTCPeerConnectionFactory::CreatePeerConnection):
     23
    1242017-02-28  Tim Horton  <timothy_horton@apple.com>
    225
  • trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp

    r213108 r213190  
    156156void LibWebRTCMediaEndpoint::doCreateOffer()
    157157{
     158    if (!LibWebRTCProvider::factory()) {
     159        m_peerConnectionBackend.createOfferFailed(Exception { NOT_SUPPORTED_ERR, ASCIILiteral("libwebrtc backend is missing.") });
     160        return;
     161    }
     162       
    158163    m_isInitiator = true;
    159164    auto& senders = m_peerConnectionBackend.connection().getSenders();
    160165    if (senders.size()) {
    161166        // FIXME: We only support one stream for the moment.
    162         auto stream = LibWebRTCProvider::factory().CreateLocalMediaStream(streamId(m_peerConnectionBackend.connection()));
     167        auto stream = LibWebRTCProvider::factory()->CreateLocalMediaStream(streamId(m_peerConnectionBackend.connection()));
    163168        for (RTCRtpSender& sender : senders) {
    164169            auto* track = sender.track();
     
    168173                if (source.type() == RealtimeMediaSource::Audio) {
    169174                    auto trackSource = RealtimeOutgoingAudioSource::create(source);
    170                     auto rtcTrack = LibWebRTCProvider::factory().CreateAudioTrack(track->id().utf8().data(), trackSource.ptr());
     175                    auto rtcTrack = LibWebRTCProvider::factory()->CreateAudioTrack(track->id().utf8().data(), trackSource.ptr());
    171176                    trackSource->setTrack(rtc::scoped_refptr<webrtc::AudioTrackInterface>(rtcTrack));
    172177                    m_peerConnectionBackend.addAudioSource(WTFMove(trackSource));
     
    174179                } else {
    175180                    auto videoSource = RealtimeOutgoingVideoSource::create(source);
    176                     auto videoTrack = LibWebRTCProvider::factory().CreateVideoTrack(track->id().utf8().data(), videoSource.ptr());
     181                    auto videoTrack = LibWebRTCProvider::factory()->CreateVideoTrack(track->id().utf8().data(), videoSource.ptr());
    177182                    m_peerConnectionBackend.addVideoSource(WTFMove(videoSource));
    178183                    stream->AddTrack(WTFMove(videoTrack));
     
    187192void LibWebRTCMediaEndpoint::doCreateAnswer()
    188193{
     194    if (!LibWebRTCProvider::factory()) {
     195        m_peerConnectionBackend.createAnswerFailed(Exception { NOT_SUPPORTED_ERR, ASCIILiteral("libwebrtc backend is missing.") });
     196        return;
     197    }
     198
    189199    m_isInitiator = false;
    190200
     
    192202    if (senders.size()) {
    193203        // FIXME: We only support one stream for the moment.
    194         auto stream = LibWebRTCProvider::factory().CreateLocalMediaStream(streamId(m_peerConnectionBackend.connection()));
     204        auto stream = LibWebRTCProvider::factory()->CreateLocalMediaStream(streamId(m_peerConnectionBackend.connection()));
    195205        for (RTCRtpSender& sender : senders) {
    196206            auto* track = sender.track();
     
    200210                if (source.type() == RealtimeMediaSource::Audio) {
    201211                    auto trackSource = RealtimeOutgoingAudioSource::create(source);
    202                     auto rtcTrack = LibWebRTCProvider::factory().CreateAudioTrack(track->id().utf8().data(), trackSource.ptr());
     212                    auto rtcTrack = LibWebRTCProvider::factory()->CreateAudioTrack(track->id().utf8().data(), trackSource.ptr());
    203213                    trackSource->setTrack(rtc::scoped_refptr<webrtc::AudioTrackInterface>(rtcTrack));
    204214                    m_peerConnectionBackend.addAudioSource(WTFMove(trackSource));
     
    206216                } else {
    207217                    auto videoSource = RealtimeOutgoingVideoSource::create(source);
    208                     auto videoTrack = LibWebRTCProvider::factory().CreateVideoTrack(track->id().utf8().data(), videoSource.ptr());
     218                    auto videoTrack = LibWebRTCProvider::factory()->CreateVideoTrack(track->id().utf8().data(), videoSource.ptr());
    209219                    m_peerConnectionBackend.addVideoSource(WTFMove(videoSource));
    210220                    stream->AddTrack(WTFMove(videoTrack));
  • trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.cpp

    r213167 r213190  
    2828
    2929#if USE(LIBWEBRTC)
    30 
    3130#include "LibWebRTCAudioModule.h"
    3231#include "Logging.h"
     32#include <dlfcn.h>
    3333#include <webrtc/api/peerconnectionfactory.h>
    3434#include <webrtc/api/peerconnectionfactoryproxy.h>
     
    3838#include <wtf/Function.h>
    3939#include <wtf/NeverDestroyed.h>
     40#endif
    4041
    4142namespace WebCore {
    4243
     44#if USE(LIBWEBRTC)
    4345struct PeerConnectionFactoryAndThreads : public rtc::MessageHandler {
    4446    std::unique_ptr<LibWebRTCAudioModule> audioDeviceModule;
     
    112114}
    113115
    114 webrtc::PeerConnectionFactoryInterface& LibWebRTCProvider::factory()
     116webrtc::PeerConnectionFactoryInterface* LibWebRTCProvider::factory()
    115117{
     118    if (!webRTCAvailable())
     119        return nullptr;
    116120    if (!staticFactoryAndThreads().factory)
    117121        initializePeerConnectionFactoryAndThreads();
    118     return *staticFactoryAndThreads().factory;
     122    return staticFactoryAndThreads().factory;
    119123}
    120124
     
    167171    return createActualPeerConnection(observer, WTFMove(portAllocator));
    168172}
     173#endif // USE(LIBWEBRTC)
     174
     175bool LibWebRTCProvider::webRTCAvailable()
     176{
     177#if USE(LIBWEBRTC)
     178    static bool available = [] {
     179        void* libwebrtcLibrary = dlopen("libwebrtc.dylib", RTLD_LAZY);
     180        if (!libwebrtcLibrary)
     181            return false;
     182        dlclose(libwebrtcLibrary);
     183        return true;
     184    }();
     185    return available;
     186#else
     187    return true;
     188#endif
     189}
    169190
    170191} // namespace WebCore
    171 
    172 #endif // USE(LIBWEBRTC)
  • trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.h

    r212745 r213190  
    5151    virtual ~LibWebRTCProvider() = default;
    5252
     53    static bool webRTCAvailable();
    5354#if USE(LIBWEBRTC)
    5455    WEBCORE_EXPORT virtual rtc::scoped_refptr<webrtc::PeerConnectionInterface> createPeerConnection(webrtc::PeerConnectionObserver&);
     
    5758    static WEBCORE_EXPORT void callOnWebRTCNetworkThread(Function<void()>&&);
    5859    static WEBCORE_EXPORT void callOnWebRTCSignalingThread(Function<void()>&&);
    59     static WEBCORE_EXPORT webrtc::PeerConnectionFactoryInterface& factory();
     60    static WEBCORE_EXPORT webrtc::PeerConnectionFactoryInterface* factory();
    6061    // Used for mock testing
    6162    static void setPeerConnectionFactory(rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>&&);
  • trunk/Source/WebCore/testing/MockLibWebRTCPeerConnection.cpp

    r212338 r213190  
    5252    if (provider && !realPeerConnectionFactory()) {
    5353        auto& factory = getRealPeerConnectionFactory();
    54         factory = &provider->factory();
     54        factory = provider->factory();
    5555    }
    5656
     
    163163rtc::scoped_refptr<webrtc::PeerConnectionInterface> MockLibWebRTCPeerConnectionFactory::CreatePeerConnection(const webrtc::PeerConnectionInterface::RTCConfiguration& configuration, std::unique_ptr<cricket::PortAllocator> portAllocator, std::unique_ptr<rtc::RTCCertificateGeneratorInterface> generator, webrtc::PeerConnectionObserver* observer)
    164164{
     165    if (!realPeerConnectionFactory())
     166        return nullptr;
     167
    165168    if (m_numberOfRealPeerConnections) {
    166169        auto connection = realPeerConnectionFactory()->CreatePeerConnection(configuration, WTFMove(portAllocator), WTFMove(generator), observer);
  • trunk/Source/WebKit2/ChangeLog

    r213189 r213190  
     12017-02-28  Alex Christensen  <achristensen@webkit.org>
     2
     3        LibWebRTCProvider should check existence of libwebrtc.dylib
     4        https://bugs.webkit.org/show_bug.cgi?id=168986
     5
     6        Reviewed by Youenn Fablet.
     7
     8        * Shared/WebPreferencesDefinitions.h:
     9        * Shared/WebPreferencesStore.cpp:
     10        * UIProcess/WebPreferences.cpp:
     11        (WebKit::checkWebRTCAvailability): Deleted.
     12
    1132017-02-28  Wenson Hsieh  <wenson_hsieh@apple.com>
    214
  • trunk/Source/WebKit2/Shared/WebPreferencesDefinitions.h

    r212945 r213190  
    313313//   wider testing).
    314314
    315 // Disable webrtc feature if libwebrtc library is not present
    316 namespace WebKit {
    317 bool checkWebRTCAvailability();
    318 }
    319 
    320315#define FOR_EACH_WEBKIT_EXPERIMENTAL_FEATURE_PREFERENCE(macro) \
    321316    macro(SpringTimingFunctionEnabled, springTimingFunctionEnabled, Bool, bool, DEFAULT_EXPERIMENTAL_FEATURES_ENABLED, "CSS Spring Animations", "CSS Spring Animation prototype") \
     
    329324    macro(WebAnimationsEnabled, webAnimationsEnabled, Bool, bool, false, "Web Animations", "Web Animations prototype") \
    330325    macro(WebGL2Enabled, webGL2Enabled, Bool, bool, DEFAULT_EXPERIMENTAL_FEATURES_ENABLED, "WebGL 2.0", "WebGL 2 prototype") \
    331     macro(PeerConnectionEnabled, peerConnectionEnabled, Bool, bool, checkWebRTCAvailability(), "WebRTC", "Enable WebRTC API") \
     326    macro(PeerConnectionEnabled, peerConnectionEnabled, Bool, bool, WebCore::LibWebRTCProvider::webRTCAvailable(), "WebRTC", "Enable WebRTC API") \
    332327    \
    333328
  • trunk/Source/WebKit2/Shared/WebPreferencesStore.cpp

    r204668 r213190  
    3030#include "WebCoreArgumentCoders.h"
    3131#include "WebPreferencesKeys.h"
     32#include <WebCore/LibWebRTCProvider.h>
    3233#include <WebCore/Settings.h>
    3334#include <WebCore/TextEncodingRegistry.h>
  • trunk/Source/WebKit2/UIProcess/WebPreferences.cpp

    r213074 r213190  
    3030#include "WebPreferencesKeys.h"
    3131#include "WebProcessPool.h"
    32 #include <dlfcn.h>
     32#include <WebCore/LibWebRTCProvider.h>
    3333#include <wtf/NeverDestroyed.h>
    3434#include <wtf/ThreadingPrimitives.h>
     
    197197#undef DEFINE_PREFERENCE_GETTER_AND_SETTERS
    198198
    199 bool checkWebRTCAvailability()
    200 {
    201 #if USE(LIBWEBRTC)
    202     static bool available = [&] {
    203         void* libwebrtcLibrary = dlopen("libwebrtc.dylib", RTLD_LAZY);
    204         if (!libwebrtcLibrary)
    205             return false;
    206         dlclose(libwebrtcLibrary);
    207         return true;
    208     }();
    209     return available;
    210 #else
    211     return true;
    212 #endif
    213 }
    214 
    215199#define DEFINE_EXPERIMENTAL_PREFERENCE_GETTER_AND_SETTERS(KeyUpper, KeyLower, TypeName, Type, DefaultValue, HumanReadableName, HumanReadableDescription) \
    216200    void WebPreferences::set##KeyUpper(const Type& value) \
Note: See TracChangeset for help on using the changeset viewer.