Expose RTCRtpSender.setParameters
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Sep 2018 22:30:04 +0000 (22:30 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Sep 2018 22:30:04 +0000 (22:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=189307

Reviewed by Eric Carlson.

LayoutTests/imported/w3c:

* web-platform-tests/webrtc/RTCRtpSender-replaceTrack-expected.txt:
* web-platform-tests/webrtc/RTCRtpSender-setParameters-expected.txt:

Source/ThirdParty/libwebrtc:

* Configurations/libwebrtc.iOS.exp:
* Configurations/libwebrtc.iOSsim.exp:
* Configurations/libwebrtc.mac.exp:

Source/WebCore:

Implement RTCRtpSender.setParameters.
This is an incomplete implementation as we need to refresh parameters as per the spec and testing is much easier with full transceiver support.
Implementation uses sender backend to set the parameters at libwebrtc level.
Fix the case of a stopped sender/transceiver in which case promise should be rejected.
Covered by rebased and modified tests.

* Modules/mediastream/RTCRtpParameters.h:
* Modules/mediastream/RTCRtpSender.cpp:
(WebCore::RTCRtpSender::setParameters):
* Modules/mediastream/RTCRtpSender.h:
* Modules/mediastream/RTCRtpSender.idl:
* Modules/mediastream/RTCRtpSenderBackend.h:
* Modules/mediastream/RTCRtpTransceiver.cpp:
(WebCore::RTCRtpTransceiver::stop):
* Modules/mediastream/RTCRtpTransceiver.h:
* Modules/mediastream/libwebrtc/LibWebRTCRtpReceiverBackend.cpp:
(WebCore::LibWebRTCRtpReceiverBackend::getParameters):
* Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.cpp:
(WebCore::LibWebRTCRtpSenderBackend::getParameters const):
(WebCore::LibWebRTCRtpSenderBackend::setParameters):
* Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.h:
* Modules/mediastream/libwebrtc/LibWebRTCUtils.cpp:
(WebCore::toRTCEncodingParameters):
(WebCore::fromRTCEncodingParameters):
(WebCore::toRTCHeaderExtensionParameters):
(WebCore::fromRTCHeaderExtensionParameters):
(WebCore::toRTCCodecParameters):
(WebCore::toRTCRtpParameters):
(WebCore::fromRTCRtpParameters):
* Modules/mediastream/libwebrtc/LibWebRTCUtils.h:

LayoutTests:

* webrtc/video-getParameters.html:

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

22 files changed:
LayoutTests/ChangeLog
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCRtpSender-replaceTrack-expected.txt
LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCRtpSender-setParameters-expected.txt
LayoutTests/webrtc/video-getParameters.html
Source/ThirdParty/libwebrtc/ChangeLog
Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOS.exp
Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOSsim.exp
Source/ThirdParty/libwebrtc/Configurations/libwebrtc.mac.exp
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/RTCRtpParameters.h
Source/WebCore/Modules/mediastream/RTCRtpSender.cpp
Source/WebCore/Modules/mediastream/RTCRtpSender.h
Source/WebCore/Modules/mediastream/RTCRtpSender.idl
Source/WebCore/Modules/mediastream/RTCRtpSenderBackend.h
Source/WebCore/Modules/mediastream/RTCRtpTransceiver.cpp
Source/WebCore/Modules/mediastream/RTCRtpTransceiver.h
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpReceiverBackend.cpp
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.cpp
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.h
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCUtils.cpp
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCUtils.h

index 08a953c..60be969 100644 (file)
@@ -1,3 +1,12 @@
+2018-09-05  Youenn Fablet  <youenn@apple.com>
+
+        Expose RTCRtpSender.setParameters
+        https://bugs.webkit.org/show_bug.cgi?id=189307
+
+        Reviewed by Eric Carlson.
+
+        * webrtc/video-getParameters.html:
+
 2018-09-05  Truitt Savell  <tsavell@apple.com>
 
         Rebaseline test after changes in https://trac.webkit.org/changeset/235669/webkit deleted the expectation. 
index cf7b31b..2eccbd8 100644 (file)
@@ -1,3 +1,13 @@
+2018-09-05  Youenn Fablet  <youenn@apple.com>
+
+        Expose RTCRtpSender.setParameters
+        https://bugs.webkit.org/show_bug.cgi?id=189307
+
+        Reviewed by Eric Carlson.
+
+        * web-platform-tests/webrtc/RTCRtpSender-replaceTrack-expected.txt:
+        * web-platform-tests/webrtc/RTCRtpSender-setParameters-expected.txt:
+
 2018-09-04  Frederic Wang  <fwang@igalia.com>
 
         Add basic support for ScrollIntoViewOptions
index 71f717f..fc64b50 100644 (file)
@@ -1,7 +1,7 @@
 
 PASS Calling replaceTrack on closed connection should reject with InvalidStateError 
 PASS Calling replaceTrack with track of different kind should reject with TypeError 
-FAIL Calling replaceTrack on stopped sender should reject with InvalidStateError assert_unreached: Should have rejected: undefined Reached unreachable code
+PASS Calling replaceTrack on stopped sender should reject with InvalidStateError 
 PASS Calling replaceTrack on sender with null track and not set to session description should resolve with sender.track set to given track 
 PASS Calling replaceTrack on sender not set to session description should resolve with sender.track set to given track 
 PASS Calling replaceTrack(null) on sender not set to session description should resolve with sender.track set to null 
index 156bd67..78a6005 100644 (file)
@@ -1,3 +1,3 @@
 
-FAIL setParameters() when transceiver is stopped should reject with InvalidStateError sender.setParameters is not a function. (In 'sender.setParameters(param)', 'sender.setParameters' is undefined)
+PASS setParameters() when transceiver is stopped should reject with InvalidStateError 
 
index 3b26908..e3a2931 100644 (file)
@@ -51,7 +51,7 @@ promise_test((test) => {
         assert_equals(JSON.stringify(senderParameters), JSON.stringify(receiverParameters), "testing sender vs. receiver parameters");
 
         senderParameters.encodings[0].ssrc = 1;
-        assert_equals(JSON.stringify(senderParameters), '{"codecs":[],"degradationPreference":"balanced","encodings":[{"active":true,"dtx":"disabled","fec":{"ssrc":1},"maxBitrate":0,"maxFramerate":0,"priority":"medium","rid":"","rtx":{"ssrc":1},"scaleResolutionDownBy":1,"ssrc":1}],"headerExtensions":[],"transactionId":""}', "Testing sanitized parameters");
+        assert_equals(JSON.stringify(senderParameters), '{"codecs":[],"degradationPreference":"balanced","encodings":[{"active":true,"fec":{"ssrc":1},"maxBitrate":0,"maxFramerate":0,"priority":"medium","rid":"","rtx":{"ssrc":1},"scaleResolutionDownBy":1,"ssrc":1}],"headerExtensions":[],"transactionId":""}', "Testing sanitized parameters");
     });
 }, "Basic video stats");
         </script>
