Changeset 282217 in webkit


Ignore:
Timestamp:
Sep 9, 2021 9:08:51 AM (10 months ago)
Author:
youenn@apple.com
Message:

Update RTCPeerConnection descriptions as per specification
https://bugs.webkit.org/show_bug.cgi?id=229963

Reviewed by Eric Carlson.

LayoutTests/imported/w3c:

  • web-platform-tests/webrtc/RTCPeerConnection-description-attributes-timing.https-expected.txt:
  • web-platform-tests/webrtc/RTCPeerConnection-setLocalDescription-rollback-expected.txt:

Source/WebCore:

A peer connection has two sets of descriptions: main thread descriptions which are exposed to JS and signaling thread descriptions
which are used/modified internally by the backend.
WebRTC spec describes when signaling thread descriptions should be used to set main thread descriptions.
This should be done at the end of setting remote/local descriptions, as well as when adding or surfacing an ICE candidate.
We make sure to grab signaling thread descriptions at those moments, then hop to main thread to set the main thread descriptions.

In case of closed connection, we stop early as we do not need to surface new descriptions (as well as resolve promises/fire events).

Covered by rebased tests.

  • Modules/mediastream/PeerConnectionBackend.cpp:

(WebCore::PeerConnectionBackend::setLocalDescriptionSucceeded):
(WebCore::PeerConnectionBackend::setRemoteDescriptionSucceeded):
(WebCore::PeerConnectionBackend::addIceCandidate):
(WebCore::PeerConnectionBackend::newICECandidate):

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

(WebCore::updateDescription):
(WebCore::RTCPeerConnection::updateDescriptions):

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

(WebCore::fromSessionDescriptionType):
(WebCore::descriptionsFromPeerConnection):
(WebCore::LibWebRTCMediaEndpoint::addIceCandidate):
(WebCore::LibWebRTCMediaEndpoint::OnIceCandidate):
(WebCore::LibWebRTCMediaEndpoint::setLocalSessionDescriptionSucceeded):
(WebCore::LibWebRTCMediaEndpoint::setRemoteSessionDescriptionSucceeded):

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

(WebCore::LibWebRTCPeerConnectionBackend::doAddIceCandidate):

  • Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h:

LayoutTests:

Now that we update descriptions at specific times,
we need to wait a bit to get the description.

  • webrtc/datachannel/mdns-ice-candidates.html:
Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r282214 r282217  
     12021-09-09  Youenn Fablet  <youenn@apple.com>
     2
     3        Update RTCPeerConnection descriptions as per specification
     4        https://bugs.webkit.org/show_bug.cgi?id=229963
     5
     6        Reviewed by Eric Carlson.
     7
     8        Now that we update descriptions at specific times,
     9        we need to wait a bit to get the description.
     10
     11        * webrtc/datachannel/mdns-ice-candidates.html:
     12
    1132021-09-09  Eric Hutchison  <ehutchison@apple.com>
    214
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r282208 r282217  
     12021-09-09  Youenn Fablet  <youenn@apple.com>
     2
     3        Update RTCPeerConnection descriptions as per specification
     4        https://bugs.webkit.org/show_bug.cgi?id=229963
     5
     6        Reviewed by Eric Carlson.
     7
     8        * web-platform-tests/webrtc/RTCPeerConnection-description-attributes-timing.https-expected.txt:
     9        * web-platform-tests/webrtc/RTCPeerConnection-setLocalDescription-rollback-expected.txt:
     10
    1112021-09-09  Manuel Rego Casasnovas  <rego@igalia.com>
    212
  • trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-description-attributes-timing.https-expected.txt

    r270252 r282217  
    11
    2 FAIL pendingLocalDescription is surfaced at the right time assert_equals: pendingLocalDescription is still null while promise pending expected null but got object "[object RTCSessionDescription]"
    3 FAIL pendingRemoteDescription is surfaced at the right time assert_equals: pendingRemoteDescription is still null while promise pending expected null but got object "[object RTCSessionDescription]"
    4 FAIL currentLocalDescription is surfaced at the right time assert_equals: currentLocalDescription is still null while promise pending expected null but got object "[object RTCSessionDescription]"
    5 FAIL currentRemoteDescription is surfaced at the right time assert_equals: currentRemoteDescription is still null while promise pending expected null but got object "[object RTCSessionDescription]"
     2PASS pendingLocalDescription is surfaced at the right time
     3PASS pendingRemoteDescription is surfaced at the right time
     4PASS currentLocalDescription is surfaced at the right time
     5PASS currentRemoteDescription is surfaced at the right time
    66
  • trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-setLocalDescription-rollback-expected.txt

    r281985 r282217  
    44PASS setLocalDescription(rollback) after setting answer description should reject with InvalidStateError
    55PASS setLocalDescription(rollback) should ignore invalid sdp content and succeed
    6 FAIL setLocalDescription(rollback) should update internal state with a queued tassk, in the right order assert_not_equals: pendingLocalDescription should not be set synchronously after a call to sLD got disallowed value null
     6FAIL setLocalDescription(rollback) should update internal state with a queued tassk, in the right order assert_equals: pendingLocalDescription should be updated before the signalingstatechange event expected null but got object "[object RTCSessionDescription]"
    77
  • trunk/LayoutTests/webrtc/datachannel/mdns-ice-candidates.html

    r269236 r282217  
    161161    const channel2 = pc.createDataChannel('sendDataChannel2');
    162162    const offer2 = await pc.createOffer();
    163     const description = pc.localDescription;
    164163
    165164    // Make sure we can apply the filtered description.
    166     await pc.setLocalDescription(description);
     165    await pc.setLocalDescription(pc.localDescription);
     166
     167    // Reapply description which should have candidates.
     168    await pc.setLocalDescription(offer2);
     169    const description = pc.localDescription;
    167170
    168171    const lines = description.sdp.split('\r\n').filter(line => {
  • trunk/Source/WebCore/ChangeLog

    r282211 r282217  
     12021-09-09  Youenn Fablet  <youenn@apple.com>
     2
     3        Update RTCPeerConnection descriptions as per specification
     4        https://bugs.webkit.org/show_bug.cgi?id=229963
     5
     6        Reviewed by Eric Carlson.
     7
     8        A peer connection has two sets of descriptions: main thread descriptions which are exposed to JS and signaling thread descriptions
     9        which are used/modified internally by the backend.
     10        WebRTC spec describes when signaling thread descriptions should be used to set main thread descriptions.
     11        This should be done at the end of setting remote/local descriptions, as well as when adding or surfacing an ICE candidate.
     12        We make sure to grab signaling thread descriptions at those moments, then hop to main thread to set the main thread descriptions.
     13
     14        In case of closed connection, we stop early as we do not need to surface new descriptions (as well as resolve promises/fire events).
     15
     16        Covered by rebased tests.
     17
     18        * Modules/mediastream/PeerConnectionBackend.cpp:
     19        (WebCore::PeerConnectionBackend::setLocalDescriptionSucceeded):
     20        (WebCore::PeerConnectionBackend::setRemoteDescriptionSucceeded):
     21        (WebCore::PeerConnectionBackend::addIceCandidate):
     22        (WebCore::PeerConnectionBackend::newICECandidate):
     23        * Modules/mediastream/PeerConnectionBackend.h:
     24        * Modules/mediastream/RTCPeerConnection.cpp:
     25        (WebCore::updateDescription):
     26        (WebCore::RTCPeerConnection::updateDescriptions):
     27        * Modules/mediastream/RTCPeerConnection.h:
     28        * Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
     29        (WebCore::fromSessionDescriptionType):
     30        (WebCore::descriptionsFromPeerConnection):
     31        (WebCore::LibWebRTCMediaEndpoint::addIceCandidate):
     32        (WebCore::LibWebRTCMediaEndpoint::OnIceCandidate):
     33        (WebCore::LibWebRTCMediaEndpoint::setLocalSessionDescriptionSucceeded):
     34        (WebCore::LibWebRTCMediaEndpoint::setRemoteSessionDescriptionSucceeded):
     35        * Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:
     36        * Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:
     37        (WebCore::LibWebRTCPeerConnectionBackend::doAddIceCandidate):
     38        * Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h:
     39
    1402021-09-09  Antti Koivisto  <antti@apple.com>
    241
  • trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp

    r282197 r282217  
    176176}
    177177
    178 void PeerConnectionBackend::setLocalDescriptionSucceeded(std::unique_ptr<RTCSctpTransportBackend>&& sctpBackend)
     178void PeerConnectionBackend::setLocalDescriptionSucceeded(std::optional<DescriptionStates>&& descriptionStates, std::unique_ptr<RTCSctpTransportBackend>&& sctpBackend)
    179179{
    180180    ASSERT(isMainThread());
     
    182182
    183183    ASSERT(m_setDescriptionPromise);
    184     m_peerConnection.doTask([this, promise = WTFMove(m_setDescriptionPromise), sctpBackend = WTFMove(sctpBackend)]() mutable {
    185         if (m_peerConnection.isClosed())
    186             return;
    187 
     184    m_peerConnection.doTask([this, promise = WTFMove(m_setDescriptionPromise), descriptionStates = WTFMove(descriptionStates), sctpBackend = WTFMove(sctpBackend)]() mutable {
     185        if (m_peerConnection.isClosed())
     186            return;
     187
     188        if (descriptionStates)
     189            m_peerConnection.updateDescriptions(WTFMove(*descriptionStates));
    188190        m_peerConnection.updateTransceiversAfterSuccessfulLocalDescription();
    189191        m_peerConnection.updateSctpBackend(WTFMove(sctpBackend));
     
    214216}
    215217
    216 void PeerConnectionBackend::setRemoteDescriptionSucceeded(std::unique_ptr<RTCSctpTransportBackend>&& sctpBackend)
     218void PeerConnectionBackend::setRemoteDescriptionSucceeded(std::optional<DescriptionStates>&& descriptionStates, std::unique_ptr<RTCSctpTransportBackend>&& sctpBackend)
    217219{
    218220    ASSERT(isMainThread());
     
    235237    }
    236238
    237     m_peerConnection.doTask([this, promise = WTFMove(promise), sctpBackend = WTFMove(sctpBackend)]() mutable {
    238         if (m_peerConnection.isClosed())
    239             return;
    240 
     239    m_peerConnection.doTask([this, promise = WTFMove(promise), descriptionStates = WTFMove(descriptionStates), sctpBackend = WTFMove(sctpBackend)]() mutable {
     240        if (m_peerConnection.isClosed())
     241            return;
     242
     243        if (descriptionStates)
     244            m_peerConnection.updateDescriptions(WTFMove(*descriptionStates));
    241245        m_peerConnection.updateTransceiversAfterSuccessfulRemoteDescription();
    242246        m_peerConnection.updateSctpBackend(WTFMove(sctpBackend));
     
    315319        if (!weakThis || weakThis->m_peerConnection.isClosed())
    316320            return;
    317         RELEASE_LOG_ERROR(WebRTC, "Adding ice candidate finished, success=%d", result.hasException());
    318         promise.settle(WTFMove(result));
     321
     322        if (result.hasException()) {
     323            RELEASE_LOG_ERROR(WebRTC, "Adding ice candidate failed %d", result.exception().code());
     324            promise.reject(result.releaseException());
     325            return;
     326        }
     327
     328        if (auto descriptions = result.releaseReturnValue())
     329            weakThis->m_peerConnection.updateDescriptions(WTFMove(*descriptions));
     330        promise.resolve();
    319331    });
    320332}
     
    350362}
    351363
    352 void PeerConnectionBackend::newICECandidate(String&& sdp, String&& mid, unsigned short sdpMLineIndex, String&& serverURL)
    353 {
    354     m_peerConnection.doTask([logSiteIdentifier = LOGIDENTIFIER, this, sdp = WTFMove(sdp), mid = WTFMove(mid), sdpMLineIndex, serverURL = WTFMove(serverURL)]() mutable {
    355         if (m_peerConnection.isClosed())
    356             return;
     364void PeerConnectionBackend::newICECandidate(String&& sdp, String&& mid, unsigned short sdpMLineIndex, String&& serverURL, std::optional<DescriptionStates>&& descriptions)
     365{
     366    m_peerConnection.doTask([logSiteIdentifier = LOGIDENTIFIER, this, sdp = WTFMove(sdp), mid = WTFMove(mid), sdpMLineIndex, serverURL = WTFMove(serverURL), descriptions = WTFMove(descriptions)]() mutable {
     367        if (m_peerConnection.isClosed())
     368            return;
     369
     370        if (descriptions)
     371            m_peerConnection.updateDescriptions(WTFMove(*descriptions));
    357372
    358373        UNUSED_PARAM(logSiteIdentifier);
  • trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.h

    r282197 r282217  
    105105    virtual void close() = 0;
    106106
    107     virtual RefPtr<RTCSessionDescription> localDescription() const = 0;
    108     virtual RefPtr<RTCSessionDescription> currentLocalDescription() const = 0;
    109     virtual RefPtr<RTCSessionDescription> pendingLocalDescription() const = 0;
    110 
    111     virtual RefPtr<RTCSessionDescription> remoteDescription() const = 0;
    112     virtual RefPtr<RTCSessionDescription> currentRemoteDescription() const = 0;
    113     virtual RefPtr<RTCSessionDescription> pendingRemoteDescription() const = 0;
    114 
    115107    virtual void restartIce() = 0;
    116108    virtual bool setConfiguration(MediaEndpointConfiguration&&) = 0;
     
    131123    virtual void emulatePlatformEvent(const String& action) = 0;
    132124
    133     void newICECandidate(String&& sdp, String&& mid, unsigned short sdpMLineIndex, String&& serverURL);
     125    struct DescriptionStates {
     126        std::optional<RTCSdpType> currentLocalDescriptionSdpType;
     127        String currentLocalDescriptionSdp;
     128        std::optional<RTCSdpType> pendingLocalDescriptionSdpType;
     129        String pendingLocalDescriptionSdp;
     130        std::optional<RTCSdpType> currentRemoteDescriptionSdpType;
     131        String currentRemoteDescriptionSdp;
     132        std::optional<RTCSdpType> pendingRemoteDescriptionSdpType;
     133        String pendingRemoteDescriptionSdp;
     134    };
     135
     136    void newICECandidate(String&& sdp, String&& mid, unsigned short sdpMLineIndex, String&& serverURL, std::optional<DescriptionStates>&&);
    134137    virtual void disableICECandidateFiltering();
    135138    void enableICECandidateFiltering();
     
    188191    bool shouldFilterICECandidates() const { return m_shouldFilterICECandidates; };
    189192
     193    using AddIceCandidateCallbackFunction = void(ExceptionOr<std::optional<PeerConnectionBackend::DescriptionStates>>&&);
     194    using AddIceCandidateCallback = Function<AddIceCandidateCallbackFunction>;
     195
    190196protected:
    191197    void fireICECandidateEvent(RefPtr<RTCIceCandidate>&&, String&& url);
     
    200206    void createAnswerFailed(Exception&&);
    201207
    202     void setLocalDescriptionSucceeded(std::unique_ptr<RTCSctpTransportBackend>&&);
     208    void setLocalDescriptionSucceeded(std::optional<DescriptionStates>&&, std::unique_ptr<RTCSctpTransportBackend>&&);
    203209    void setLocalDescriptionFailed(Exception&&);
    204210
    205     void setRemoteDescriptionSucceeded(std::unique_ptr<RTCSctpTransportBackend>&&);
     211    void setRemoteDescriptionSucceeded(std::optional<DescriptionStates>&&, std::unique_ptr<RTCSctpTransportBackend>&&);
    206212    void setRemoteDescriptionFailed(Exception&&);
    207 
    208     void addIceCandidateSucceeded();
    209     void addIceCandidateFailed(Exception&&);
    210213
    211214    void validateSDP(const String&) const;
     
    224227    virtual void doSetLocalDescription(const RTCSessionDescription*) = 0;
    225228    virtual void doSetRemoteDescription(const RTCSessionDescription&) = 0;
    226     virtual void doAddIceCandidate(RTCIceCandidate&, Function<void(ExceptionOr<void>&&)>&&) = 0;
     229    virtual void doAddIceCandidate(RTCIceCandidate&, AddIceCandidateCallback&&) = 0;
    227230    virtual void endOfIceCandidates(DOMPromiseDeferred<void>&&);
    228231    virtual void doStop() = 0;
  • trunk/Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp

    r282197 r282217  
    248248}
    249249
    250 RefPtr<RTCSessionDescription> RTCPeerConnection::localDescription() const
    251 {
    252     return m_backend->localDescription();
    253 }
    254 
    255 RefPtr<RTCSessionDescription> RTCPeerConnection::currentLocalDescription() const
    256 {
    257     return m_backend->currentLocalDescription();
    258 }
    259 
    260 RefPtr<RTCSessionDescription> RTCPeerConnection::pendingLocalDescription() const
    261 {
    262     return m_backend->pendingLocalDescription();
    263 }
    264 
    265250void RTCPeerConnection::setRemoteDescription(Description&& remoteDescription, Ref<DeferredPromise>&& promise)
    266251{
     
    285270        m_backend->setRemoteDescription(*description, WTFMove(promise));
    286271    });
    287 }
    288 
    289 RefPtr<RTCSessionDescription> RTCPeerConnection::remoteDescription() const
    290 {
    291     return m_backend->remoteDescription();
    292 }
    293 
    294 RefPtr<RTCSessionDescription> RTCPeerConnection::currentRemoteDescription() const
    295 {
    296     return m_backend->currentRemoteDescription();
    297 }
    298 
    299 RefPtr<RTCSessionDescription> RTCPeerConnection::pendingRemoteDescription() const
    300 {
    301     return m_backend->pendingRemoteDescription();
    302272}
    303273
     
    935905}
    936906
     907static void updateDescription(RefPtr<RTCSessionDescription>& description, std::optional<RTCSdpType> type, String&& sdp)
     908{
     909    if (description && type && description->sdp() == sdp && description->type() == *type)
     910        return;
     911    if (!type || sdp.isEmpty()) {
     912        description = nullptr;
     913        return;
     914    }
     915    description = RTCSessionDescription::create(*type, WTFMove(sdp));
     916}
     917
     918void RTCPeerConnection::updateDescriptions(PeerConnectionBackend::DescriptionStates&& states)
     919{
     920    updateDescription(m_currentLocalDescription, states.currentLocalDescriptionSdpType, WTFMove(states.currentLocalDescriptionSdp));
     921    updateDescription(m_pendingLocalDescription, states.pendingLocalDescriptionSdpType, WTFMove(states.pendingLocalDescriptionSdp));
     922    updateDescription(m_currentRemoteDescription, states.currentRemoteDescriptionSdpType, WTFMove(states.currentRemoteDescriptionSdp));
     923    updateDescription(m_pendingRemoteDescription, states.pendingRemoteDescriptionSdpType, WTFMove(states.pendingRemoteDescriptionSdp));
     924}
     925
    937926void RTCPeerConnection::updateTransceiverTransports()
    938927{
  • trunk/Source/WebCore/Modules/mediastream/RTCPeerConnection.h

    r282197 r282217  
    113113    using Description = Variant<RTCSessionDescriptionInit, RefPtr<RTCSessionDescription>>;
    114114    void setLocalDescription(std::optional<Description>&&, Ref<DeferredPromise>&&);
    115     RefPtr<RTCSessionDescription> localDescription() const;
    116     RefPtr<RTCSessionDescription> currentLocalDescription() const;
    117     RefPtr<RTCSessionDescription> pendingLocalDescription() const;
     115    RefPtr<RTCSessionDescription> localDescription() const { return m_pendingLocalDescription ? m_pendingLocalDescription.get() : m_currentLocalDescription.get(); }
     116    RefPtr<RTCSessionDescription> currentLocalDescription() const { return m_currentLocalDescription.get(); }
     117    RefPtr<RTCSessionDescription> pendingLocalDescription() const { return m_pendingLocalDescription.get(); }
    118118
    119119    void setRemoteDescription(Description&&, Ref<DeferredPromise>&&);
    120     RefPtr<RTCSessionDescription> remoteDescription() const;
    121     RefPtr<RTCSessionDescription> currentRemoteDescription() const;
    122     RefPtr<RTCSessionDescription> pendingRemoteDescription() const;
     120    RTCSessionDescription* remoteDescription() const { return m_pendingRemoteDescription ? m_pendingRemoteDescription.get() : m_currentRemoteDescription.get(); }
     121    RTCSessionDescription* currentRemoteDescription() const { return m_currentRemoteDescription.get(); }
     122    RTCSessionDescription* pendingRemoteDescription() const { return m_pendingRemoteDescription.get(); }
    123123
    124124    using Candidate = std::optional<Variant<RTCIceCandidateInit, RefPtr<RTCIceCandidate>>>;
     
    188188    void doTask(Function<void()>&&);
    189189
     190    void updateDescriptions(PeerConnectionBackend::DescriptionStates&&);
    190191    void updateTransceiversAfterSuccessfulLocalDescription();
    191192    void updateTransceiversAfterSuccessfulRemoteDescription();
     
    272273    Vector<Ref<RTCIceTransport>> m_iceTransports;
    273274    RefPtr<RTCSctpTransport> m_sctpTransport;
     275
     276    RefPtr<RTCSessionDescription> m_currentLocalDescription;
     277    RefPtr<RTCSessionDescription> m_pendingLocalDescription;
     278    RefPtr<RTCSessionDescription> m_currentRemoteDescription;
     279    RefPtr<RTCSessionDescription> m_pendingRemoteDescription;
    274280};
    275281
  • trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp

    r282197 r282217  
    6161#include <webrtc/system_wrappers/include/field_trial.h>
    6262#include <wtf/MainThread.h>
     63#include <wtf/SharedTask.h>
    6364
    6465namespace WebCore {
     
    142143    ASSERT_NOT_REACHED();
    143144    return "";
    144 }
    145 
    146 static inline RTCSdpType fromSessionDescriptionType(const webrtc::SessionDescriptionInterface& description)
    147 {
    148     auto type = description.type();
    149     if (type == webrtc::SessionDescriptionInterface::kOffer)
    150         return RTCSdpType::Offer;
    151     if (type == webrtc::SessionDescriptionInterface::kAnswer)
    152         return RTCSdpType::Answer;
    153     ASSERT(type == webrtc::SessionDescriptionInterface::kPrAnswer);
    154     return RTCSdpType::Pranswer;
    155 }
    156 
    157 static inline RefPtr<RTCSessionDescription> fromSessionDescription(const webrtc::SessionDescriptionInterface* description)
    158 {
    159     if (!description)
    160         return nullptr;
    161 
    162     std::string sdp;
    163     description->ToString(&sdp);
    164 
    165     return RTCSessionDescription::create(fromSessionDescriptionType(*description), fromStdString(sdp));
    166 }
    167 
    168 // FIXME: We might want to create a new object only if the session actually changed for all description getters.
    169 RefPtr<RTCSessionDescription> LibWebRTCMediaEndpoint::currentLocalDescription() const
    170 {
    171     return m_backend ? fromSessionDescription(m_backend->current_local_description()) : nullptr;
    172 }
    173 
    174 RefPtr<RTCSessionDescription> LibWebRTCMediaEndpoint::currentRemoteDescription() const
    175 {
    176     return m_backend ? fromSessionDescription(m_backend->current_remote_description()) : nullptr;
    177 }
    178 
    179 RefPtr<RTCSessionDescription> LibWebRTCMediaEndpoint::pendingLocalDescription() const
    180 {
    181     return m_backend ? fromSessionDescription(m_backend->pending_local_description()) : nullptr;
    182 }
    183 
    184 RefPtr<RTCSessionDescription> LibWebRTCMediaEndpoint::pendingRemoteDescription() const
    185 {
    186     return m_backend ? fromSessionDescription(m_backend->pending_remote_description()) : nullptr;
    187 }
    188 
    189 RefPtr<RTCSessionDescription> LibWebRTCMediaEndpoint::localDescription() const
    190 {
    191     return m_backend ? fromSessionDescription(m_backend->local_description()) : nullptr;
    192 }
    193 
    194 RefPtr<RTCSessionDescription> LibWebRTCMediaEndpoint::remoteDescription() const
    195 {
    196     return m_backend ? fromSessionDescription(m_backend->remote_description()) : nullptr;
    197145}
    198146
     
    621569}
    622570
    623 void LibWebRTCMediaEndpoint::addIceCandidate(std::unique_ptr<webrtc::IceCandidateInterface>&& candidate, std::function<void(webrtc::RTCError)>&& callback)
    624 {
    625     m_backend->AddIceCandidate(WTFMove(candidate), WTFMove(callback));
     571static inline RTCSdpType fromSessionDescriptionType(const webrtc::SessionDescriptionInterface& description)
     572{
     573    auto type = description.type();
     574    if (type == webrtc::SessionDescriptionInterface::kOffer)
     575        return RTCSdpType::Offer;
     576    if (type == webrtc::SessionDescriptionInterface::kAnswer)
     577        return RTCSdpType::Answer;
     578    ASSERT(type == webrtc::SessionDescriptionInterface::kPrAnswer);
     579    return RTCSdpType::Pranswer;
     580}
     581
     582static std::optional<PeerConnectionBackend::DescriptionStates> descriptionsFromPeerConnection(webrtc::PeerConnectionInterface* connection)
     583{
     584    if (!connection)
     585        return { };
     586
     587    std::optional<RTCSdpType> currentLocalDescriptionSdpType, pendingLocalDescriptionSdpType, currentRemoteDescriptionSdpType, pendingRemoteDescriptionSdpType;
     588    std::string currentLocalDescriptionSdp, pendingLocalDescriptionSdp, currentRemoteDescriptionSdp, pendingRemoteDescriptionSdp;
     589    if (auto* description = connection->current_local_description()) {
     590        currentLocalDescriptionSdpType = fromSessionDescriptionType(*description);
     591        description->ToString(&currentLocalDescriptionSdp);
     592    }
     593    if (auto* description = connection->pending_local_description()) {
     594        pendingLocalDescriptionSdpType = fromSessionDescriptionType(*description);
     595        description->ToString(&pendingLocalDescriptionSdp);
     596    }
     597    if (auto* description = connection->current_remote_description()) {
     598        currentRemoteDescriptionSdpType = fromSessionDescriptionType(*description);
     599        description->ToString(&currentRemoteDescriptionSdp);
     600    }
     601    if (auto* description = connection->pending_remote_description()) {
     602        pendingRemoteDescriptionSdpType = fromSessionDescriptionType(*description);
     603        description->ToString(&pendingRemoteDescriptionSdp);
     604    }
     605
     606    return PeerConnectionBackend::DescriptionStates {
     607        currentLocalDescriptionSdpType, fromStdString(currentLocalDescriptionSdp),
     608        pendingLocalDescriptionSdpType, fromStdString(pendingLocalDescriptionSdp),
     609        currentRemoteDescriptionSdpType, fromStdString(currentRemoteDescriptionSdp),
     610        pendingRemoteDescriptionSdpType, fromStdString(pendingRemoteDescriptionSdp)
     611    };
     612}
     613
     614void LibWebRTCMediaEndpoint::addIceCandidate(std::unique_ptr<webrtc::IceCandidateInterface>&& candidate, PeerConnectionBackend::AddIceCandidateCallback&& callback)
     615{
     616    m_backend->AddIceCandidate(WTFMove(candidate), [task = createSharedTask<PeerConnectionBackend::AddIceCandidateCallbackFunction>(WTFMove(callback)), backend = m_backend](auto&& error) mutable {
     617        callOnMainThread([task = WTFMove(task), descriptions = descriptionsFromPeerConnection(backend.get()), error = WTFMove(error)]() mutable {
     618            if (!error.ok()) {
     619                task->run(toException(error));
     620                return;
     621            }
     622            task->run(WTFMove(descriptions));
     623        });
     624    });
    626625}
    627626
     
    635634    auto sdpMLineIndex = safeCast<unsigned short>(rtcCandidate->sdp_mline_index());
    636635
    637     callOnMainThread([protectedThis = makeRef(*this), mid = fromStdString(rtcCandidate->sdp_mid()), sdp = fromStdString(sdp), sdpMLineIndex, url = fromStdString(rtcCandidate->server_url())]() mutable {
    638         if (protectedThis->isStopped())
    639             return;
    640         protectedThis->m_peerConnectionBackend.newICECandidate(WTFMove(sdp), WTFMove(mid), sdpMLineIndex, WTFMove(url));
     636    callOnMainThread([protectedThis = makeRef(*this), descriptions = descriptionsFromPeerConnection(m_backend.get()), mid = fromStdString(rtcCandidate->sdp_mid()), sdp = fromStdString(sdp), sdpMLineIndex, url = fromStdString(rtcCandidate->server_url())]() mutable {
     637        if (protectedThis->isStopped())
     638            return;
     639        protectedThis->m_peerConnectionBackend.newICECandidate(WTFMove(sdp), WTFMove(mid), sdpMLineIndex, WTFMove(url), WTFMove(descriptions));
    641640    });
    642641}
     
    700699void LibWebRTCMediaEndpoint::setLocalSessionDescriptionSucceeded()
    701700{
    702     callOnMainThread([protectedThis = makeRef(*this), sctpState = SctpTransportState(m_backend->GetSctpTransport())]() mutable {
    703         if (protectedThis->isStopped())
    704             return;
    705         protectedThis->m_peerConnectionBackend.setLocalDescriptionSucceeded(sctpState.createBackend());
     701    callOnMainThread([protectedThis = makeRef(*this), descriptions = descriptionsFromPeerConnection(m_backend.get()), sctpState = SctpTransportState(m_backend->GetSctpTransport())]() mutable {
     702        if (protectedThis->isStopped())
     703            return;
     704        protectedThis->m_peerConnectionBackend.setLocalDescriptionSucceeded(WTFMove(descriptions), sctpState.createBackend());
    706705    });
    707706}
     
    718717void LibWebRTCMediaEndpoint::setRemoteSessionDescriptionSucceeded()
    719718{
    720     callOnMainThread([protectedThis = makeRef(*this), sctpState = SctpTransportState(m_backend->GetSctpTransport())]() mutable {
    721         if (protectedThis->isStopped())
    722             return;
    723         protectedThis->m_peerConnectionBackend.setRemoteDescriptionSucceeded(sctpState.createBackend());
     719    callOnMainThread([protectedThis = makeRef(*this), descriptions = descriptionsFromPeerConnection(m_backend.get()), sctpState = SctpTransportState(m_backend->GetSctpTransport())]() mutable {
     720        if (protectedThis->isStopped())
     721            return;
     722        protectedThis->m_peerConnectionBackend.setRemoteDescriptionSucceeded(WTFMove(descriptions), sctpState.createBackend());
    724723    });
    725724}
  • trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h

    r281981 r282217  
    9090    void getStats(webrtc::RtpSenderInterface&, Ref<DeferredPromise>&&);
    9191    std::unique_ptr<RTCDataChannelHandler> createDataChannel(const String&, const RTCDataChannelInit&);
    92     void addIceCandidate(std::unique_ptr<webrtc::IceCandidateInterface>&&, std::function<void(webrtc::RTCError)>&&);
     92    void addIceCandidate(std::unique_ptr<webrtc::IceCandidateInterface>&&, PeerConnectionBackend::AddIceCandidateCallback&&);
    9393
    9494    void close();
    9595    void stop();
    9696    bool isStopped() const { return !m_backend; }
    97 
    98     RefPtr<RTCSessionDescription> localDescription() const;
    99     RefPtr<RTCSessionDescription> remoteDescription() const;
    100     RefPtr<RTCSessionDescription> currentLocalDescription() const;
    101     RefPtr<RTCSessionDescription> currentRemoteDescription() const;
    102     RefPtr<RTCSessionDescription> pendingLocalDescription() const;
    103     RefPtr<RTCSessionDescription> pendingRemoteDescription() const;
    10497
    10598    bool addTrack(LibWebRTCRtpSenderBackend&, MediaStreamTrack&, const Vector<String>&);
  • trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp

    r282054 r282217  
    4848#include "RealtimeOutgoingVideoSource.h"
    4949#include "Settings.h"
    50 #include <wtf/SharedTask.h>
    5150
    5251namespace WebCore {
     
    271270}
    272271
    273 void LibWebRTCPeerConnectionBackend::doAddIceCandidate(RTCIceCandidate& candidate, Function<void(ExceptionOr<void>&&)>&& callback)
     272void LibWebRTCPeerConnectionBackend::doAddIceCandidate(RTCIceCandidate& candidate, AddIceCandidateCallback&& callback)
    274273{
    275274    webrtc::SdpParseError error;
     
    282281    }
    283282
    284     m_endpoint->addIceCandidate(WTFMove(rtcCandidate), [task = createSharedTask<void(ExceptionOr<void>&&)>(WTFMove(callback))](auto&& error) mutable {
    285         callOnMainThread([task = WTFMove(task), error = WTFMove(error)] {
    286             if (!error.ok()) {
    287                 task->run(toException(error));
    288                 return;
    289             }
    290             task->run({ });
    291         });
    292     });
     283    m_endpoint->addIceCandidate(WTFMove(rtcCandidate), WTFMove(callback));
    293284}
    294285
     
    312303}
    313304
    314 RefPtr<RTCSessionDescription> LibWebRTCPeerConnectionBackend::currentLocalDescription() const
    315 {
    316     auto description = m_endpoint->currentLocalDescription();
    317     if (description)
    318         validateSDP(description->sdp());
    319     return description;
    320 }
    321 
    322 RefPtr<RTCSessionDescription> LibWebRTCPeerConnectionBackend::currentRemoteDescription() const
    323 {
    324     return m_endpoint->currentRemoteDescription();
    325 }
    326 
    327 RefPtr<RTCSessionDescription> LibWebRTCPeerConnectionBackend::pendingLocalDescription() const
    328 {
    329     auto description = m_endpoint->pendingLocalDescription();
    330     if (description)
    331         validateSDP(description->sdp());
    332     return description;
    333 }
    334 
    335 RefPtr<RTCSessionDescription> LibWebRTCPeerConnectionBackend::pendingRemoteDescription() const
    336 {
    337     return m_endpoint->pendingRemoteDescription();
    338 }
    339 
    340 RefPtr<RTCSessionDescription> LibWebRTCPeerConnectionBackend::localDescription() const
    341 {
    342     auto description = m_endpoint->localDescription();
    343     if (description)
    344         validateSDP(description->sdp());
    345     return description;
    346 }
    347 
    348 RefPtr<RTCSessionDescription> LibWebRTCPeerConnectionBackend::remoteDescription() const
    349 {
    350     return m_endpoint->remoteDescription();
    351 }
    352 
    353305static inline RefPtr<RTCRtpSender> findExistingSender(const Vector<RefPtr<RTCRtpTransceiver>>& transceivers, LibWebRTCRtpSenderBackend& senderBackend)
    354306{
  • trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h

    r281981 r282217  
    6363    void doSetLocalDescription(const RTCSessionDescription*) final;
    6464    void doSetRemoteDescription(const RTCSessionDescription&) final;
    65     void doAddIceCandidate(RTCIceCandidate&, Function<void(ExceptionOr<void>&&)>&&) final;
     65    void doAddIceCandidate(RTCIceCandidate&, AddIceCandidateCallback&&) final;
    6666    void doStop() final;
    6767    std::unique_ptr<RTCDataChannelHandler> createDataChannelHandler(const String&, const RTCDataChannelInit&) final;
     
    7171    void getStats(RTCRtpSender&, Ref<DeferredPromise>&&) final;
    7272    void getStats(RTCRtpReceiver&, Ref<DeferredPromise>&&) final;
    73 
    74     RefPtr<RTCSessionDescription> localDescription() const final;
    75     RefPtr<RTCSessionDescription> currentLocalDescription() const final;
    76     RefPtr<RTCSessionDescription> pendingLocalDescription() const final;
    77 
    78     RefPtr<RTCSessionDescription> remoteDescription() const final;
    79     RefPtr<RTCSessionDescription> currentRemoteDescription() const final;
    80     RefPtr<RTCSessionDescription> pendingRemoteDescription() const final;
    8173
    8274    std::optional<bool> canTrickleIceCandidates() const final;
Note: See TracChangeset for help on using the changeset viewer.