Bug 1411977 - Part 7: Stop using extra dispatches for ICE candidates and gathering state changes. r?drno
MozReview-Commit-ID: 6OvhNJER4wc
--- a/dom/media/PeerConnection.js
+++ b/dom/media/PeerConnection.js
@@ -374,17 +374,17 @@ class RTCPeerConnection {
this._localType = null;
this._remoteType = null;
// http://rtcweb-wg.github.io/jsep/#rfc.section.4.1.9
// canTrickle == null means unknown; when a remote description is received it
// is set to true or false based on the presence of the "trickle" ice-option
this._canTrickle = null;
// States
- this._iceGatheringState = this._iceConnectionState = "new";
+ this._iceConnectionState = "new";
this._hasStunServer = this._hasTurnServer = false;
this._iceGatheredRelayCandidates = false;
// Stored webrtc timing information
this._storedRtpSourceReferenceTime = null;
// TODO: Remove legacy API eventually
// see Bug 1328194
this._onGetStatsIsLegacy = false;
@@ -1514,17 +1514,17 @@ class RTCPeerConnection {
}
return new this._win.RTCSessionDescription({ type: this._remoteType, sdp });
}
get peerIdentity() { return this._peerIdentity; }
get idpLoginUrl() { return this._localIdp.idpLoginUrl; }
get id() { return this._impl.id; }
set id(s) { this._impl.id = s; }
- get iceGatheringState() { return this._iceGatheringState; }
+ get iceGatheringState() { return this._pc.iceGatheringState; }
get iceConnectionState() { return this._iceConnectionState; }
get signalingState() {
// checking for our local pc closed indication
// before invoking the pc methods.
if (this._closed) {
return "closed";
}
@@ -1534,18 +1534,17 @@ class RTCPeerConnection {
"SignalingHaveLocalOffer": "have-local-offer",
"SignalingHaveRemoteOffer": "have-remote-offer",
"SignalingHaveLocalPranswer": "have-local-pranswer",
"SignalingHaveRemotePranswer": "have-remote-pranswer",
"SignalingClosed": "closed"
}[this._impl.signalingState];
}
- changeIceGatheringState(state) {
- this._iceGatheringState = state;
+ notifyIceGatheringStateChange() {
_globalPCList.notifyLifecycleObservers(this, "icegatheringstatechange");
this.dispatchEvent(new this._win.Event("icegatheringstatechange"));
}
changeIceConnectionState(state) {
if (state != this._iceConnectionState) {
this._iceConnectionState = state;
_globalPCList.notifyLifecycleObservers(this, "iceconnectionstatechange");
@@ -1776,51 +1775,47 @@ class PeerConnectionObserver {
} else {
pc.logError("ICE failed, see about:webrtc for more details");
}
}
pc.changeIceConnectionState(iceConnectionState);
}
- // This method is responsible for updating iceGatheringState. This
- // state is defined in the WebRTC specification as follows:
+ // This method is responsible for firing events for changes in ICE gathering
+ // state.
//
// iceGatheringState:
// ------------------
// new The object was just created, and no networking has occurred
// yet.
//
// gathering The ICE agent is in the process of gathering candidates for
// this RTCPeerConnection.
//
// complete The ICE agent has completed gathering. Events such as adding
// a new interface or a new TURN server will cause the state to
// go back to gathering.
//
- handleIceGatheringStateChange(gatheringState) {
- let pc = this._dompc;
- if (pc.iceGatheringState === gatheringState) {
- return;
- }
- pc.changeIceGatheringState(gatheringState);
+ handleIceGatheringStateChange() {
+ this._dompc.notifyIceGatheringStateChange();
}
onStateChange(state) {
switch (state) {
case "SignalingState":
this.dispatchEvent(new this._win.Event("signalingstatechange"));
break;
case "IceConnectionState":
this.handleIceConnectionStateChange(this._dompc._pc.iceConnectionState);
break;
case "IceGatheringState":
- this.handleIceGatheringStateChange(this._dompc._pc.iceGatheringState);
+ this.handleIceGatheringStateChange();
break;
default:
this._dompc.logWarning("Unhandled state type: " + state);
break;
}
}
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
@@ -3083,50 +3083,33 @@ PeerConnectionImpl::CandidateReady(const
return;
}
CSFLogDebug(LOGTAG, "Passing local candidate to content: %s",
candidate.c_str());
SendLocalIceCandidateToContent(level, mid, candidate);
}
-static void
-SendLocalIceCandidateToContentImpl(nsWeakPtr weakPCObserver,
- uint16_t level,
- const std::string& mid,
- const std::string& candidate) {
- RefPtr<PeerConnectionObserver> pco = do_QueryObjectReferent(weakPCObserver);
+void
+PeerConnectionImpl::SendLocalIceCandidateToContent(
+ uint16_t level,
+ const std::string& mid,
+ const std::string& candidate) {
+ RefPtr<PeerConnectionObserver> pco = do_QueryObjectReferent(mPCObserver);
if (!pco) {
return;
}
JSErrorResult rv;
pco->OnIceCandidate(level,
ObString(mid.c_str()),
ObString(candidate.c_str()),
rv);
}
-void
-PeerConnectionImpl::SendLocalIceCandidateToContent(
- uint16_t level,
- const std::string& mid,
- const std::string& candidate) {
- // We dispatch this because OnSetLocalDescriptionSuccess does a setTimeout(0)
- // to unwind the stack, but the event handlers don't. We need to ensure that
- // the candidates do not skip ahead of the callback.
- NS_DispatchToMainThread(
- WrapRunnableNM(&SendLocalIceCandidateToContentImpl,
- mPCObserver,
- level,
- mid,
- candidate),
- NS_DISPATCH_NORMAL);
-}
-
static bool isDone(PCImplIceConnectionState state) {
return state != PCImplIceConnectionState::Checking &&
state != PCImplIceConnectionState::New;
}
static bool isSucceeded(PCImplIceConnectionState state) {
return state == PCImplIceConnectionState::Connected ||
state == PCImplIceConnectionState::Completed;
@@ -3244,25 +3227,22 @@ PeerConnectionImpl::IceGatheringStateCha
MOZ_ASSERT_UNREACHABLE("Unexpected mIceGatheringState!");
}
RefPtr<PeerConnectionObserver> pco = do_QueryObjectReferent(mPCObserver);
if (!pco) {
return;
}
WrappableJSErrorResult rv;
- mThread->Dispatch(WrapRunnable(pco,
- &PeerConnectionObserver::OnStateChange,
- PCObserverStateType::IceGatheringState,
- rv, static_cast<JSCompartment*>(nullptr)),
- NS_DISPATCH_NORMAL);
if (mIceGatheringState == PCImplIceGatheringState::Complete) {
SendLocalIceCandidateToContent(0, "", "");
}
+
+ pco->OnStateChange(PCObserverStateType::IceGatheringState, rv);
}
void
PeerConnectionImpl::UpdateDefaultCandidate(const std::string& defaultAddr,
uint16_t defaultPort,
const std::string& defaultRtcpAddr,
uint16_t defaultRtcpPort,
uint16_t level) {