index 1865dfa..ddec699 100644 (file)
@@ -1,3 +1,14 @@
+2018-09-05  Youenn Fablet  <youenn@apple.com>
+
+        Expose RTCRtpSender.setParameters
+        https://bugs.webkit.org/show_bug.cgi?id=189307
+
+        Reviewed by Eric Carlson.
+
+        * Configurations/libwebrtc.iOS.exp:
+        * Configurations/libwebrtc.iOSsim.exp:
+        * Configurations/libwebrtc.mac.exp:
+
 2018-08-29  David Kilzer  <ddkilzer@apple.com>
 
         Remove empty directories from from svn.webkit.org repository
index 8478b28..d64cdf0 100644 (file)
@@ -206,3 +206,9 @@ __ZN3rtc13PacketOptionsD1Ev
 __ZN3rtc19PacketSocketFactory21CreateClientTcpSocketERKNS_13SocketAddressES3_RKNS_9ProxyInfoERKNSt3__112basic_stringIcNS7_11char_traitsIcEENS7_9allocatorIcEEEERKNS_22PacketSocketTcpOptionsE
 __ZN3rtc13PacketOptionsC1Ev
 __ZN6webrtc27CreatePeerConnectionFactoryEPN3rtc6ThreadES2_S2_NS0_13scoped_refptrINS_17AudioDeviceModuleEEENS3_INS_19AudioEncoderFactoryEEENS3_INS_19AudioDecoderFactoryEEENSt3__110unique_ptrINS_19VideoEncoderFactoryENSA_14default_deleteISC_EEEENSB_INS_19VideoDecoderFactoryENSD_ISG_EEEENS3_INS_10AudioMixerEEENS3_INS_15AudioProcessingEEE
