Use "= default" to denote default constructor or destructor
[WebKit-https.git] / Source / WebCore / Modules / mediastream / libwebrtc / LibWebRTCPeerConnectionBackend.cpp
index dce8648..0532565 100644 (file)
@@ -28,7 +28,6 @@
 #if USE(LIBWEBRTC)
 
 #include "Document.h"
-#include "ExceptionCode.h"
 #include "IceCandidate.h"
 #include "JSRTCStatsReport.h"
 #include "LibWebRTCDataChannelHandler.h"
@@ -41,7 +40,6 @@
 #include "RTCSessionDescription.h"
 #include "RealtimeIncomingAudioSource.h"
 #include "RealtimeIncomingVideoSource.h"
-#include <wtf/text/StringBuilder.h>
 
 namespace WebCore {
 
@@ -67,23 +65,36 @@ LibWebRTCPeerConnectionBackend::LibWebRTCPeerConnectionBackend(RTCPeerConnection
 {
 }
 
-LibWebRTCPeerConnectionBackend::~LibWebRTCPeerConnectionBackend()
+LibWebRTCPeerConnectionBackend::~LibWebRTCPeerConnectionBackend() = default;
+
+static inline webrtc::PeerConnectionInterface::BundlePolicy bundlePolicyfromConfiguration(const MediaEndpointConfiguration& configuration)
+{
+    switch (configuration.bundlePolicy) {
+    case RTCBundlePolicy::MaxCompat:
+        return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat;
+    case RTCBundlePolicy::MaxBundle:
+        return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle;
+    case RTCBundlePolicy::Balanced:
+        return webrtc::PeerConnectionInterface::kBundlePolicyBalanced;
+    }
+}
+
+static inline webrtc::PeerConnectionInterface::IceTransportsType iceTransportPolicyfromConfiguration(const MediaEndpointConfiguration& configuration)
 {
+    switch (configuration.iceTransportPolicy) {
+    case RTCIceTransportPolicy::Relay:
+        return webrtc::PeerConnectionInterface::kRelay;
+    case RTCIceTransportPolicy::All:
+        return webrtc::PeerConnectionInterface::kAll;
+    }
 }
 
 static webrtc::PeerConnectionInterface::RTCConfiguration configurationFromMediaEndpointConfiguration(MediaEndpointConfiguration&& configuration)
 {
     webrtc::PeerConnectionInterface::RTCConfiguration rtcConfiguration;
 
-    if (configuration.iceTransportPolicy == RTCIceTransportPolicy::Relay)
-        rtcConfiguration.type = webrtc::PeerConnectionInterface::kRelay;
-
-    // FIXME: Support PeerConnectionStates::BundlePolicy::MaxBundle.
-    // LibWebRTC does not like it and will fail to set any configuration field otherwise.
-    // See https://bugs.webkit.org/show_bug.cgi?id=169389.
-
-    if (configuration.bundlePolicy == RTCBundlePolicy::MaxCompat)
-        rtcConfiguration.bundle_policy = webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat;
+    rtcConfiguration.type = iceTransportPolicyfromConfiguration(configuration);
+    rtcConfiguration.bundle_policy = bundlePolicyfromConfiguration(configuration);
 
     for (auto& server : configuration.iceServers) {
         webrtc::PeerConnectionInterface::IceServer iceServer;
@@ -95,14 +106,15 @@ static webrtc::PeerConnectionInterface::RTCConfiguration configurationFromMediaE
     }
 
     rtcConfiguration.set_cpu_adaptation(false);
-    rtcConfiguration.ice_candidate_pool_size = configuration.iceCandidatePoolSize;
+    // FIXME: Activate ice candidate pool size once it no longer bothers test bots.
+    // rtcConfiguration.ice_candidate_pool_size = configuration.iceCandidatePoolSize;
 
     return rtcConfiguration;
 }
 
-void LibWebRTCPeerConnectionBackend::setConfiguration(MediaEndpointConfiguration&& configuration)
+bool LibWebRTCPeerConnectionBackend::setConfiguration(MediaEndpointConfiguration&& configuration)
 {
-    m_endpoint->backend().SetConfiguration(configurationFromMediaEndpointConfiguration(WTFMove(configuration)));
+    return m_endpoint->setConfiguration(libWebRTCProvider(m_peerConnection), configurationFromMediaEndpointConfiguration(WTFMove(configuration)));
 }
 
 void LibWebRTCPeerConnectionBackend::getStats(MediaStreamTrack* track, Ref<DeferredPromise>&& promise)
@@ -161,7 +173,7 @@ void LibWebRTCPeerConnectionBackend::doCreateOffer(RTCOfferOptions&& options)
 void LibWebRTCPeerConnectionBackend::doCreateAnswer(RTCAnswerOptions&&)
 {
     if (!m_isRemoteDescriptionSet) {
-        createAnswerFailed(Exception { INVALID_STATE_ERR, "No remote description set" });
+        createAnswerFailed(Exception { InvalidStateError, "No remote description set" });
         return;
     }
     m_endpoint->doCreateAnswer();
@@ -358,34 +370,34 @@ void LibWebRTCPeerConnectionBackend::replaceTrack(RTCRtpSender& sender, Ref<Medi
     switch (currentTrack->source().type()) {
     case RealtimeMediaSource::Type::None:
         ASSERT_NOT_REACHED();
-        promise.reject(INVALID_MODIFICATION_ERR);
+        promise.reject(InvalidModificationError);
         break;
     case RealtimeMediaSource::Type::Audio: {
         for (auto& audioSource : m_audioSources) {
             if (&audioSource->source() == &currentTrack->privateTrack()) {
                 if (!audioSource->setSource(track->privateTrack())) {
-                    promise.reject(INVALID_MODIFICATION_ERR);
+                    promise.reject(InvalidModificationError);
                     return;
                 }
                 connection().enqueueReplaceTrackTask(sender, WTFMove(track), WTFMove(promise));
                 return;
             }
         }
-        promise.reject(INVALID_MODIFICATION_ERR);
+        promise.reject(InvalidModificationError);
         break;
     }
     case RealtimeMediaSource::Type::Video: {
         for (auto& videoSource : m_videoSources) {
             if (&videoSource->source() == &currentTrack->privateTrack()) {
                 if (!videoSource->setSource(track->privateTrack())) {
-                    promise.reject(INVALID_MODIFICATION_ERR);
+                    promise.reject(InvalidModificationError);
                     return;
                 }
                 connection().enqueueReplaceTrackTask(sender, WTFMove(track), WTFMove(promise));
                 return;
             }
         }
-        promise.reject(INVALID_MODIFICATION_ERR);
+        promise.reject(InvalidModificationError);
         break;
     }
     }