Changeset 218903 in webkit


Ignore:
Timestamp:
Jun 28, 2017 4:24:42 PM (7 years ago)
Author:
commit-queue@webkit.org
Message:

Support PeerConnectionStates::BundlePolicy::MaxBundle when setting rtc configuration
https://bugs.webkit.org/show_bug.cgi?id=169389

Patch by Youenn Fablet <youenn@apple.com> on 2017-06-28
Reviewed by Alex Christensen.

Source/WebCore:

Covered by manual testing (appr.tc and https://youennf.github.io/webrtc-tests/src/content/peerconnection/trickle-ice/).
Previously, we were creating a libwebrtc peer connection and then setting its configuration.
libwebrtc does not like the configuration to be changed and may refuse to set the configuration.
Instead of doing that, we are now creating the libwebrtc peer connection with the provided configuration.

  • Modules/mediastream/MediaEndpointPeerConnection.cpp:

(WebCore::MediaEndpointPeerConnection::setConfiguration):

  • Modules/mediastream/MediaEndpointPeerConnection.h:
  • Modules/mediastream/PeerConnectionBackend.h:
  • Modules/mediastream/RTCPeerConnection.cpp:

(WebCore::RTCPeerConnection::initializeWith):
(WebCore::iceServersFromConfiguration):
(WebCore::RTCPeerConnection::initializeConfiguration):
(WebCore::RTCPeerConnection::setConfiguration):

  • Modules/mediastream/RTCPeerConnection.h:
  • Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:

(WebCore::LibWebRTCMediaEndpoint::LibWebRTCMediaEndpoint):
(WebCore::LibWebRTCMediaEndpoint::setConfiguration):
(WebCore::LibWebRTCMediaEndpoint::stop):

  • Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:
  • Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:

(WebCore::configurationFromMediaEndpointConfiguration):
(WebCore::LibWebRTCPeerConnectionBackend::setConfiguration):

  • Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h:
  • platform/mediastream/libwebrtc/LibWebRTCProvider.cpp:

(WebCore::createActualPeerConnection):
(WebCore::LibWebRTCProvider::createPeerConnection):

  • platform/mediastream/libwebrtc/LibWebRTCProvider.h:

Source/WebKit2:

Updating according new WebCore LIbWebRTCProvider API.

  • WebProcess/Network/webrtc/LibWebRTCProvider.cpp:

(WebKit::LibWebRTCProvider::createPeerConnection):

  • WebProcess/Network/webrtc/LibWebRTCProvider.h:
Location:
trunk/Source
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r218901 r218903  
     12017-06-28  Youenn Fablet  <youenn@apple.com>
     2
     3        Support PeerConnectionStates::BundlePolicy::MaxBundle when setting rtc configuration
     4        https://bugs.webkit.org/show_bug.cgi?id=169389
     5
     6        Reviewed by Alex Christensen.
     7
     8        Covered by manual testing (appr.tc and https://youennf.github.io/webrtc-tests/src/content/peerconnection/trickle-ice/).
     9        Previously, we were creating a libwebrtc peer connection and then setting its configuration.
     10        libwebrtc does not like the configuration to be changed and may refuse to set the configuration.
     11        Instead of doing that, we are now creating the libwebrtc peer connection with the provided configuration.
     12
     13        * Modules/mediastream/MediaEndpointPeerConnection.cpp:
     14        (WebCore::MediaEndpointPeerConnection::setConfiguration):
     15        * Modules/mediastream/MediaEndpointPeerConnection.h:
     16        * Modules/mediastream/PeerConnectionBackend.h:
     17        * Modules/mediastream/RTCPeerConnection.cpp:
     18        (WebCore::RTCPeerConnection::initializeWith):
     19        (WebCore::iceServersFromConfiguration):
     20        (WebCore::RTCPeerConnection::initializeConfiguration):
     21        (WebCore::RTCPeerConnection::setConfiguration):
     22        * Modules/mediastream/RTCPeerConnection.h:
     23        * Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
     24        (WebCore::LibWebRTCMediaEndpoint::LibWebRTCMediaEndpoint):
     25        (WebCore::LibWebRTCMediaEndpoint::setConfiguration):
     26        (WebCore::LibWebRTCMediaEndpoint::stop):
     27        * Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:
     28        * Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:
     29        (WebCore::configurationFromMediaEndpointConfiguration):
     30        (WebCore::LibWebRTCPeerConnectionBackend::setConfiguration):
     31        * Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h:
     32        * platform/mediastream/libwebrtc/LibWebRTCProvider.cpp:
     33        (WebCore::createActualPeerConnection):
     34        (WebCore::LibWebRTCProvider::createPeerConnection):
     35        * platform/mediastream/libwebrtc/LibWebRTCProvider.h:
     36
    1372017-06-28  Brent Fulgham  <bfulgham@apple.com>
    238
  • trunk/Source/WebCore/Modules/mediastream/MediaEndpointPeerConnection.cpp

    r218498 r218903  
    603603}
    604604
    605 void MediaEndpointPeerConnection::setConfiguration(MediaEndpointConfiguration&& configuration)
     605bool MediaEndpointPeerConnection::setConfiguration(MediaEndpointConfiguration&& configuration)
    606606{
    607607    m_mediaEndpoint->setConfiguration(WTFMove(configuration));
     608    return true;
    608609}
    609610
  • trunk/Source/WebCore/Modules/mediastream/MediaEndpointPeerConnection.h

    r216501 r218903  
    5757    RefPtr<RTCSessionDescription> pendingRemoteDescription() const final;
    5858
    59     void setConfiguration(MediaEndpointConfiguration&&) final;
     59    bool setConfiguration(MediaEndpointConfiguration&&) final;
    6060
    6161    void getStats(MediaStreamTrack*, Ref<DeferredPromise>&&) final;
  • trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.h

    r218335 r218903  
    8989    virtual RefPtr<RTCSessionDescription> pendingRemoteDescription() const = 0;
    9090
    91     virtual void setConfiguration(MediaEndpointConfiguration&&) = 0;
     91    virtual bool setConfiguration(MediaEndpointConfiguration&&) = 0;
    9292
    9393    virtual void getStats(MediaStreamTrack*, Ref<DeferredPromise>&&) = 0;
  • trunk/Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp

    r218844 r218903  
    9898        return Exception { NOT_SUPPORTED_ERR };
    9999
    100     return setConfiguration(WTFMove(configuration));
     100    return initializeConfiguration(WTFMove(configuration));
    101101}
    102102
     
    299299}
    300300
    301 ExceptionOr<void> RTCPeerConnection::setConfiguration(RTCConfiguration&& configuration)
    302 {
    303     if (isClosed())
    304         return Exception { INVALID_STATE_ERR };
    305 
     301static inline std::optional<Vector<MediaEndpointConfiguration::IceServerInfo>> iceServersFromConfiguration(RTCConfiguration& configuration)
     302{
    306303    Vector<MediaEndpointConfiguration::IceServerInfo> servers;
    307304    if (configuration.iceServers) {
     
    309306        for (auto& server : configuration.iceServers.value()) {
    310307            Vector<URL> serverURLs;
    311             WTF::switchOn(server.urls,
    312                 [&serverURLs] (const String& string) {
    313                     serverURLs.reserveInitialCapacity(1);
     308            WTF::switchOn(server.urls, [&serverURLs] (const String& string) {
     309                serverURLs.reserveInitialCapacity(1);
     310                serverURLs.uncheckedAppend(URL { URL { }, string });
     311            }, [&serverURLs] (const Vector<String>& vector) {
     312                serverURLs.reserveInitialCapacity(vector.size());
     313                for (auto& string : vector)
    314314                    serverURLs.uncheckedAppend(URL { URL { }, string });
    315                 },
    316                 [&serverURLs] (const Vector<String>& vector) {
    317                     serverURLs.reserveInitialCapacity(vector.size());
    318                     for (auto& string : vector)
    319                         serverURLs.uncheckedAppend(URL { URL { }, string });
    320                 }
    321             );
     315            });
    322316            for (auto& serverURL : serverURLs) {
    323317                if (!(serverURL.protocolIs("turn") || serverURL.protocolIs("turns") || serverURL.protocolIs("stun")))
    324                     return Exception { INVALID_ACCESS_ERR };
     318                    return std::nullopt;
    325319            }
    326320            servers.uncheckedAppend({ WTFMove(serverURLs), server.credential, server.username });
    327321        }
    328322    }
    329 
    330     m_backend->setConfiguration({ WTFMove(servers), configuration.iceTransportPolicy, configuration.bundlePolicy, configuration.iceCandidatePoolSize });
     323    return servers;
     324}
     325
     326ExceptionOr<void> RTCPeerConnection::initializeConfiguration(RTCConfiguration&& configuration)
     327{
     328    auto servers = iceServersFromConfiguration(configuration);
     329    if (!servers)
     330        return Exception { INVALID_ACCESS_ERR };
     331
     332    // FIXME: https://bugs.webkit.org/show_bug.cgi?id=173938
     333    // Also decide whether to report an exception or output a message in the console log if setting configuration fails.
     334    m_backend->setConfiguration({ WTFMove(servers.value()), configuration.iceTransportPolicy, configuration.bundlePolicy, configuration.iceCandidatePoolSize });
     335
     336    m_configuration = WTFMove(configuration);
     337    return { };
     338}
     339
     340ExceptionOr<void> RTCPeerConnection::setConfiguration(RTCConfiguration&& configuration)
     341{
     342    if (isClosed())
     343        return Exception { INVALID_STATE_ERR };
     344
     345    auto servers = iceServersFromConfiguration(configuration);
     346    if (!servers)
     347        return Exception { INVALID_ACCESS_ERR };
     348
     349    // FIXME: https://bugs.webkit.org/show_bug.cgi?id=173938
     350    // Also decide whether to report an exception or output a message in the console log if setting configuration fails.
     351    m_backend->setConfiguration({ WTFMove(servers.value()), configuration.iceTransportPolicy, configuration.bundlePolicy, configuration.iceCandidatePoolSize });
    331352    m_configuration = WTFMove(configuration);
    332353    return { };
  • trunk/Source/WebCore/Modules/mediastream/RTCPeerConnection.h

    r217932 r218903  
    154154    RTCPeerConnection(ScriptExecutionContext&);
    155155
     156    ExceptionOr<void> initializeConfiguration(RTCConfiguration&&);
    156157    Ref<RTCRtpTransceiver> completeAddTransceiver(Ref<RTCRtpSender>&&, const RTCRtpTransceiverInit&, const String& trackId, const String& trackKind);
    157158
  • trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp

    r218844 r218903  
    6060    : m_peerConnectionBackend(peerConnection)
    6161    , m_peerConnectionFactory(*client.factory())
    62     , m_backend(client.createPeerConnection(*this))
    6362    , m_createSessionDescriptionObserver(*this)
    6463    , m_setLocalSessionDescriptionObserver(*this)
     
    6665    , m_statsLogTimer(*this, &LibWebRTCMediaEndpoint::gatherStatsForLogging)
    6766{
    68     ASSERT(m_backend);
    6967    ASSERT(client.factory());
     68}
     69
     70bool LibWebRTCMediaEndpoint::setConfiguration(LibWebRTCProvider& client, webrtc::PeerConnectionInterface::RTCConfiguration&& configuration)
     71{
     72    if (!m_backend) {
     73        m_backend = client.createPeerConnection(*this, WTFMove(configuration));
     74        return !!m_backend;
     75    }
     76    return m_backend->SetConfiguration(WTFMove(configuration));
    7077}
    7178
     
    767774void LibWebRTCMediaEndpoint::stop()
    768775{
     776    if (!m_backend)
     777        return;
     778
    769779    stopLoggingStats();
    770780
    771     ASSERT(m_backend);
    772781    m_backend->Close();
    773782    m_backend = nullptr;
  • trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h

    r218714 r218903  
    6363    virtual ~LibWebRTCMediaEndpoint() { }
    6464
     65    bool setConfiguration(LibWebRTCProvider&, webrtc::PeerConnectionInterface::RTCConfiguration&&);
     66
    6567    webrtc::PeerConnectionInterface& backend() const { ASSERT(m_backend); return *m_backend.get(); }
    6668    void doSetLocalDescription(RTCSessionDescription&);
  • trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp

    r218645 r218903  
    7272}
    7373
     74static inline webrtc::PeerConnectionInterface::BundlePolicy bundlePolicyfromConfiguration(const MediaEndpointConfiguration& configuration)
     75{
     76    switch (configuration.bundlePolicy) {
     77    case RTCBundlePolicy::MaxCompat:
     78        return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat;
     79    case RTCBundlePolicy::MaxBundle:
     80        return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle;
     81    case RTCBundlePolicy::Balanced:
     82        return webrtc::PeerConnectionInterface::kBundlePolicyBalanced;
     83    }
     84}
     85
     86static inline webrtc::PeerConnectionInterface::IceTransportsType iceTransportPolicyfromConfiguration(const MediaEndpointConfiguration& configuration)
     87{
     88    switch (configuration.iceTransportPolicy) {
     89    case RTCIceTransportPolicy::Relay:
     90        return webrtc::PeerConnectionInterface::kRelay;
     91    case RTCIceTransportPolicy::All:
     92        return webrtc::PeerConnectionInterface::kAll;
     93    }
     94}
     95
    7496static webrtc::PeerConnectionInterface::RTCConfiguration configurationFromMediaEndpointConfiguration(MediaEndpointConfiguration&& configuration)
    7597{
    7698    webrtc::PeerConnectionInterface::RTCConfiguration rtcConfiguration;
    7799
    78     if (configuration.iceTransportPolicy == RTCIceTransportPolicy::Relay)
    79         rtcConfiguration.type = webrtc::PeerConnectionInterface::kRelay;
    80 
    81     // FIXME: Support PeerConnectionStates::BundlePolicy::MaxBundle.
    82     // LibWebRTC does not like it and will fail to set any configuration field otherwise.
    83     // See https://bugs.webkit.org/show_bug.cgi?id=169389.
    84 
    85     if (configuration.bundlePolicy == RTCBundlePolicy::MaxCompat)
    86         rtcConfiguration.bundle_policy = webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat;
     100    rtcConfiguration.type = iceTransportPolicyfromConfiguration(configuration);
     101    rtcConfiguration.bundle_policy = bundlePolicyfromConfiguration(configuration);
    87102
    88103    for (auto& server : configuration.iceServers) {
     
    101116}
    102117
    103 void LibWebRTCPeerConnectionBackend::setConfiguration(MediaEndpointConfiguration&& configuration)
    104 {
    105     m_endpoint->backend().SetConfiguration(configurationFromMediaEndpointConfiguration(WTFMove(configuration)));
     118bool LibWebRTCPeerConnectionBackend::setConfiguration(MediaEndpointConfiguration&& configuration)
     119{
     120    return m_endpoint->setConfiguration(libWebRTCProvider(m_peerConnection), configurationFromMediaEndpointConfiguration(WTFMove(configuration)));
    106121}
    107122
  • trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h

    r218431 r218903  
    6161    void doStop() final;
    6262    std::unique_ptr<RTCDataChannelHandler> createDataChannelHandler(const String&, const RTCDataChannelInit&) final;
    63     void setConfiguration(MediaEndpointConfiguration&&) final;
     63    bool setConfiguration(MediaEndpointConfiguration&&) final;
    6464    void getStats(MediaStreamTrack*, Ref<DeferredPromise>&&) final;
    6565    Ref<RTCRtpReceiver> createReceiver(const String& transceiverMid, const String& trackKind, const String& trackId) final;
  • trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.cpp

    r218645 r218903  
    169169}
    170170
    171 static rtc::scoped_refptr<webrtc::PeerConnectionInterface> createActualPeerConnection(webrtc::PeerConnectionObserver& observer, std::unique_ptr<cricket::BasicPortAllocator>&& portAllocator)
     171static rtc::scoped_refptr<webrtc::PeerConnectionInterface> createActualPeerConnection(webrtc::PeerConnectionObserver& observer, std::unique_ptr<cricket::BasicPortAllocator>&& portAllocator, webrtc::PeerConnectionInterface::RTCConfiguration&& configuration)
    172172{
    173173    ASSERT(staticFactoryAndThreads().factory);
    174174
    175     webrtc::PeerConnectionInterface::RTCConfiguration config;
    176     // FIXME: Add a default configuration.
    177     return staticFactoryAndThreads().factory->CreatePeerConnection(config, WTFMove(portAllocator), nullptr, &observer);
    178 }
    179 
    180 rtc::scoped_refptr<webrtc::PeerConnectionInterface> LibWebRTCProvider::createPeerConnection(webrtc::PeerConnectionObserver& observer)
     175    return staticFactoryAndThreads().factory->CreatePeerConnection(configuration, WTFMove(portAllocator), nullptr, &observer);
     176}
     177
     178rtc::scoped_refptr<webrtc::PeerConnectionInterface> LibWebRTCProvider::createPeerConnection(webrtc::PeerConnectionObserver& observer, webrtc::PeerConnectionInterface::RTCConfiguration&& configuration)
    181179{
    182180    // Default WK1 implementation.
     
    188186    ASSERT(staticFactoryAndThreads().networkThreadWithSocketServer);
    189187
    190     return createActualPeerConnection(observer, nullptr);
    191 }
    192 
    193 rtc::scoped_refptr<webrtc::PeerConnectionInterface> LibWebRTCProvider::createPeerConnection(webrtc::PeerConnectionObserver& observer, rtc::NetworkManager& networkManager, rtc::PacketSocketFactory& packetSocketFactory)
     188    return createActualPeerConnection(observer, nullptr, WTFMove(configuration));
     189}
     190
     191rtc::scoped_refptr<webrtc::PeerConnectionInterface> LibWebRTCProvider::createPeerConnection(webrtc::PeerConnectionObserver& observer, rtc::NetworkManager& networkManager, rtc::PacketSocketFactory& packetSocketFactory, webrtc::PeerConnectionInterface::RTCConfiguration&& configuration)
    194192{
    195193    ASSERT(!staticFactoryAndThreads().networkThreadWithSocketServer);
     
    207205    });
    208206
    209     return createActualPeerConnection(observer, WTFMove(portAllocator));
     207    return createActualPeerConnection(observer, WTFMove(portAllocator), WTFMove(configuration));
    210208}
    211209
  • trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.h

    r215239 r218903  
    5353    static bool webRTCAvailable();
    5454#if USE(LIBWEBRTC)
    55     WEBCORE_EXPORT virtual rtc::scoped_refptr<webrtc::PeerConnectionInterface> createPeerConnection(webrtc::PeerConnectionObserver&);
     55    WEBCORE_EXPORT virtual rtc::scoped_refptr<webrtc::PeerConnectionInterface> createPeerConnection(webrtc::PeerConnectionObserver&, webrtc::PeerConnectionInterface::RTCConfiguration&&);
    5656
    5757    WEBCORE_EXPORT webrtc::PeerConnectionFactoryInterface* factory();
     
    7070
    7171protected:
    72     WEBCORE_EXPORT rtc::scoped_refptr<webrtc::PeerConnectionInterface> createPeerConnection(webrtc::PeerConnectionObserver&, rtc::NetworkManager&, rtc::PacketSocketFactory&);
     72    WEBCORE_EXPORT rtc::scoped_refptr<webrtc::PeerConnectionInterface> createPeerConnection(webrtc::PeerConnectionObserver&, rtc::NetworkManager&, rtc::PacketSocketFactory&, webrtc::PeerConnectionInterface::RTCConfiguration&&);
    7373
    7474    bool m_enableEnumeratingAllNetworkInterfaces { false };
  • trunk/Source/WebKit2/ChangeLog

    r218902 r218903  
     12017-06-28  Youenn Fablet  <youenn@apple.com>
     2
     3        Support PeerConnectionStates::BundlePolicy::MaxBundle when setting rtc configuration
     4        https://bugs.webkit.org/show_bug.cgi?id=169389
     5
     6        Reviewed by Alex Christensen.
     7
     8        Updating according new WebCore LIbWebRTCProvider API.
     9
     10        * WebProcess/Network/webrtc/LibWebRTCProvider.cpp:
     11        (WebKit::LibWebRTCProvider::createPeerConnection):
     12        * WebProcess/Network/webrtc/LibWebRTCProvider.h:
     13
    1142017-06-28  Chris Dumez  <cdumez@apple.com>
    215
  • trunk/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCProvider.cpp

    r216338 r218903  
    3535namespace WebKit {
    3636
    37 rtc::scoped_refptr<webrtc::PeerConnectionInterface> LibWebRTCProvider::createPeerConnection(webrtc::PeerConnectionObserver& observer)
     37rtc::scoped_refptr<webrtc::PeerConnectionInterface> LibWebRTCProvider::createPeerConnection(webrtc::PeerConnectionObserver& observer, webrtc::PeerConnectionInterface::RTCConfiguration&& configuration)
    3838{
    39     return WebCore::LibWebRTCProvider::createPeerConnection(observer, WebProcess::singleton().libWebRTCNetwork().monitor(), WebProcess::singleton().libWebRTCNetwork().socketFactory());
     39    return WebCore::LibWebRTCProvider::createPeerConnection(observer, WebProcess::singleton().libWebRTCNetwork().monitor(), WebProcess::singleton().libWebRTCNetwork().socketFactory(), WTFMove(configuration));
    4040}
    4141
  • trunk/Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCProvider.h

    r215239 r218903  
    3737
    3838private:
    39     rtc::scoped_refptr<webrtc::PeerConnectionInterface> createPeerConnection(webrtc::PeerConnectionObserver&) final;
     39    rtc::scoped_refptr<webrtc::PeerConnectionInterface> createPeerConnection(webrtc::PeerConnectionObserver&, webrtc::PeerConnectionInterface::RTCConfiguration&&) final;
    4040};
    4141#else
Note: See TracChangeset for help on using the changeset viewer.