+__ZNK6webrtc8RTCError7messageEv
+__ZN6webrtc12RtpExtensionC1Ev
+__ZN6webrtc12RtpExtensionD1Ev
+__ZN6webrtc21RtpEncodingParametersC1ERKS0_
+__ZN6webrtc21RtpEncodingParametersC1Ev
+__ZN6webrtc21RtpEncodingParametersD1Ev
index 8478b28..4fc1c4a 100644 (file)
@@ -206,3 +206,10 @@ __ZN3rtc13PacketOptionsD1Ev
 __ZN3rtc19PacketSocketFactory21CreateClientTcpSocketERKNS_13SocketAddressES3_RKNS_9ProxyInfoERKNSt3__112basic_stringIcNS7_11char_traitsIcEENS7_9allocatorIcEEEERKNS_22PacketSocketTcpOptionsE
 __ZN3rtc13PacketOptionsC1Ev
 __ZN6webrtc27CreatePeerConnectionFactoryEPN3rtc6ThreadES2_S2_NS0_13scoped_refptrINS_17AudioDeviceModuleEEENS3_INS_19AudioEncoderFactoryEEENS3_INS_19AudioDecoderFactoryEEENSt3__110unique_ptrINS_19VideoEncoderFactoryENSA_14default_deleteISC_EEEENSB_INS_19VideoDecoderFactoryENSD_ISG_EEEENS3_INS_10AudioMixerEEENS3_INS_15AudioProcessingEEE
+__ZNK6webrtc8RTCError7messageEv
+__ZNK6webrtc8RTCError7messageEv
+__ZN6webrtc12RtpExtensionC1Ev
+__ZN6webrtc12RtpExtensionD1Ev
+__ZN6webrtc21RtpEncodingParametersC1ERKS0_
+__ZN6webrtc21RtpEncodingParametersC1Ev
+__ZN6webrtc21RtpEncodingParametersD1Ev
index 8478b28..4fc1c4a 100644 (file)
@@ -206,3 +206,10 @@ __ZN3rtc13PacketOptionsD1Ev
 __ZN3rtc19PacketSocketFactory21CreateClientTcpSocketERKNS_13SocketAddressES3_RKNS_9ProxyInfoERKNSt3__112basic_stringIcNS7_11char_traitsIcEENS7_9allocatorIcEEEERKNS_22PacketSocketTcpOptionsE
 __ZN3rtc13PacketOptionsC1Ev
 __ZN6webrtc27CreatePeerConnectionFactoryEPN3rtc6ThreadES2_S2_NS0_13scoped_refptrINS_17AudioDeviceModuleEEENS3_INS_19AudioEncoderFactoryEEENS3_INS_19AudioDecoderFactoryEEENSt3__110unique_ptrINS_19VideoEncoderFactoryENSA_14default_deleteISC_EEEENSB_INS_19VideoDecoderFactoryENSD_ISG_EEEENS3_INS_10AudioMixerEEENS3_INS_15AudioProcessingEEE
+__ZNK6webrtc8RTCError7messageEv
+__ZNK6webrtc8RTCError7messageEv
+__ZN6webrtc12RtpExtensionC1Ev
+__ZN6webrtc12RtpExtensionD1Ev
+__ZN6webrtc21RtpEncodingParametersC1ERKS0_
+__ZN6webrtc21RtpEncodingParametersC1Ev
+__ZN6webrtc21RtpEncodingParametersD1Ev
index e8c5174..99072ac 100644 (file)
@@ -1,3 +1,41 @@
+2018-09-05  Youenn Fablet  <youenn@apple.com>
+
+        Expose RTCRtpSender.setParameters
+        https://bugs.webkit.org/show_bug.cgi?id=189307
+
+        Reviewed by Eric Carlson.
+
+        Implement RTCRtpSender.setParameters.
+        This is an incomplete implementation as we need to refresh parameters as per the spec and testing is much easier with full transceiver support.
+        Implementation uses sender backend to set the parameters at libwebrtc level.
+        Fix the case of a stopped sender/transceiver in which case promise should be rejected.
+        Covered by rebased and modified tests.
+
+        * Modules/mediastream/RTCRtpParameters.h:
+        * Modules/mediastream/RTCRtpSender.cpp:
+        (WebCore::RTCRtpSender::setParameters):
+        * Modules/mediastream/RTCRtpSender.h:
+        * Modules/mediastream/RTCRtpSender.idl:
+        * Modules/mediastream/RTCRtpSenderBackend.h:
+        * Modules/mediastream/RTCRtpTransceiver.cpp:
+        (WebCore::RTCRtpTransceiver::stop):
+        * Modules/mediastream/RTCRtpTransceiver.h:
+        * Modules/mediastream/libwebrtc/LibWebRTCRtpReceiverBackend.cpp:
+        (WebCore::LibWebRTCRtpReceiverBackend::getParameters):
+        * Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.cpp:
+        (WebCore::LibWebRTCRtpSenderBackend::getParameters const):
+        (WebCore::LibWebRTCRtpSenderBackend::setParameters):
+        * Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.h:
+        * Modules/mediastream/libwebrtc/LibWebRTCUtils.cpp:
+        (WebCore::toRTCEncodingParameters):
+        (WebCore::fromRTCEncodingParameters):
+        (WebCore::toRTCHeaderExtensionParameters):
+        (WebCore::fromRTCHeaderExtensionParameters):
+        (WebCore::toRTCCodecParameters):
+        (WebCore::toRTCRtpParameters):
+        (WebCore::fromRTCRtpParameters):
+        * Modules/mediastream/libwebrtc/LibWebRTCUtils.h:
+
 2018-09-05  Simon Fraser  <simon.fraser@apple.com>
 
         Remove some logging that I committed by mistake.
