Add support for sender/receiver getCapabilities
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Nov 2018 04:01:49 +0000 (04:01 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Nov 2018 04:01:49 +0000 (04:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191192

Reviewed by Eric Carlson.

LayoutTests/imported/w3c:

* web-platform-tests/webrtc/RTCRtpCapabilities-helper.js:
(string_appeared_here.validateRtpCapabilities): Change already made upstream.
* web-platform-tests/webrtc/RTCRtpReceiver-getCapabilities-expected.txt:
* web-platform-tests/webrtc/RTCRtpSender-getCapabilities-expected.txt:
* web-platform-tests/webrtc/RTCRtpTransceiver-setCodecPreferences-expected.txt:

Source/WebCore:

Expose sender/receiver RTCRtpCapabilities to JS.
Add corresponding IDL and plumbing down to libwebrtc peer connection factory.
Covered by rebased tests.

* CMakeLists.txt:
* DerivedSources.make:
* Modules/mediastream/PeerConnectionBackend.cpp:
(WebCore::PeerConnectionBackend::receiverCapabilities):
(WebCore::PeerConnectionBackend::senderCapabilities):
* Modules/mediastream/PeerConnectionBackend.h:
* Modules/mediastream/RTCRtpCapabilities.idl: Added.
* Modules/mediastream/RTCRtpReceiver.cpp:
(WebCore::RTCRtpReceiver::getCapabilities):
* Modules/mediastream/RTCRtpReceiver.h:
* Modules/mediastream/RTCRtpReceiver.idl:
* Modules/mediastream/RTCRtpSender.cpp:
(WebCore::RTCRtpSender::getCapabilities):
* Modules/mediastream/RTCRtpSender.h:
* Modules/mediastream/RTCRtpSender.idl:
* Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:
(WebCore::PeerConnectionBackend::receiverCapabilities):
(WebCore::PeerConnectionBackend::senderCapabilities):
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* platform/mediastream/RTCPMuxPolicy.h:
* platform/mediastream/RTCRtpCapabilities.h: Added.
* platform/mediastream/libwebrtc/LibWebRTCProvider.cpp:
(WebCore::typeFromKind):
(WebCore::fromStdString):
(WebCore::toChannels):
(WebCore::toRTCRtpCapabilities):
(WebCore::LibWebRTCProvider::receiverCapabilities):
(WebCore::LibWebRTCProvider::senderCapabilities):
* platform/mediastream/libwebrtc/LibWebRTCProvider.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237911 268f45cc-cd09-0410-ab3c-d52691b4dbfc

22 files changed:
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCRtpReceiver-getCapabilities-expected.txt
LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCRtpSender-getCapabilities-expected.txt
LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCRtpTransceiver-setCodecPreferences-expected.txt
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.make
Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp
Source/WebCore/Modules/mediastream/PeerConnectionBackend.h
Source/WebCore/Modules/mediastream/RTCRtpCapabilities.idl [new file with mode: 0644]
Source/WebCore/Modules/mediastream/RTCRtpReceiver.cpp
Source/WebCore/Modules/mediastream/RTCRtpReceiver.h
Source/WebCore/Modules/mediastream/RTCRtpReceiver.idl
Source/WebCore/Modules/mediastream/RTCRtpSender.cpp
Source/WebCore/Modules/mediastream/RTCRtpSender.h
Source/WebCore/Modules/mediastream/RTCRtpSender.idl
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/mediastream/RTCRtpCapabilities.h [new file with mode: 0644]
Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.cpp
Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.h

index 0699dfd..ec401ca 100644 (file)
@@ -1,5 +1,18 @@
 2018-11-06  Youenn Fablet  <youenn@apple.com>
 
+        Add support for sender/receiver getCapabilities
+        https://bugs.webkit.org/show_bug.cgi?id=191192
+
+        Reviewed by Eric Carlson.
+
+        * web-platform-tests/webrtc/RTCRtpCapabilities-helper.js:
+        (string_appeared_here.validateRtpCapabilities): Change already made upstream.
+        * web-platform-tests/webrtc/RTCRtpReceiver-getCapabilities-expected.txt:
+        * web-platform-tests/webrtc/RTCRtpSender-getCapabilities-expected.txt:
+        * web-platform-tests/webrtc/RTCRtpTransceiver-setCodecPreferences-expected.txt:
+
+2018-11-06  Youenn Fablet  <youenn@apple.com>
+
         Support onremovetrack for RTCPeerConnection removed tracks
         https://bugs.webkit.org/show_bug.cgi?id=191299
 
index ab9317a..93321c3 100644 (file)
@@ -1,5 +1,5 @@
 
-FAIL RTCRtpSender.getCapabilities('audio') should return RTCRtpCapabilities dictionary RTCRtpReceiver.getCapabilities is not a function. (In 'RTCRtpReceiver.getCapabilities('audio')', 'RTCRtpReceiver.getCapabilities' is undefined)
-FAIL RTCRtpSender.getCapabilities('video') should return RTCRtpCapabilities dictionary RTCRtpReceiver.getCapabilities is not a function. (In 'RTCRtpReceiver.getCapabilities('video')', 'RTCRtpReceiver.getCapabilities' is undefined)
-FAIL RTCRtpSender.getCapabilities('dummy') should return null RTCRtpReceiver.getCapabilities is not a function. (In 'RTCRtpReceiver.getCapabilities('dummy')', 'RTCRtpReceiver.getCapabilities' is undefined)
+PASS RTCRtpSender.getCapabilities('audio') should return RTCRtpCapabilities dictionary 
+PASS RTCRtpSender.getCapabilities('video') should return RTCRtpCapabilities dictionary 
+PASS RTCRtpSender.getCapabilities('dummy') should return null 
 
index 461e028..93321c3 100644 (file)
@@ -1,5 +1,5 @@
 
-FAIL RTCRtpSender.getCapabilities('audio') should return RTCRtpCapabilities dictionary RTCRtpSender.getCapabilities is not a function. (In 'RTCRtpSender.getCapabilities('audio')', 'RTCRtpSender.getCapabilities' is undefined)
-FAIL RTCRtpSender.getCapabilities('video') should return RTCRtpCapabilities dictionary RTCRtpSender.getCapabilities is not a function. (In 'RTCRtpSender.getCapabilities('video')', 'RTCRtpSender.getCapabilities' is undefined)
-FAIL RTCRtpSender.getCapabilities('dummy') should return null RTCRtpSender.getCapabilities is not a function. (In 'RTCRtpSender.getCapabilities('dummy')', 'RTCRtpSender.getCapabilities' is undefined)
+PASS RTCRtpSender.getCapabilities('audio') should return RTCRtpCapabilities dictionary 
+PASS RTCRtpSender.getCapabilities('video') should return RTCRtpCapabilities dictionary 
+PASS RTCRtpSender.getCapabilities('dummy') should return null 
 
index d259b42..c048ec8 100644 (file)
@@ -1,11 +1,11 @@
 
-FAIL setCodecPreferences() on audio transceiver with codecs returned from RTCRtpSender.getCapabilities('audio') should succeed RTCRtpSender.getCapabilities is not a function. (In 'RTCRtpSender.getCapabilities('audio')', 'RTCRtpSender.getCapabilities' is undefined)
-FAIL setCodecPreferences() on video transceiver with codecs returned from RTCRtpReceiver.getCapabilities('video') should succeed RTCRtpReceiver.getCapabilities is not a function. (In 'RTCRtpReceiver.getCapabilities('video')', 'RTCRtpReceiver.getCapabilities' is undefined)
-FAIL setCodecPreferences() with both sender receiver codecs combined should succeed RTCRtpSender.getCapabilities is not a function. (In 'RTCRtpSender.getCapabilities('audio')', 'RTCRtpSender.getCapabilities' is undefined)
+FAIL setCodecPreferences() on audio transceiver with codecs returned from RTCRtpSender.getCapabilities('audio') should succeed transceiver.setCodecPreferences is not a function. (In 'transceiver.setCodecPreferences(capabilities.codecs)', 'transceiver.setCodecPreferences' is undefined)
+FAIL setCodecPreferences() on video transceiver with codecs returned from RTCRtpReceiver.getCapabilities('video') should succeed transceiver.setCodecPreferences is not a function. (In 'transceiver.setCodecPreferences(capabilities.codecs)', 'transceiver.setCodecPreferences' is undefined)
+FAIL setCodecPreferences() with both sender receiver codecs combined should succeed transceiver.setCodecPreferences is not a function. (In 'transceiver.setCodecPreferences([...capabilities1.codecs, ... capabilities2.codecs])', 'transceiver.setCodecPreferences' is undefined)
 FAIL setCodecPreferences([]) should succeed transceiver.setCodecPreferences is not a function. (In 'transceiver.setCodecPreferences([])', 'transceiver.setCodecPreferences' is undefined)
-FAIL setCodecPreferences() with reordered codecs should succeed RTCRtpSender.getCapabilities is not a function. (In 'RTCRtpSender.getCapabilities('audio')', 'RTCRtpSender.getCapabilities' is undefined)
-FAIL setCodecPreferences() on audio transceiver with codecs returned from getCapabilities('video') should throw InvalidAccessError RTCRtpSender.getCapabilities is not a function. (In 'RTCRtpSender.getCapabilities('video')', 'RTCRtpSender.getCapabilities' is undefined)
+FAIL setCodecPreferences() with reordered codecs should succeed transceiver.setCodecPreferences is not a function. (In 'transceiver.setCodecPreferences(codecs)', 'transceiver.setCodecPreferences' is undefined)
+FAIL setCodecPreferences() on audio transceiver with codecs returned from getCapabilities('video') should throw InvalidAccessError Test bug: unrecognized DOMException code "() => transceiver.setCodecPreferences(capabilities.codecs)" passed to assert_throws()
 FAIL setCodecPreferences() with user defined codec should throw InvalidAccessError Test bug: unrecognized DOMException code "() => transceiver.setCodecPreferences(codecs)" passed to assert_throws()
-FAIL setCodecPreferences() with user defined codec together with codecs returned from getCapabilities() should throw InvalidAccessError RTCRtpSender.getCapabilities is not a function. (In 'RTCRtpSender.getCapabilities('audio')', 'RTCRtpSender.getCapabilities' is undefined)
-FAIL setCodecPreferences() with modified codecs returned from getCapabilities() should throw InvalidAccessError RTCRtpSender.getCapabilities is not a function. (In 'RTCRtpSender.getCapabilities('audio')', 'RTCRtpSender.getCapabilities' is undefined)
+FAIL setCodecPreferences() with user defined codec together with codecs returned from getCapabilities() should throw InvalidAccessError Test bug: unrecognized DOMException code "() => transceiver.setCodecPreferences(codecs)" passed to assert_throws()
+FAIL setCodecPreferences() with modified codecs returned from getCapabilities() should throw InvalidAccessError Test bug: unrecognized DOMException code "() => transceiver.setCodecPreferences(codecs)" passed to assert_throws()
 
index 3f1bfc5..22321d1 100644 (file)
@@ -333,6 +333,7 @@ set(WebCore_NON_SVG_IDL_FILES
     Modules/mediastream/RTCPeerConnectionIceEvent.idl
     Modules/mediastream/RTCPeerConnectionState.idl
     Modules/mediastream/RTCPriorityType.idl
+    Modules/mediastream/RTCRtpCapabilities.idl
     Modules/mediastream/RTCRtpCodecParameters.idl
     Modules/mediastream/RTCRtpContributingSource.idl
     Modules/mediastream/RTCRtpEncodingParameters.idl
index 9f88e1e..83d46fd 100644 (file)
@@ -1,5 +1,47 @@
 2018-11-06  Youenn Fablet  <youenn@apple.com>
 
+        Add support for sender/receiver getCapabilities
+        https://bugs.webkit.org/show_bug.cgi?id=191192
+
+        Reviewed by Eric Carlson.
+
+        Expose sender/receiver RTCRtpCapabilities to JS.
+        Add corresponding IDL and plumbing down to libwebrtc peer connection factory.
+        Covered by rebased tests.
+
+        * CMakeLists.txt:
+        * DerivedSources.make:
+        * Modules/mediastream/PeerConnectionBackend.cpp:
+        (WebCore::PeerConnectionBackend::receiverCapabilities):
+        (WebCore::PeerConnectionBackend::senderCapabilities):
+        * Modules/mediastream/PeerConnectionBackend.h:
+        * Modules/mediastream/RTCRtpCapabilities.idl: Added.
+        * Modules/mediastream/RTCRtpReceiver.cpp:
+        (WebCore::RTCRtpReceiver::getCapabilities):
+        * Modules/mediastream/RTCRtpReceiver.h:
+        * Modules/mediastream/RTCRtpReceiver.idl:
+        * Modules/mediastream/RTCRtpSender.cpp:
+        (WebCore::RTCRtpSender::getCapabilities):
+        * Modules/mediastream/RTCRtpSender.h:
+        * Modules/mediastream/RTCRtpSender.idl:
+        * Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:
+        (WebCore::PeerConnectionBackend::receiverCapabilities):
+        (WebCore::PeerConnectionBackend::senderCapabilities):
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/mediastream/RTCPMuxPolicy.h:
+        * platform/mediastream/RTCRtpCapabilities.h: Added.
+        * platform/mediastream/libwebrtc/LibWebRTCProvider.cpp:
+        (WebCore::typeFromKind):
+        (WebCore::fromStdString):
+        (WebCore::toChannels):
+        (WebCore::toRTCRtpCapabilities):
+        (WebCore::LibWebRTCProvider::receiverCapabilities):
+        (WebCore::LibWebRTCProvider::senderCapabilities):
+        * platform/mediastream/libwebrtc/LibWebRTCProvider.h:
+
+2018-11-06  Youenn Fablet  <youenn@apple.com>
+
         Calling sender.replaceTrack() twice produces a new transceiver and its corresponding m= section
         https://bugs.webkit.org/show_bug.cgi?id=191261
 
index 255cd3a..526ed08 100644 (file)
@@ -254,6 +254,7 @@ JS_BINDING_IDLS = \
     $(WebCore)/Modules/mediastream/RTCOfferOptions.idl \
     $(WebCore)/Modules/mediastream/RTCPeerConnection.idl \
     $(WebCore)/Modules/mediastream/RTCPeerConnectionState.idl \
+    $(WebCore)/Modules/mediastream/RTCRtpCapabilities.idl \
     $(WebCore)/Modules/mediastream/RTCRtpCodecParameters.idl \
     $(WebCore)/Modules/mediastream/RTCRtpContributingSource.idl \
     $(WebCore)/Modules/mediastream/RTCRtpEncodingParameters.idl \
index 8ba1a40..d20dbca 100644 (file)
@@ -42,6 +42,7 @@
 #include "RTCIceCandidate.h"
 #include "RTCPeerConnection.h"
 #include "RTCPeerConnectionIceEvent.h"
+#include "RTCRtpCapabilities.h"
 #include "RuntimeEnabledFeatures.h"
 #include <wtf/text/StringBuilder.h>
 #include <wtf/text/StringConcatenateNumbers.h>
@@ -57,6 +58,18 @@ static std::unique_ptr<PeerConnectionBackend> createNoPeerConnectionBackend(RTCP
 }
 
 CreatePeerConnectionBackend PeerConnectionBackend::create = createNoPeerConnectionBackend;
+
+std::optional<RTCRtpCapabilities> PeerConnectionBackend::receiverCapabilities(ScriptExecutionContext&, const String&)
+{
+    ASSERT_NOT_REACHED();
+    return { };
+}
+
+std::optional<RTCRtpCapabilities> PeerConnectionBackend::senderCapabilities(ScriptExecutionContext&, const String&)
+{
+    ASSERT_NOT_REACHED();
+    return { };
+}
 #endif
 
 PeerConnectionBackend::PeerConnectionBackend(RTCPeerConnection& peerConnection)
index 56f6f09..f62a7b2 100644 (file)
@@ -79,6 +79,9 @@ class PeerConnectionBackend
 public:
     WEBCORE_EXPORT static CreatePeerConnectionBackend create;
 
+    static std::optional<RTCRtpCapabilities> receiverCapabilities(ScriptExecutionContext&, const String& kind);
+    static std::optional<RTCRtpCapabilities> senderCapabilities(ScriptExecutionContext&, const String& kind);
+
     explicit PeerConnectionBackend(RTCPeerConnection&);
     virtual ~PeerConnectionBackend() = default;
 
diff --git a/Source/WebCore/Modules/mediastream/RTCRtpCapabilities.idl b/Source/WebCore/Modules/mediastream/RTCRtpCapabilities.idl
new file mode 100644 (file)
index 0000000..8b22e26
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+[
+    Conditional=WEB_RTC,
+    EnabledAtRuntime=PeerConnection,
+    JSGenerateToJSObject
+] dictionary RTCRtpCodecCapability {
+    required DOMString mimeType;
+    required unsigned long clockRate;
+    unsigned short channels;
+    DOMString sdpFmtpLine;
+};
+
+[
+    Conditional=WEB_RTC,
+    EnabledAtRuntime=PeerConnection,
+    JSGenerateToJSObject
+] dictionary RTCRtpHeaderExtensionCapability {
+    DOMString uri;
+};
+
+[
+    Conditional=WEB_RTC,
+    EnabledAtRuntime=PeerConnection,
+    JSGenerateToJSObject
+] dictionary RTCRtpCapabilities {
+    required sequence<RTCRtpCodecCapability> codecs;
+    required sequence<RTCRtpHeaderExtensionCapability> headerExtensions;
+};
index 2e6ddc4..7ffb5c8 100644 (file)
@@ -32,7 +32,9 @@
 #include "RTCRtpReceiver.h"
 
 #if ENABLE(WEB_RTC)
+
 #include "PeerConnectionBackend.h"
+#include "RTCRtpCapabilities.h"
 
 namespace WebCore {
 
@@ -61,6 +63,11 @@ void RTCRtpReceiver::getStats(Ref<DeferredPromise>&& promise)
     m_connection->getStats(*this, WTFMove(promise));
 }
 
+std::optional<RTCRtpCapabilities> RTCRtpReceiver::getCapabilities(ScriptExecutionContext& context, const String& kind)
+{
+    return PeerConnectionBackend::receiverCapabilities(context, kind);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(WEB_RTC)
index b4fee60..97feb81 100644 (file)
@@ -40,6 +40,7 @@
 namespace WebCore {
 
 class PeerConnectionBackend;
+struct RTCRtpCapabilities;
 
 class RTCRtpReceiver : public RefCounted<RTCRtpReceiver>, public ScriptWrappable  {
 public:
@@ -48,6 +49,8 @@ public:
         return adoptRef(*new RTCRtpReceiver(connection, WTFMove(track), WTFMove(backend)));
     }
 
+    static std::optional<RTCRtpCapabilities> getCapabilities(ScriptExecutionContext&, const String& kind);
+
     void stop();
 
     void setBackend(std::unique_ptr<RTCRtpReceiverBackend>&& backend) { m_backend = WTFMove(backend); }
index 9d8565a..287dcec 100644 (file)
     ImplementationLacksVTable
 ] interface RTCRtpReceiver {
     readonly attribute MediaStreamTrack track;
-    RTCRtpParameters getParameters();
     // FIXME 169662: missing transport
     // FIXME 169662: missing rtcpTransport
-    // FIXME 169662: missing getCapabilities
+    [CallWith=ScriptExecutionContext] static RTCRtpCapabilities? getCapabilities(DOMString kind);
+    RTCRtpParameters getParameters();
     sequence<RTCRtpContributingSource> getContributingSources();
     sequence<RTCRtpSynchronizationSource> getSynchronizationSources();
     Promise<RTCStatsReport> getStats();
index a18c02f..ef39647 100644 (file)
@@ -33,6 +33,7 @@
 
 #if ENABLE(WEB_RTC)
 
+#include "RTCRtpCapabilities.h"
 #include "RuntimeEnabledFeatures.h"
 
 namespace WebCore {
@@ -121,6 +122,11 @@ void RTCRtpSender::getStats(Ref<DeferredPromise>&& promise)
     m_connection->getStats(*this, WTFMove(promise));
 }
 
+std::optional<RTCRtpCapabilities> RTCRtpSender::getCapabilities(ScriptExecutionContext& context, const String& kind)
+{
+    return PeerConnectionBackend::senderCapabilities(context, kind);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(WEB_RTC)
index 49aad3e..46cfa6a 100644 (file)
 namespace WebCore {
 
 class PeerConnectionBackend;
+struct RTCRtpCapabilities;
 
 class RTCRtpSender : public RefCounted<RTCRtpSender>, public ScriptWrappable {
 public:
     static Ref<RTCRtpSender> create(PeerConnectionBackend&, Ref<MediaStreamTrack>&&, Vector<String>&& mediaStreamIds, std::unique_ptr<RTCRtpSenderBackend>&&);
     static Ref<RTCRtpSender> create(PeerConnectionBackend&, String&& trackKind, Vector<String>&& mediaStreamIds, std::unique_ptr<RTCRtpSenderBackend>&&);
 
+    static std::optional<RTCRtpCapabilities> getCapabilities(ScriptExecutionContext&, const String& kind);
+
     MediaStreamTrack* track() { return m_track.get(); }
 
     const String& trackId() const { return m_trackId; }
index 09cdb8e..3c202a6 100644 (file)
@@ -37,8 +37,8 @@
     readonly attribute MediaStreamTrack? track;
     // FIXME 169662: missing transport
     // FIXME 169662: missing rtcpTransport
-    // FIXME 169662: missing getCapabilities
     // FIXME 169662: missing setStreams
+    [CallWith=ScriptExecutionContext] static RTCRtpCapabilities? getCapabilities(DOMString kind);
     RTCRtpSendParameters getParameters();
     Promise<void> setParameters(RTCRtpSendParameters parameters);
     [CallWith=ScriptExecutionContext] Promise<void> replaceTrack(MediaStreamTrack? withTrack);
index 6979ceb..fbadf68 100644 (file)
@@ -38,6 +38,7 @@
 #include "Page.h"
 #include "RTCIceCandidate.h"
 #include "RTCPeerConnection.h"
+#include "RTCRtpCapabilities.h"
 #include "RTCRtpReceiver.h"
 #include "RTCSessionDescription.h"
 #include "RealtimeIncomingAudioSource.h"
@@ -65,6 +66,22 @@ static std::unique_ptr<PeerConnectionBackend> createLibWebRTCPeerConnectionBacke
 
 CreatePeerConnectionBackend PeerConnectionBackend::create = createLibWebRTCPeerConnectionBackend;
 
+std::optional<RTCRtpCapabilities> PeerConnectionBackend::receiverCapabilities(ScriptExecutionContext& context, const String& kind)
+{
+    auto* page = downcast<Document>(context).page();
+    if (!page)
+        return { };
+    return page->libWebRTCProvider().receiverCapabilities(kind);
+}
+
+std::optional<RTCRtpCapabilities> PeerConnectionBackend::senderCapabilities(ScriptExecutionContext& context, const String& kind)
+{
+    auto* page = downcast<Document>(context).page();
+    if (!page)
+        return { };
+    return page->libWebRTCProvider().senderCapabilities(kind);
+}
+
 LibWebRTCPeerConnectionBackend::LibWebRTCPeerConnectionBackend(RTCPeerConnection& peerConnection, LibWebRTCProvider& provider)
     : PeerConnectionBackend(peerConnection)
     , m_endpoint(LibWebRTCMediaEndpoint::create(*this, provider))
index b8d32d9..4392b08 100644 (file)
@@ -2936,6 +2936,7 @@ JSRTCPeerConnection.cpp
 JSRTCPeerConnectionIceEvent.cpp
 JSRTCPeerConnectionState.cpp
 JSRTCPriorityType.cpp
+JSRTCRtpCapabilities.cpp
 JSRTCRtpCodecParameters.cpp
 JSRTCRtpContributingSource.cpp
 JSRTCRtpEncodingParameters.cpp
index fbfc758..e1a41bc 100644 (file)
                4129C9AB1F59C573009D7403 /* ReadableStreamSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 418C395B1C8F0A610051C8A3 /* ReadableStreamSource.h */; settings = {ATTRIBUTES = (Private, ); }; };
                4129C9AF1F59CF5B009D7403 /* ReadableStreamSink.h in Headers */ = {isa = PBXBuildFile; fileRef = 4129C9801F5861C7009D7403 /* ReadableStreamSink.h */; settings = {ATTRIBUTES = (Private, ); }; };
                4129DF861BB5B80C00322A16 /* JSReadableStreamPrivateConstructors.h in Headers */ = {isa = PBXBuildFile; fileRef = 4129DF841BB5B7F700322A16 /* JSReadableStreamPrivateConstructors.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               412DE4B8219285C00075F3A7 /* RTCRtpCapabilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 412DE4B6219285BF0075F3A7 /* RTCRtpCapabilities.h */; };
                4133CB8B20F80E9900E89B11 /* MediaStreamAudioSourceCocoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4133CB8920F80E8600E89B11 /* MediaStreamAudioSourceCocoa.cpp */; };
                41380C271F3436AC00155FDA /* DOMCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 41380C251F34369A00155FDA /* DOMCache.h */; };
                41380C291F3436AC00155FDA /* DOMCacheStorage.h in Headers */ = {isa = PBXBuildFile; fileRef = 41380C221F34369000155FDA /* DOMCacheStorage.h */; };
                4129DF831BB5B7F700322A16 /* JSReadableStreamPrivateConstructors.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSReadableStreamPrivateConstructors.cpp; sourceTree = "<group>"; };
                4129DF841BB5B7F700322A16 /* JSReadableStreamPrivateConstructors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSReadableStreamPrivateConstructors.h; sourceTree = "<group>"; };
                412BA5FE218C651800365474 /* RTCPMuxPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RTCPMuxPolicy.h; sourceTree = "<group>"; };
+               412DE4B6219285BF0075F3A7 /* RTCRtpCapabilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RTCRtpCapabilities.h; sourceTree = "<group>"; };
                413015D51C7B570400091C6E /* FetchResponse.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FetchResponse.cpp; sourceTree = "<group>"; };
                413015D51C7B570400091C6F /* FetchBodySource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FetchBodySource.cpp; sourceTree = "<group>"; };
                413015D61C7B570400091C6E /* FetchResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchResponse.h; sourceTree = "<group>"; };
                4131F3B41F955BC30059995A /* ExtendableEventInit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExtendableEventInit.h; sourceTree = "<group>"; };
                4131F3B51F955BC50059995A /* ExtendableEventInit.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ExtendableEventInit.idl; sourceTree = "<group>"; };
                4133CB8920F80E8600E89B11 /* MediaStreamAudioSourceCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaStreamAudioSourceCocoa.cpp; sourceTree = "<group>"; };
+               41369E55218C76E300792E29 /* RTCRtpCapabilities.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = RTCRtpCapabilities.idl; sourceTree = "<group>"; };
                41380C201F34368A00155FDA /* DOMCache.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = DOMCache.cpp; path = Modules/cache/DOMCache.cpp; sourceTree = SOURCE_ROOT; };
                41380C211F34368D00155FDA /* DOMCacheStorage.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = DOMCacheStorage.cpp; path = Modules/cache/DOMCacheStorage.cpp; sourceTree = SOURCE_ROOT; };
                41380C221F34369000155FDA /* DOMCacheStorage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = DOMCacheStorage.h; path = Modules/cache/DOMCacheStorage.h; sourceTree = SOURCE_ROOT; };
                                41A48A9C1E83129100D2AC2D /* RTCPeerConnectionState.idl */,
                                41FCB75C214866FE0038ADC6 /* RTCPriorityType.h */,
                                41E593FD214865A900D3CB61 /* RTCPriorityType.idl */,
+                               41369E55218C76E300792E29 /* RTCRtpCapabilities.idl */,
                                41FCB75F214866FF0038ADC6 /* RTCRtpCodecParameters.h */,
                                41FCB759214865D30038ADC6 /* RTCRtpCodecParameters.idl */,
                                414AD3FF21498D3000521676 /* RTCRtpCodingParameters.h */,
                                07221BAA17CF0AD400848E51 /* RTCPeerConnectionHandlerClient.h */,
                                41A48A9D1E8312EB00D2AC2D /* RTCPeerConnectionState.h */,
                                412BA5FE218C651800365474 /* RTCPMuxPolicy.h */,
+                               412DE4B6219285BF0075F3A7 /* RTCRtpCapabilities.h */,
                                31EB54DD1E7DC74400C1623B /* RTCRtpTransceiverDirection.h */,
                                313591041E7DDC6000F30630 /* RTCSdpType.h */,
                                07221BAB17CF0AD400848E51 /* RTCSessionDescriptionDescriptor.cpp */,
                                51E399021D6E4750009C8831 /* GameControllerGamepadProvider.h in Headers */,
                                516C62211950D48700337E75 /* GamepadEvent.h in Headers */,
                                51A9D9EA195B931F001B2B5C /* GamepadManager.h in Headers */,
+                               412DE4B8219285C00075F3A7 /* RTCRtpCapabilities.h in Headers */,
                                515BE1921D54F5FB00DD7C68 /* GamepadProvider.h in Headers */,
                                515BE1931D54F5FB00DD7C68 /* GamepadProviderClient.h in Headers */,
                                8EC6C963201A251600FBFA53 /* GapLength.h in Headers */,
diff --git a/Source/WebCore/platform/mediastream/RTCRtpCapabilities.h b/Source/WebCore/platform/mediastream/RTCRtpCapabilities.h
new file mode 100644 (file)
index 0000000..3fa6644
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEB_RTC)
+
+#include <wtf/Vector.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+struct RTCRtpCapabilities {
+    struct CodecCapability {
+        String mimeType;
+        uint32_t clockRate { 0 };
+        std::optional<uint16_t> channels;
+        String sdpFmtpLine;
+    };
+    struct HeaderExtensionCapability {
+        String uri;
+    };
+
+    Vector<CodecCapability> codecs;
+    Vector<HeaderExtensionCapability> headerExtensions;
+};
+
+}; // namespace WebCore
+
+#endif
index e981196..edc70eb 100644 (file)
@@ -29,6 +29,7 @@
 #if USE(LIBWEBRTC)
 #include "LibWebRTCAudioModule.h"
 #include "Logging.h"
+#include "RTCRtpCapabilities.h"
 #include <dlfcn.h>
 
 ALLOW_UNUSED_PARAMETERS_BEGIN
@@ -280,6 +281,68 @@ rtc::RTCCertificateGenerator& LibWebRTCProvider::certificateGenerator()
     return *factoryAndThreads.certificateGenerator;
 }
 
+static inline std::optional<cricket::MediaType> typeFromKind(const String& kind)
+{
+    if (kind == "audio"_s)
+        return cricket::MediaType::MEDIA_TYPE_AUDIO;
+    if (kind == "video"_s)
+        return cricket::MediaType::MEDIA_TYPE_VIDEO;
+    return { };
+}
+
+static inline String fromStdString(const std::string& value)
+{
+    return String::fromUTF8(value.data(), value.length());
+}
+
+static inline std::optional<uint16_t> toChannels(absl::optional<int> numChannels)
+{
+    if (!numChannels)
+        return { };
+    return static_cast<uint32_t>(*numChannels);
+}
+
+static inline RTCRtpCapabilities toRTCRtpCapabilities(const webrtc::RtpCapabilities& rtpCapabilities)
+{
+    RTCRtpCapabilities capabilities;
+
+    capabilities.codecs.reserveInitialCapacity(rtpCapabilities.codecs.size());
+    for (auto& codec : rtpCapabilities.codecs)
+        capabilities.codecs.uncheckedAppend(RTCRtpCapabilities::CodecCapability { fromStdString(codec.mime_type()), static_cast<uint32_t>(codec.clock_rate ? *codec.clock_rate : 0), toChannels(codec.num_channels), { } });
+
+    capabilities.headerExtensions.reserveInitialCapacity(rtpCapabilities.header_extensions.size());
+    for (auto& header : rtpCapabilities.header_extensions)
+        capabilities.headerExtensions.uncheckedAppend(RTCRtpCapabilities::HeaderExtensionCapability { fromStdString(header.uri) });
+
+    return capabilities;
+}
+
+std::optional<RTCRtpCapabilities> LibWebRTCProvider::receiverCapabilities(const String& kind)
+{
+    auto mediaType = typeFromKind(kind);
+    if (!mediaType)
+        return { };
+
+    auto* factory = this->factory();
+    if (!factory)
+        return { };
+
+    return toRTCRtpCapabilities(factory->GetRtpReceiverCapabilities(*mediaType));
+}
+
+std::optional<RTCRtpCapabilities> LibWebRTCProvider::senderCapabilities(const String& kind)
+{
+    auto mediaType = typeFromKind(kind);
+    if (!mediaType)
+        return { };
+
+    auto* factory = this->factory();
+    if (!factory)
+        return { };
+
+    return toRTCRtpCapabilities(factory->GetRtpSenderCapabilities(*mediaType));
+}
+
 #endif // USE(LIBWEBRTC)
 
 } // namespace WebCore
index 5d12e7b..c249427 100644 (file)
@@ -59,6 +59,7 @@ class PeerConnectionFactoryInterface;
 namespace WebCore {
 
 class LibWebRTCAudioModule;
+struct RTCRtpCapabilities;
 
 enum class MDNSRegisterError { NotImplemented, BadParameter, DNSSD, Internal, Timeout };
 
@@ -109,6 +110,9 @@ public:
 
     rtc::RTCCertificateGenerator& certificateGenerator();
 
+    std::optional<RTCRtpCapabilities> receiverCapabilities(const String& kind);
+    std::optional<RTCRtpCapabilities> senderCapabilities(const String& kind);
+
 protected:
     LibWebRTCProvider() = default;