Diff
Modified: trunk/LayoutTests/ChangeLog (208444 => 208445)
--- trunk/LayoutTests/ChangeLog 2016-11-09 18:27:37 UTC (rev 208444)
+++ trunk/LayoutTests/ChangeLog 2016-11-09 18:28:08 UTC (rev 208445)
@@ -1,3 +1,15 @@
+2016-11-09 Youenn Fablet <[email protected]>
+
+ [WebRTC] Introduce asynchronous backend for other RTCPeerConnection API
+ https://bugs.webkit.org/show_bug.cgi?id=164409
+
+ Reviewed by Eric Carlson.
+
+ Rebasing test as patch changes the order in which error cases are checked in case of setRemoteDescription/setLocalDescription.
+ New order tries to follow more closely https://www.w3.org/TR/webrtc/#set-description.
+
+ * fast/mediastream/RTCPeerConnection-stable-expected.txt:
+
2016-11-09 Joanmarie Diggs <[email protected]>
AX: [ATK] Wrong selected element at a given index in a list box (redux)
Modified: trunk/LayoutTests/fast/mediastream/RTCPeerConnection-stable-expected.txt (208444 => 208445)
--- trunk/LayoutTests/fast/mediastream/RTCPeerConnection-stable-expected.txt 2016-11-09 18:27:37 UTC (rev 208444)
+++ trunk/LayoutTests/fast/mediastream/RTCPeerConnection-stable-expected.txt 2016-11-09 18:28:08 UTC (rev 208445)
@@ -6,25 +6,25 @@
PASS pc.signalingState is "stable"
PASS pc.setLocalDescription(sessionDescription, finishIfSucceeded, requestFailed1); did not throw exception.
PASS setLocalDescription failed.
-FAIL errorReason.name should be InvalidSessionDescriptionError. Was InvalidAccessError.
+FAIL errorReason.name should be InvalidSessionDescriptionError. Was InvalidStateError.
FAIL pc.localDescription should throw an exception. Was null.
FAIL pc.remoteDescription should throw an exception. Was null.
PASS pc.signalingState is "stable"
PASS pc.setLocalDescription(sessionDescription, finishIfSucceeded, requestFailed2); did not throw exception.
PASS setLocalDescription failed.
-FAIL errorReason.name should be InvalidSessionDescriptionError. Was InvalidAccessError.
+FAIL errorReason.name should be InvalidSessionDescriptionError. Was InvalidStateError.
FAIL pc.localDescription should throw an exception. Was null.
FAIL pc.remoteDescription should throw an exception. Was null.
PASS pc.signalingState is "stable"
PASS pc.setRemoteDescription(sessionDescription, finishIfSucceeded, requestFailed3); did not throw exception.
PASS setRemoteDescription failed.
-FAIL errorReason.name should be InvalidSessionDescriptionError. Was InvalidAccessError.
+FAIL errorReason.name should be InvalidSessionDescriptionError. Was InvalidStateError.
FAIL pc.localDescription should throw an exception. Was null.
FAIL pc.remoteDescription should throw an exception. Was null.
PASS pc.signalingState is "stable"
PASS pc.setRemoteDescription(sessionDescription, finishIfSucceeded, requestFailed4); did not throw exception.
PASS setRemoteDescription failed.
-FAIL errorReason.name should be InvalidSessionDescriptionError. Was InvalidAccessError.
+FAIL errorReason.name should be InvalidSessionDescriptionError. Was InvalidStateError.
FAIL pc.localDescription should throw an exception. Was null.
FAIL pc.remoteDescription should throw an exception. Was null.
PASS pc.signalingState is "stable"
Modified: trunk/Source/WebCore/ChangeLog (208444 => 208445)
--- trunk/Source/WebCore/ChangeLog 2016-11-09 18:27:37 UTC (rev 208444)
+++ trunk/Source/WebCore/ChangeLog 2016-11-09 18:28:08 UTC (rev 208445)
@@ -1,3 +1,63 @@
+2016-11-09 Youenn Fablet <[email protected]>
+
+ [WebRTC] Introduce asynchronous backend for other RTCPeerConnection API
+ https://bugs.webkit.org/show_bug.cgi?id=164409
+
+ Reviewed by Eric Carlson.
+
+ Covered by existing tests.
+
+ Following on createOffer changes, applying the same changes to createAnswer, setLocalDescription, setRemoteDescription and addIceCandidate.
+ Also refactored ICE candidate event generation (done at PeerConnectionBackend).
+ Updated stop implementation to clean any promise that may be stored in PeerConnectionBackend.
+
+ The goal of this is to be more aligned with https://www.w3.org/TR/webrtc/.
+ Implementation of the various functions such as //www.w3.org/TR/webrtc/#set-description would be done in PeerConnectionBackend.
+ This will require additional code moved from MediaEndpointPeerConnection up to PeerConnectionBackend.
+
+ * Modules/mediastream/MediaEndpointPeerConnection.cpp:
+ (WebCore::MediaEndpointPeerConnection::createOfferTask):
+ (WebCore::MediaEndpointPeerConnection::doCreateAnswer):
+ (WebCore::MediaEndpointPeerConnection::createAnswerTask):
+ (WebCore::MediaEndpointPeerConnection::doSetLocalDescription):
+ (WebCore::MediaEndpointPeerConnection::setLocalDescriptionTask):
+ (WebCore::MediaEndpointPeerConnection::doSetRemoteDescription):
+ (WebCore::MediaEndpointPeerConnection::setRemoteDescriptionTask):
+ (WebCore::MediaEndpointPeerConnection::doAddIceCandidate):
+ (WebCore::MediaEndpointPeerConnection::addIceCandidateTask):
+ (WebCore::MediaEndpointPeerConnection::doStop):
+ (WebCore::MediaEndpointPeerConnection::gotIceCandidate):
+ (WebCore::MediaEndpointPeerConnection::doneGatheringCandidates):
+ (WebCore::MediaEndpointPeerConnection::createAnswer): Deleted.
+ (WebCore::MediaEndpointPeerConnection::setLocalDescription): Deleted.
+ (WebCore::MediaEndpointPeerConnection::setRemoteDescription): Deleted.
+ (WebCore::MediaEndpointPeerConnection::addIceCandidate): Deleted.
+ (WebCore::MediaEndpointPeerConnection::stop): Deleted.
+ (WebCore::MediaEndpointPeerConnection::localDescriptionTypeValidForState): Deleted.
+ (WebCore::MediaEndpointPeerConnection::remoteDescriptionTypeValidForState): Deleted.
+ * Modules/mediastream/MediaEndpointPeerConnection.h:
+ * Modules/mediastream/PeerConnectionBackend.cpp:
+ (WebCore::PeerConnectionBackend::createOffer):
+ (WebCore::PeerConnectionBackend::createOfferFailed):
+ (WebCore::PeerConnectionBackend::createAnswer):
+ (WebCore::PeerConnectionBackend::createAnswerSucceeded):
+ (WebCore::PeerConnectionBackend::createAnswerFailed):
+ (WebCore::isLocalDescriptionTypeValidForState):
+ (WebCore::PeerConnectionBackend::setLocalDescription):
+ (WebCore::PeerConnectionBackend::setLocalDescriptionSucceeded):
+ (WebCore::PeerConnectionBackend::setLocalDescriptionFailed):
+ (WebCore::isRemoteDescriptionTypeValidForState):
+ (WebCore::PeerConnectionBackend::setRemoteDescription):
+ (WebCore::PeerConnectionBackend::setRemoteDescriptionSucceeded):
+ (WebCore::PeerConnectionBackend::setRemoteDescriptionFailed):
+ (WebCore::PeerConnectionBackend::addIceCandidate):
+ (WebCore::PeerConnectionBackend::addIceCandidateSucceeded):
+ (WebCore::PeerConnectionBackend::addIceCandidateFailed):
+ (WebCore::PeerConnectionBackend::fireICECandidateEvent):
+ (WebCore::PeerConnectionBackend::doneGatheringCandidates):
+ (WebCore::PeerConnectionBackend::stop):
+ * Modules/mediastream/PeerConnectionBackend.h:
+
2016-11-09 Eric Carlson <[email protected]>
[MediaStream][Mac] Mark captured video frames as ready for display immediately
Modified: trunk/Source/WebCore/Modules/mediastream/MediaEndpointPeerConnection.cpp (208444 => 208445)
--- trunk/Source/WebCore/Modules/mediastream/MediaEndpointPeerConnection.cpp 2016-11-09 18:27:37 UTC (rev 208444)
+++ trunk/Source/WebCore/Modules/mediastream/MediaEndpointPeerConnection.cpp 2016-11-09 18:28:08 UTC (rev 208445)
@@ -204,28 +204,25 @@
String sdp;
SDPProcessor::Result result = m_sdpProcessor->generate(*configurationSnapshot, sdp);
if (result != SDPProcessor::Result::Success) {
- createOfferFailed(OperationError, "SDPProcessor internal error");
+ createOfferFailed(Exception { OperationError, "SDPProcessor internal error" });
return;
}
createOfferSucceeded(WTFMove(sdp));
}
-void MediaEndpointPeerConnection::createAnswer(RTCAnswerOptions&& options, SessionDescriptionPromise&& promise)
+void MediaEndpointPeerConnection::doCreateAnswer(RTCAnswerOptions&& options)
{
- runTask([this, protectedOptions = WTFMove(options), protectedPromise = WTFMove(promise)]() mutable {
- createAnswerTask(protectedOptions, protectedPromise);
+ runTask([this, protectedOptions = WTFMove(options)]() mutable {
+ createAnswerTask(protectedOptions);
});
}
-void MediaEndpointPeerConnection::createAnswerTask(const RTCAnswerOptions&, SessionDescriptionPromise& promise)
+void MediaEndpointPeerConnection::createAnswerTask(const RTCAnswerOptions&)
{
ASSERT(!m_dtlsFingerprint.isEmpty());
- if (m_peerConnection.internalSignalingState() == SignalingState::Closed)
- return;
-
if (!internalRemoteDescription()) {
- promise.reject(INVALID_STATE_ERR, "No remote description set");
+ createAnswerFailed(Exception { INVALID_STATE_ERR, "No remote description set" });
return;
}
@@ -289,8 +286,13 @@
if (hasUnassociatedTransceivers(transceivers))
markAsNeedingNegotiation();
- auto description = MediaEndpointSessionDescription::create(RTCSessionDescription::SdpType::Answer, WTFMove(configurationSnapshot));
- promise.resolve(*description->toRTCSessionDescription(*m_sdpProcessor));
+ String sdp;
+ SDPProcessor::Result result = m_sdpProcessor->generate(*configurationSnapshot, sdp);
+ if (result != SDPProcessor::Result::Success) {
+ createAnswerFailed(Exception { OperationError, "SDPProcessor internal error" });
+ return;
+ }
+ createAnswerSucceeded(WTFMove(sdp));
}
static RealtimeMediaSourceMap createSourceMap(const MediaDescriptionVector& remoteMediaDescriptions, unsigned localMediaDescriptionCount, const RtpTransceiverVector& transceivers)
@@ -312,14 +314,14 @@
return sourceMap;
}
-void MediaEndpointPeerConnection::setLocalDescription(RTCSessionDescription& description, VoidPromise&& promise)
+void MediaEndpointPeerConnection::doSetLocalDescription(RTCSessionDescription& description)
{
- runTask([this, protectedDescription = RefPtr<RTCSessionDescription>(&description), protectedPromise = WTFMove(promise)]() mutable {
- setLocalDescriptionTask(WTFMove(protectedDescription), protectedPromise);
+ runTask([this, protectedDescription = RefPtr<RTCSessionDescription>(&description)]() mutable {
+ setLocalDescriptionTask(WTFMove(protectedDescription));
});
}
-void MediaEndpointPeerConnection::setLocalDescriptionTask(RefPtr<RTCSessionDescription>&& description, VoidPromise& promise)
+void MediaEndpointPeerConnection::setLocalDescriptionTask(RefPtr<RTCSessionDescription>&& description)
{
if (m_peerConnection.internalSignalingState() == SignalingState::Closed)
return;
@@ -326,16 +328,11 @@
auto result = MediaEndpointSessionDescription::create(WTFMove(description), *m_sdpProcessor);
if (result.hasException()) {
- promise.reject(result.releaseException());
+ setLocalDescriptionFailed(result.releaseException());
return;
}
auto newDescription = result.releaseReturnValue();
- if (!localDescriptionTypeValidForState(newDescription->type())) {
- promise.reject(INVALID_STATE_ERR, "Description type incompatible with current signaling state");
- return;
- }
-
const RtpTransceiverVector& transceivers = m_peerConnection.getTransceivers();
const MediaDescriptionVector& mediaDescriptions = newDescription->configuration()->mediaDescriptions();
MediaEndpointSessionDescription* localDescription = internalLocalDescription();
@@ -357,7 +354,7 @@
notImplemented();
} else if (result == MediaEndpoint::UpdateResult::Failed) {
- promise.reject(OperationError, "Unable to apply session description");
+ setLocalDescriptionFailed(Exception { OperationError, "Unable to apply session description" });
return;
}
@@ -376,7 +373,7 @@
RealtimeMediaSourceMap sendSourceMap = createSourceMap(remoteConfiguration->mediaDescriptions(), mediaDescriptions.size(), transceivers);
if (m_mediaEndpoint->updateSendConfiguration(remoteConfiguration, sendSourceMap, isInitiator) == MediaEndpoint::UpdateResult::Failed) {
- promise.reject(OperationError, "Unable to apply session description");
+ setLocalDescriptionFailed(Exception { OperationError, "Unable to apply session description" });
return;
}
}
@@ -423,7 +420,7 @@
if (m_peerConnection.internalSignalingState() == SignalingState::Stable && m_negotiationNeeded)
m_peerConnection.scheduleNegotiationNeededEvent();
- promise.resolve(nullptr);
+ setLocalDescriptionSucceeded();
}
RefPtr<RTCSessionDescription> MediaEndpointPeerConnection::localDescription() const
@@ -441,30 +438,22 @@
return createRTCSessionDescription(m_pendingLocalDescription.get());
}
-void MediaEndpointPeerConnection::setRemoteDescription(RTCSessionDescription& description, VoidPromise&& promise)
+void MediaEndpointPeerConnection::doSetRemoteDescription(RTCSessionDescription& description)
{
- runTask([this, protectedDescription = RefPtr<RTCSessionDescription>(&description), protectedPromise = WTFMove(promise)]() mutable {
- setRemoteDescriptionTask(WTFMove(protectedDescription), protectedPromise);
+ runTask([this, protectedDescription = RefPtr<RTCSessionDescription>(&description)]() mutable {
+ setRemoteDescriptionTask(WTFMove(protectedDescription));
});
}
-void MediaEndpointPeerConnection::setRemoteDescriptionTask(RefPtr<RTCSessionDescription>&& description, VoidPromise& promise)
+void MediaEndpointPeerConnection::setRemoteDescriptionTask(RefPtr<RTCSessionDescription>&& description)
{
- if (m_peerConnection.internalSignalingState() == SignalingState::Closed)
- return;
-
auto result = MediaEndpointSessionDescription::create(WTFMove(description), *m_sdpProcessor);
if (result.hasException()) {
- promise.reject(result.releaseException());
+ setRemoteDescriptionFailed(result.releaseException());
return;
}
auto newDescription = result.releaseReturnValue();
- if (!remoteDescriptionTypeValidForState(newDescription->type())) {
- promise.reject(INVALID_STATE_ERR, "Description type incompatible with current signaling state");
- return;
- }
-
auto& mediaDescriptions = newDescription->configuration()->mediaDescriptions();
for (auto& mediaDescription : mediaDescriptions) {
if (mediaDescription.type != "audio" && mediaDescription.type != "video")
@@ -481,7 +470,7 @@
sendSourceMap = createSourceMap(mediaDescriptions, internalLocalDescription()->configuration()->mediaDescriptions().size(), transceivers);
if (m_mediaEndpoint->updateSendConfiguration(newDescription->configuration(), sendSourceMap, isInitiator) == MediaEndpoint::UpdateResult::Failed) {
- promise.reject(OperationError, "Unable to apply session description");
+ setRemoteDescriptionFailed(Exception { OperationError, "Unable to apply session description" });
return;
}
@@ -594,7 +583,7 @@
m_peerConnection.fireEvent(Event::create(eventNames().signalingstatechangeEvent, false, false));
}
- promise.resolve(nullptr);
+ setRemoteDescriptionSucceeded();
}
RefPtr<RTCSessionDescription> MediaEndpointPeerConnection::remoteDescription() const
@@ -629,20 +618,17 @@
m_mediaEndpoint->setConfiguration({ WTFMove(iceServers), configuration.iceTransportPolicy(), configuration.bundlePolicy() });
}
-void MediaEndpointPeerConnection::addIceCandidate(RTCIceCandidate& rtcCandidate, PeerConnection::VoidPromise&& promise)
+void MediaEndpointPeerConnection::doAddIceCandidate(RTCIceCandidate& rtcCandidate)
{
- runTask([this, protectedCandidate = RefPtr<RTCIceCandidate>(&rtcCandidate), protectedPromise = WTFMove(promise)]() mutable {
- addIceCandidateTask(*protectedCandidate, protectedPromise);
+ runTask([this, protectedCandidate = RefPtr<RTCIceCandidate>(&rtcCandidate)]() mutable {
+ addIceCandidateTask(*protectedCandidate);
});
}
-void MediaEndpointPeerConnection::addIceCandidateTask(RTCIceCandidate& rtcCandidate, PeerConnection::VoidPromise& promise)
+void MediaEndpointPeerConnection::addIceCandidateTask(RTCIceCandidate& rtcCandidate)
{
- if (m_peerConnection.internalSignalingState() == SignalingState::Closed)
- return;
-
if (!internalRemoteDescription()) {
- promise.reject(INVALID_STATE_ERR, "No remote description set");
+ addIceCandidateFailed(Exception { INVALID_STATE_ERR, "No remote description set" });
return;
}
@@ -661,13 +647,13 @@
}
if (!targetMediaDescription) {
- promise.reject(OperationError, "sdpMid did not match any media description");
+ addIceCandidateFailed(Exception { OperationError, "sdpMid did not match any media description" });
return;
}
} else if (rtcCandidate.sdpMLineIndex()) {
unsigned short sdpMLineIndex = rtcCandidate.sdpMLineIndex().value();
if (sdpMLineIndex >= remoteMediaDescriptions.size()) {
- promise.reject(OperationError, "sdpMLineIndex is out of range");
+ addIceCandidateFailed(Exception { OperationError, "sdpMLineIndex is out of range" });
return;
}
targetMediaDescription = &remoteMediaDescriptions[sdpMLineIndex];
@@ -679,7 +665,7 @@
auto result = m_sdpProcessor->parseCandidateLine(rtcCandidate.candidate());
if (result.parsingStatus() != SDPProcessor::Result::Success) {
if (result.parsingStatus() == SDPProcessor::Result::ParseError)
- promise.reject(OperationError, "Invalid candidate content");
+ addIceCandidateFailed(Exception { OperationError, "Invalid candidate content" });
else
LOG_ERROR("SDPProcessor internal error");
return;
@@ -690,7 +676,7 @@
targetMediaDescription->addIceCandidate(WTFMove(result.candidate()));
- promise.resolve(nullptr);
+ addIceCandidateSucceeded();
}
void MediaEndpointPeerConnection::getStats(MediaStreamTrack*, PeerConnection::StatsPromise&& promise)
@@ -750,7 +736,7 @@
promise.resolve(nullptr);
}
-void MediaEndpointPeerConnection::stop()
+void MediaEndpointPeerConnection::doStop()
{
m_mediaEndpoint->stop();
}
@@ -771,44 +757,6 @@
m_mediaEndpoint->emulatePlatformEvent(action);
}
-bool MediaEndpointPeerConnection::localDescriptionTypeValidForState(RTCSessionDescription::SdpType type) const
-{
- switch (m_peerConnection.internalSignalingState()) {
- case SignalingState::Stable:
- return type == RTCSessionDescription::SdpType::Offer;
- case SignalingState::HaveLocalOffer:
- return type == RTCSessionDescription::SdpType::Offer;
- case SignalingState::HaveRemoteOffer:
- return type == RTCSessionDescription::SdpType::Answer || type == RTCSessionDescription::SdpType::Pranswer;
- case SignalingState::HaveLocalPrAnswer:
- return type == RTCSessionDescription::SdpType::Answer || type == RTCSessionDescription::SdpType::Pranswer;
- default:
- return false;
- };
-
- ASSERT_NOT_REACHED();
- return false;
-}
-
-bool MediaEndpointPeerConnection::remoteDescriptionTypeValidForState(RTCSessionDescription::SdpType type) const
-{
- switch (m_peerConnection.internalSignalingState()) {
- case SignalingState::Stable:
- return type == RTCSessionDescription::SdpType::Offer;
- case SignalingState::HaveLocalOffer:
- return type == RTCSessionDescription::SdpType::Answer || type == RTCSessionDescription::SdpType::Pranswer;
- case SignalingState::HaveRemoteOffer:
- return type == RTCSessionDescription::SdpType::Offer;
- case SignalingState::HaveRemotePrAnswer:
- return type == RTCSessionDescription::SdpType::Answer || type == RTCSessionDescription::SdpType::Pranswer;
- default:
- return false;
- };
-
- ASSERT_NOT_REACHED();
- return false;
-}
-
MediaEndpointSessionDescription* MediaEndpointPeerConnection::internalLocalDescription() const
{
return m_pendingLocalDescription ? m_pendingLocalDescription.get() : m_currentLocalDescription.get();
@@ -858,7 +806,7 @@
mediaDescriptions[mediaDescriptionIndex].addIceCandidate(WTFMove(candidate));
- m_peerConnection.fireEvent(RTCIceCandidateEvent::create(false, false, RTCIceCandidate::create(candidateLine, mid, mediaDescriptionIndex)));
+ fireICECandidateEvent(RTCIceCandidate::create(candidateLine, mid, mediaDescriptionIndex));
}
void MediaEndpointPeerConnection::doneGatheringCandidates(const String& mid)
@@ -876,10 +824,8 @@
return !current.stopped() && !current.mid().isNull()
&& current.iceTransport().gatheringState() != RTCIceTransport::GatheringState::Complete;
});
- if (!stillGatheringTransceiver) {
- m_peerConnection.fireEvent(RTCIceCandidateEvent::create(false, false, nullptr));
- m_peerConnection.updateIceGatheringState(IceGatheringState::Complete);
- }
+ if (!stillGatheringTransceiver)
+ PeerConnectionBackend::doneGatheringCandidates();
}
static RTCIceTransport::TransportState deriveAggregatedIceConnectionState(const Vector<RTCIceTransport::TransportState>& states)
Modified: trunk/Source/WebCore/Modules/mediastream/MediaEndpointPeerConnection.h (208444 => 208445)
--- trunk/Source/WebCore/Modules/mediastream/MediaEndpointPeerConnection.h 2016-11-09 18:27:37 UTC (rev 208444)
+++ trunk/Source/WebCore/Modules/mediastream/MediaEndpointPeerConnection.h 2016-11-09 18:28:08 UTC (rev 208445)
@@ -54,21 +54,15 @@
public:
MediaEndpointPeerConnection(RTCPeerConnection&);
- void doCreateOffer(RTCOfferOptions&&) final;
- void createAnswer(RTCAnswerOptions&&, PeerConnection::SessionDescriptionPromise&&) override;
-
- void setLocalDescription(RTCSessionDescription&, PeerConnection::VoidPromise&&) override;
RefPtr<RTCSessionDescription> localDescription() const override;
RefPtr<RTCSessionDescription> currentLocalDescription() const override;
RefPtr<RTCSessionDescription> pendingLocalDescription() const override;
- void setRemoteDescription(RTCSessionDescription&, PeerConnection::VoidPromise&&) override;
RefPtr<RTCSessionDescription> remoteDescription() const override;
RefPtr<RTCSessionDescription> currentRemoteDescription() const override;
RefPtr<RTCSessionDescription> pendingRemoteDescription() const override;
void setConfiguration(RTCConfiguration&) override;
- void addIceCandidate(RTCIceCandidate&, PeerConnection::VoidPromise&&) override;
void getStats(MediaStreamTrack*, PeerConnection::StatsPromise&&) override;
@@ -77,8 +71,6 @@
RefPtr<RTCRtpReceiver> createReceiver(const String& transceiverMid, const String& trackKind, const String& trackId) override;
void replaceTrack(RTCRtpSender&, RefPtr<MediaStreamTrack>&&, PeerConnection::VoidPromise&&) override;
- void stop() override;
-
bool isNegotiationNeeded() const override { return m_negotiationNeeded; };
void markAsNeedingNegotiation() override;
void clearNegotiationNeededState() override { m_negotiationNeeded = false; };
@@ -89,13 +81,20 @@
void runTask(Function<void ()>&&);
void startRunningTasks();
+ void doCreateOffer(RTCOfferOptions&&) final;
+ void doCreateAnswer(RTCAnswerOptions&&) final;
+ void doSetLocalDescription(RTCSessionDescription&) final;
+ void doSetRemoteDescription(RTCSessionDescription&) final;
+ void doAddIceCandidate(RTCIceCandidate&) final;
+ void doStop() final;
+
void createOfferTask(const RTCOfferOptions&);
- void createAnswerTask(const RTCAnswerOptions&, PeerConnection::SessionDescriptionPromise&);
+ void createAnswerTask(const RTCAnswerOptions&);
- void setLocalDescriptionTask(RefPtr<RTCSessionDescription>&&, PeerConnection::VoidPromise&);
- void setRemoteDescriptionTask(RefPtr<RTCSessionDescription>&&, PeerConnection::VoidPromise&);
+ void setLocalDescriptionTask(RefPtr<RTCSessionDescription>&&);
+ void setRemoteDescriptionTask(RefPtr<RTCSessionDescription>&&);
- void addIceCandidateTask(RTCIceCandidate&, PeerConnection::VoidPromise&);
+ void addIceCandidateTask(RTCIceCandidate&);
void replaceTrackTask(RTCRtpSender&, const String& mid, RefPtr<MediaStreamTrack>&&, PeerConnection::VoidPromise&);
Modified: trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp (208444 => 208445)
--- trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp 2016-11-09 18:27:37 UTC (rev 208444)
+++ trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp 2016-11-09 18:28:08 UTC (rev 208445)
@@ -35,6 +35,8 @@
#if ENABLE(WEB_RTC)
#include "JSRTCSessionDescription.h"
+#include "RTCIceCandidate.h"
+#include "RTCIceCandidateEvent.h"
#include "RTCPeerConnection.h"
namespace WebCore {
@@ -42,10 +44,8 @@
void PeerConnectionBackend::createOffer(RTCOfferOptions&& options, PeerConnection::SessionDescriptionPromise&& promise)
{
ASSERT(!m_offerAnswerPromise);
+ ASSERT(m_peerConnection.internalSignalingState() != PeerConnectionStates::SignalingState::Closed);
- if (m_peerConnection.internalSignalingState() == PeerConnectionStates::SignalingState::Closed)
- return;
-
m_offerAnswerPromise = WTFMove(promise);
doCreateOffer(WTFMove(options));
}
@@ -62,7 +62,7 @@
m_offerAnswerPromise = Nullopt;
}
-void PeerConnectionBackend::createOfferFailed(ExceptionCode ec, String&& error)
+void PeerConnectionBackend::createOfferFailed(Exception&& exception)
{
ASSERT(isMainThread());
@@ -70,10 +70,221 @@
return;
ASSERT(m_offerAnswerPromise);
- m_offerAnswerPromise->reject(ec, WTFMove(error));
+ m_offerAnswerPromise->reject(WTFMove(exception));
m_offerAnswerPromise = Nullopt;
}
+void PeerConnectionBackend::createAnswer(RTCAnswerOptions&& options, PeerConnection::SessionDescriptionPromise&& promise)
+{
+ ASSERT(!m_offerAnswerPromise);
+ ASSERT(m_peerConnection.internalSignalingState() != PeerConnectionStates::SignalingState::Closed);
+
+ m_offerAnswerPromise = WTFMove(promise);
+ doCreateAnswer(WTFMove(options));
+}
+
+void PeerConnectionBackend::createAnswerSucceeded(String&& sdp)
+{
+ ASSERT(isMainThread());
+
+ if (m_peerConnection.internalSignalingState() == PeerConnectionStates::SignalingState::Closed)
+ return;
+
+ ASSERT(m_offerAnswerPromise);
+ m_offerAnswerPromise->resolve(RTCSessionDescription::create(RTCSessionDescription::SdpType::Answer, WTFMove(sdp)));
+ m_offerAnswerPromise = Nullopt;
+}
+
+void PeerConnectionBackend::createAnswerFailed(Exception&& exception)
+{
+ ASSERT(isMainThread());
+
+ if (m_peerConnection.internalSignalingState() == PeerConnectionStates::SignalingState::Closed)
+ return;
+
+ ASSERT(m_offerAnswerPromise);
+ m_offerAnswerPromise->reject(WTFMove(exception));
+ m_offerAnswerPromise = Nullopt;
+}
+
+static inline bool isLocalDescriptionTypeValidForState(RTCSessionDescription::SdpType type, PeerConnectionStates::SignalingState state)
+{
+ switch (state) {
+ case PeerConnectionStates::SignalingState::Stable:
+ return type == RTCSessionDescription::SdpType::Offer;
+ case PeerConnectionStates::SignalingState::HaveLocalOffer:
+ return type == RTCSessionDescription::SdpType::Offer;
+ case PeerConnectionStates::SignalingState::HaveRemoteOffer:
+ return type == RTCSessionDescription::SdpType::Answer || type == RTCSessionDescription::SdpType::Pranswer;
+ case PeerConnectionStates::SignalingState::HaveLocalPrAnswer:
+ return type == RTCSessionDescription::SdpType::Answer || type == RTCSessionDescription::SdpType::Pranswer;
+ default:
+ return false;
+ };
+
+ ASSERT_NOT_REACHED();
+ return false;
+}
+
+void PeerConnectionBackend::setLocalDescription(RTCSessionDescription& sessionDescription, PeerConnection::VoidPromise&& promise)
+{
+ ASSERT(m_peerConnection.internalSignalingState() != PeerConnectionStates::SignalingState::Closed);
+
+ if (!isLocalDescriptionTypeValidForState(sessionDescription.type(), m_peerConnection.internalSignalingState())) {
+ promise.reject(INVALID_STATE_ERR, "Description type incompatible with current signaling state");
+ return;
+ }
+
+ m_setDescriptionPromise = WTFMove(promise);
+ doSetLocalDescription(sessionDescription);
+}
+
+void PeerConnectionBackend::setLocalDescriptionSucceeded()
+{
+ ASSERT(isMainThread());
+
+ if (m_peerConnection.internalSignalingState() == PeerConnectionStates::SignalingState::Closed)
+ return;
+
+ ASSERT(m_setDescriptionPromise);
+
+ m_setDescriptionPromise->resolve(nullptr);
+ m_setDescriptionPromise = Nullopt;
+}
+
+void PeerConnectionBackend::setLocalDescriptionFailed(Exception&& exception)
+{
+ ASSERT(isMainThread());
+
+ if (m_peerConnection.internalSignalingState() == PeerConnectionStates::SignalingState::Closed)
+ return;
+
+ ASSERT(m_setDescriptionPromise);
+
+ m_setDescriptionPromise->reject(WTFMove(exception));
+ m_setDescriptionPromise = Nullopt;
+}
+
+static inline bool isRemoteDescriptionTypeValidForState(RTCSessionDescription::SdpType type, PeerConnectionStates::SignalingState state)
+{
+ switch (state) {
+ case PeerConnectionStates::SignalingState::Stable:
+ return type == RTCSessionDescription::SdpType::Offer;
+ case PeerConnectionStates::SignalingState::HaveLocalOffer:
+ return type == RTCSessionDescription::SdpType::Answer || type == RTCSessionDescription::SdpType::Pranswer;
+ case PeerConnectionStates::SignalingState::HaveRemoteOffer:
+ return type == RTCSessionDescription::SdpType::Offer;
+ case PeerConnectionStates::SignalingState::HaveRemotePrAnswer:
+ return type == RTCSessionDescription::SdpType::Answer || type == RTCSessionDescription::SdpType::Pranswer;
+ default:
+ return false;
+ };
+
+ ASSERT_NOT_REACHED();
+ return false;
+}
+
+void PeerConnectionBackend::setRemoteDescription(RTCSessionDescription& sessionDescription, PeerConnection::VoidPromise&& promise)
+{
+ ASSERT(m_peerConnection.internalSignalingState() != PeerConnectionStates::SignalingState::Closed);
+
+ if (!isRemoteDescriptionTypeValidForState(sessionDescription.type(), m_peerConnection.internalSignalingState())) {
+ promise.reject(INVALID_STATE_ERR, "Description type incompatible with current signaling state");
+ return;
+ }
+
+ m_setDescriptionPromise = WTFMove(promise);
+ doSetRemoteDescription(sessionDescription);
+}
+
+void PeerConnectionBackend::setRemoteDescriptionSucceeded()
+{
+ ASSERT(isMainThread());
+
+ if (m_peerConnection.internalSignalingState() == PeerConnectionStates::SignalingState::Closed)
+ return;
+
+ ASSERT(m_setDescriptionPromise);
+
+ m_setDescriptionPromise->resolve(nullptr);
+ m_setDescriptionPromise = Nullopt;
+}
+
+void PeerConnectionBackend::setRemoteDescriptionFailed(Exception&& exception)
+{
+ ASSERT(isMainThread());
+
+ if (m_peerConnection.internalSignalingState() == PeerConnectionStates::SignalingState::Closed)
+ return;
+
+ ASSERT(m_setDescriptionPromise);
+
+ m_setDescriptionPromise->reject(WTFMove(exception));
+ m_setDescriptionPromise = Nullopt;
+}
+
+void PeerConnectionBackend::addIceCandidate(RTCIceCandidate& iceCandidate, PeerConnection::VoidPromise&& promise)
+{
+ ASSERT(m_peerConnection.internalSignalingState() != PeerConnectionStates::SignalingState::Closed);
+
+ if (iceCandidate.sdpMid().isNull() && !iceCandidate.sdpMLineIndex()) {
+ promise.reject(Exception { TypeError, ASCIILiteral("Trying to add a candidate that is missing both sdpMid and sdpMLineIndex") });
+ return;
+ }
+ m_addIceCandidatePromise = WTFMove(promise);
+ doAddIceCandidate(iceCandidate);
+}
+
+void PeerConnectionBackend::addIceCandidateSucceeded()
+{
+ ASSERT(isMainThread());
+
+ if (m_peerConnection.internalSignalingState() == PeerConnectionStates::SignalingState::Closed)
+ return;
+
+ // FIXME: Update remote description and set ICE connection state to checking if not already done so.
+ ASSERT(m_addIceCandidatePromise);
+
+ m_addIceCandidatePromise->resolve(nullptr);
+ m_addIceCandidatePromise = Nullopt;
+}
+
+void PeerConnectionBackend::addIceCandidateFailed(Exception&& exception)
+{
+ ASSERT(isMainThread());
+ if (m_peerConnection.internalSignalingState() == PeerConnectionStates::SignalingState::Closed)
+ return;
+
+ ASSERT(m_addIceCandidatePromise);
+
+ m_addIceCandidatePromise->reject(WTFMove(exception));
+ m_addIceCandidatePromise = Nullopt;
+}
+
+void PeerConnectionBackend::fireICECandidateEvent(RefPtr<RTCIceCandidate>&& candidate)
+{
+ ASSERT(isMainThread());
+
+ m_peerConnection.fireEvent(RTCIceCandidateEvent::create(false, false, WTFMove(candidate)));
+}
+
+void PeerConnectionBackend::doneGatheringCandidates()
+{
+ ASSERT(isMainThread());
+
+ m_peerConnection.fireEvent(RTCIceCandidateEvent::create(false, false, nullptr));
+ m_peerConnection.updateIceGatheringState(PeerConnectionStates::IceGatheringState::Complete);
+}
+
+void PeerConnectionBackend::stop()
+{
+ m_offerAnswerPromise = Nullopt;
+ m_setDescriptionPromise = Nullopt;
+ m_addIceCandidatePromise = Nullopt;
+
+ doStop();
+}
+
} // namespace WebCore
#endif // ENABLE(WEB_RTC)
Modified: trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.h (208444 => 208445)
--- trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.h 2016-11-09 18:27:37 UTC (rev 208444)
+++ trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.h 2016-11-09 18:28:08 UTC (rev 208445)
@@ -56,8 +56,6 @@
struct RTCAnswerOptions;
struct RTCOfferOptions;
-using ExceptionCode = int;
-
namespace PeerConnection {
typedef DOMPromise<RTCSessionDescription> SessionDescriptionPromise;
typedef DOMPromise<std::nullptr_t> VoidPromise;
@@ -74,24 +72,22 @@
virtual ~PeerConnectionBackend() { }
void createOffer(RTCOfferOptions&&, PeerConnection::SessionDescriptionPromise&&);
- virtual void doCreateOffer(RTCOfferOptions&&) = 0;
- void createOfferSucceeded(String&&);
- void createOfferFailed(ExceptionCode, String&&);
+ void createAnswer(RTCAnswerOptions&&, PeerConnection::SessionDescriptionPromise&&);
+ void setLocalDescription(RTCSessionDescription&, PeerConnection::VoidPromise&&);
+ void setRemoteDescription(RTCSessionDescription&, PeerConnection::VoidPromise&&);
+ void addIceCandidate(RTCIceCandidate&, PeerConnection::VoidPromise&&);
- virtual void createAnswer(RTCAnswerOptions&&, PeerConnection::SessionDescriptionPromise&&) = 0;
+ void stop();
- virtual void setLocalDescription(RTCSessionDescription&, PeerConnection::VoidPromise&&) = 0;
virtual RefPtr<RTCSessionDescription> localDescription() const = 0;
virtual RefPtr<RTCSessionDescription> currentLocalDescription() const = 0;
virtual RefPtr<RTCSessionDescription> pendingLocalDescription() const = 0;
- virtual void setRemoteDescription(RTCSessionDescription&, PeerConnection::VoidPromise&&) = 0;
virtual RefPtr<RTCSessionDescription> remoteDescription() const = 0;
virtual RefPtr<RTCSessionDescription> currentRemoteDescription() const = 0;
virtual RefPtr<RTCSessionDescription> pendingRemoteDescription() const = 0;
virtual void setConfiguration(RTCConfiguration&) = 0;
- virtual void addIceCandidate(RTCIceCandidate&, PeerConnection::VoidPromise&&) = 0;
virtual void getStats(MediaStreamTrack*, PeerConnection::StatsPromise&&) = 0;
@@ -100,8 +96,6 @@
virtual RefPtr<RTCRtpReceiver> createReceiver(const String& transceiverMid, const String& trackKind, const String& trackId) = 0;
virtual void replaceTrack(RTCRtpSender&, RefPtr<MediaStreamTrack>&&, PeerConnection::VoidPromise&&) = 0;
- virtual void stop() = 0;
-
virtual bool isNegotiationNeeded() const = 0;
virtual void markAsNeedingNegotiation() = 0;
virtual void clearNegotiationNeededState() = 0;
@@ -109,8 +103,39 @@
virtual void emulatePlatformEvent(const String& action) = 0;
protected:
+ void fireICECandidateEvent(RefPtr<RTCIceCandidate>&&);
+ void doneGatheringCandidates();
+
+ void createOfferSucceeded(String&&);
+ void createOfferFailed(Exception&&);
+
+ void createAnswerSucceeded(String&&);
+ void createAnswerFailed(Exception&&);
+
+ void setLocalDescriptionSucceeded();
+ void setLocalDescriptionFailed(Exception&&);
+
+ void setRemoteDescriptionSucceeded();
+ void setRemoteDescriptionFailed(Exception&&);
+
+ void addIceCandidateSucceeded();
+ void addIceCandidateFailed(Exception&&);
+
+private:
+ virtual void doCreateOffer(RTCOfferOptions&&) = 0;
+ virtual void doCreateAnswer(RTCAnswerOptions&&) = 0;
+ virtual void doSetLocalDescription(RTCSessionDescription&) = 0;
+ virtual void doSetRemoteDescription(RTCSessionDescription&) = 0;
+ virtual void doAddIceCandidate(RTCIceCandidate&) = 0;
+ virtual void doStop() = 0;
+
+protected:
RTCPeerConnection& m_peerConnection;
+
+private:
Optional<PeerConnection::SessionDescriptionPromise> m_offerAnswerPromise;
+ Optional<PeerConnection::VoidPromise> m_setDescriptionPromise;
+ Optional<PeerConnection::VoidPromise> m_addIceCandidatePromise;
};
} // namespace WebCore