index f0fc8ee..20171b5 100644 (file)
@@ -57,7 +57,7 @@ struct RTCRtpParameters {
         unsigned long ssrc { 0 };
         RtxParameters rtx;
         FecParameters fec;
-        DtxStatus dtx { DtxStatus::Disabled };
+        std::optional<DtxStatus> dtx;
         bool active { false};
         PriorityType priority { PriorityType::Medium };
         unsigned long maxBitrate { 0 };
index 5acdd46..2b5b3c6 100644 (file)
@@ -99,6 +99,15 @@ RTCRtpParameters RTCRtpSender::getParameters()
     return m_backend->getParameters();
 }
 
+void RTCRtpSender::setParameters(const RTCRtpParameters& parameters, DOMPromiseDeferred<void>&& promise)
+{
+    if (isStopped()) {
+        promise.reject(InvalidStateError);
+        return;
+    }
+    return m_backend->setParameters(parameters, WTFMove(promise));
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(WEB_RTC)
index a5d3092..45b8901 100644 (file)
@@ -57,6 +57,8 @@ public:
     void replaceTrack(RefPtr<MediaStreamTrack>&&, DOMPromiseDeferred<void>&&);
 
     RTCRtpParameters getParameters();
+    void setParameters(const RTCRtpParameters&, DOMPromiseDeferred<void>&&);
+
     RTCRtpSenderBackend* backend() { return m_backend.get(); }
 
 private:
index 3f3fe41..c8dcd97 100644 (file)
@@ -37,7 +37,8 @@
     // FIXME 169662: missing transport
     // FIXME 169662: missing rtcpTransport
     // FIXME 169662: missing getCapabilities
-    // FIXME 169662: missing setParameters
+    // FIXME 169662: missing setStreams
     RTCRtpParameters getParameters();
+    Promise<void> setParameters(RTCRtpParameters parameters);
     Promise<void> replaceTrack(MediaStreamTrack? withTrack);
 };
index 476543c..4ad09ec 100644 (file)
@@ -38,6 +38,7 @@ class RTCRtpSenderBackend {
 public:
     virtual void replaceTrack(RTCRtpSender&, RefPtr<MediaStreamTrack>&&, DOMPromiseDeferred<void>&&) = 0;
     virtual RTCRtpParameters getParameters() const = 0;
+    virtual void setParameters(const RTCRtpParameters&, DOMPromiseDeferred<void>&&) = 0;
     virtual ~RTCRtpSenderBackend() = default;
 };
 
index 848c3df..ad4c171 100644 (file)
@@ -102,6 +102,13 @@ void RTCRtpTransceiver::disableSendingDirection()
         m_direction = RTCRtpTransceiverDirection::Inactive;
 }
 
+void RTCRtpTransceiver::stop()
+{
+    m_stopped = true;
+    m_receiver->stop();
+    m_sender->stop();
+}
+
 void RtpTransceiverSet::append(Ref<RTCRtpTransceiver>&& transceiver)
 {
     m_senders.append(transceiver->sender());
index 1a1cac9..3e71be7 100644 (file)
@@ -68,7 +68,7 @@ public:
     RTCRtpReceiver& receiver() { return m_receiver.get(); }
 
     bool stopped() const { return m_stopped; }
-    void stop() { m_stopped = true; }
+    void stop();
 
     // FIXME: Temporary solution to keep track of ICE states for this transceiver. Later, each
     // sender and receiver will have up to two DTLS transports, which in turn will have an ICE
index 4df4e7c..5406d86 100644 (file)
@@ -33,7 +33,7 @@ namespace WebCore {
 
 RTCRtpParameters LibWebRTCRtpReceiverBackend::getParameters()
 {
-    return fillRtpParameters(m_rtcReceiver->GetParameters());
+    return toRTCRtpParameters(m_rtcReceiver->GetParameters());
 }
 
 } // namespace WebCore
index 51a78ae..9371820 100644 (file)
@@ -49,7 +49,21 @@ RTCRtpParameters LibWebRTCRtpSenderBackend::getParameters() const
     if (!m_rtcSender)
         return { };
 
-    return fillRtpParameters(m_rtcSender->GetParameters());
+    return toRTCRtpParameters(m_rtcSender->GetParameters());
+}
+
+void LibWebRTCRtpSenderBackend::setParameters(const RTCRtpParameters& parameters, DOMPromiseDeferred<void>&& promise)
+{
+    if (!m_rtcSender) {
+        promise.reject(NotSupportedError);
+        return;
+    }
+    auto error = m_rtcSender->SetParameters(fromRTCRtpParameters(parameters));
+    if (!error.ok()) {
+        promise.reject(Exception { InvalidStateError, error.message() });
+        return;
+    }
+    promise.resolve();
 }
 
 } // namespace WebCore
index 24b1b1b..fe26503 100644 (file)
@@ -56,6 +56,7 @@ public:
 private:
     void replaceTrack(RTCRtpSender&, RefPtr<MediaStreamTrack>&&, DOMPromiseDeferred<void>&&) final;
     RTCRtpParameters getParameters() const final;
+    void setParameters(const RTCRtpParameters&, DOMPromiseDeferred<void>&&) final;
 
     WeakPtr<LibWebRTCPeerConnectionBackend> m_peerConnectionBackend;
     rtc::scoped_refptr<webrtc::RtpSenderInterface> m_rtcSender;
index 4e85411..2f3c10c 100644 (file)
@@ -34,7 +34,7 @@
 
 namespace WebCore {
 
-static inline RTCRtpParameters::EncodingParameters fillEncodingParameters(const webrtc::RtpEncodingParameters& rtcParameters)
+static inline RTCRtpParameters::EncodingParameters toRTCEncodingParameters(const webrtc::RtpEncodingParameters& rtcParameters)
 {
     RTCRtpParameters::EncodingParameters parameters;
 
@@ -65,7 +65,32 @@ static inline RTCRtpParameters::EncodingParameters fillEncodingParameters(const
     return parameters;
 }
 
-static inline RTCRtpParameters::HeaderExtensionParameters fillHeaderExtensionParameters(const webrtc::RtpHeaderExtensionParameters& rtcParameters)
+static inline webrtc::RtpEncodingParameters fromRTCEncodingParameters(const RTCRtpParameters::EncodingParameters& parameters)
+{
+    webrtc::RtpEncodingParameters rtcParameters;
+
+    if (parameters.dtx) {
+        switch (*parameters.dtx) {
+        case RTCRtpParameters::DtxStatus::Disabled:
+            rtcParameters.dtx = webrtc::DtxStatus::DISABLED;
+            break;
+        case RTCRtpParameters::DtxStatus::Enabled:
+            rtcParameters.dtx = webrtc::DtxStatus::ENABLED;
+        }
+    }
+    rtcParameters.active = parameters.active;
+    if (parameters.maxBitrate)
+        rtcParameters.max_bitrate_bps = parameters.maxBitrate;
+    if (parameters.maxFramerate)
+        rtcParameters.max_framerate = parameters.maxFramerate;
+    rtcParameters.rid = parameters.rid.utf8().data();
+    if (parameters.scaleResolutionDownBy != 1)
+        rtcParameters.scale_resolution_down_by = parameters.scaleResolutionDownBy;
+
+    return rtcParameters;
+}
+
+static inline RTCRtpParameters::HeaderExtensionParameters toRTCHeaderExtensionParameters(const webrtc::RtpHeaderExtensionParameters& rtcParameters)
 {
     RTCRtpParameters::HeaderExtensionParameters parameters;
 
@@ -75,7 +100,17 @@ static inline RTCRtpParameters::HeaderExtensionParameters fillHeaderExtensionPar
     return parameters;
 }
 
-static inline RTCRtpParameters::CodecParameters fillCodecParameters(const webrtc::RtpCodecParameters& rtcParameters)
+static inline webrtc::RtpHeaderExtensionParameters fromRTCHeaderExtensionParameters(const RTCRtpParameters::HeaderExtensionParameters& parameters)
+{
+    webrtc::RtpHeaderExtensionParameters rtcParameters;
+
+    rtcParameters.uri = parameters.uri.utf8().data();
+    rtcParameters.id = parameters.id;
+
+    return rtcParameters;
+}
+
+static inline RTCRtpParameters::CodecParameters toRTCCodecParameters(const webrtc::RtpCodecParameters& rtcParameters)
 {
     RTCRtpParameters::CodecParameters parameters;
 
@@ -89,17 +124,17 @@ static inline RTCRtpParameters::CodecParameters fillCodecParameters(const webrtc
     return parameters;
 }
 
-RTCRtpParameters fillRtpParameters(const webrtc::RtpParameters& rtcParameters)
+RTCRtpParameters toRTCRtpParameters(const webrtc::RtpParameters& rtcParameters)
 {
     RTCRtpParameters parameters;
 
     parameters.transactionId = fromStdString(rtcParameters.transaction_id);
     for (auto& rtcEncoding : rtcParameters.encodings)
-        parameters.encodings.append(fillEncodingParameters(rtcEncoding));
+        parameters.encodings.append(toRTCEncodingParameters(rtcEncoding));
     for (auto& extension : rtcParameters.header_extensions)
-        parameters.headerExtensions.append(fillHeaderExtensionParameters(extension));
+        parameters.headerExtensions.append(toRTCHeaderExtensionParameters(extension));
     for (auto& codec : rtcParameters.codecs)
-        parameters.codecs.append(fillCodecParameters(codec));
+        parameters.codecs.append(toRTCCodecParameters(codec));
 
     switch (rtcParameters.degradation_preference) {
     // FIXME: Support DegradationPreference::DISABLED.
@@ -117,6 +152,31 @@ RTCRtpParameters fillRtpParameters(const webrtc::RtpParameters& rtcParameters)
     return parameters;
 }
 
+webrtc::RtpParameters fromRTCRtpParameters(const RTCRtpParameters& parameters)
+{
+    webrtc::RtpParameters rtcParameters;
+    rtcParameters.transaction_id = parameters.transactionId.utf8().data();
+
+    for (auto& encoding : parameters.encodings)
+        rtcParameters.encodings.push_back(fromRTCEncodingParameters(encoding));
+    for (auto& extension : parameters.headerExtensions)
+        rtcParameters.header_extensions.push_back(fromRTCHeaderExtensionParameters(extension));
+    // Codecs parameters are readonly
+
+    switch (parameters.degradationPreference) {
+    case RTCRtpParameters::DegradationPreference::MaintainFramerate:
+        rtcParameters.degradation_preference = webrtc::DegradationPreference::MAINTAIN_FRAMERATE;
+        break;
+    case RTCRtpParameters::DegradationPreference::MaintainResolution:
+        rtcParameters.degradation_preference = webrtc::DegradationPreference::MAINTAIN_RESOLUTION;
+        break;
+    case RTCRtpParameters::DegradationPreference::Balanced:
+        rtcParameters.degradation_preference = webrtc::DegradationPreference::BALANCED;
+        break;
+    }
+    return rtcParameters;
+}
+
 }; // namespace WebCore
 
 #endif // USE(LIBWEBRTC)
index f26c3cf..ba63751 100644 (file)
@@ -36,7 +36,8 @@ namespace WebCore {
 
 struct RTCRtpParameters;
 
-RTCRtpParameters fillRtpParameters(const webrtc::RtpParameters&);
+RTCRtpParameters toRTCRtpParameters(const webrtc::RtpParameters&);
+webrtc::RtpParameters fromRTCRtpParameters(const RTCRtpParameters&);
 
 inline String fromStdString(const std::string& value)
 {