From 4515845c4e279fd7f3b875206a072e0108d228b2 Mon Sep 17 00:00:00 2001 From: EKR Date: Sun, 2 Dec 2012 13:49:56 -0800 Subject: [PATCH] Bug 817430: Set initial controlled/controlling values, based on inbound T/F. r=jesup --- media/mtransport/nricectx.cpp | 8 ++++++++ media/mtransport/nricectx.h | 7 +++++++ .../webrtc/signaling/src/media/VcmSIPCCBinding.cpp | 13 +++++++++---- media/webrtc/signaling/src/sipcc/core/gsm/fsmdef.c | 4 +++- media/webrtc/signaling/src/sipcc/core/gsm/lsm.c | 3 ++- media/webrtc/signaling/src/sipcc/include/vcm.h | 4 ++-- 6 files changed, 31 insertions(+), 8 deletions(-) diff --git a/media/mtransport/nricectx.cpp b/media/mtransport/nricectx.cpp index 5b1d6b1f5d8..e99cb2a81fd 100644 --- a/media/mtransport/nricectx.cpp +++ b/media/mtransport/nricectx.cpp @@ -349,6 +349,14 @@ void NrIceCtx::destroy_peer_ctx() { nr_ice_peer_ctx_destroy(&peer_); } +nsresult NrIceCtx::SetControlling(Controlling controlling) { + peer_->controlling = (controlling == ICE_CONTROLLING)? 1 : 0; + + MOZ_MTLOG(PR_LOG_DEBUG, "ICE ctx " << name_ << " setting controlling to" << + controlling); + return NS_OK; +} + nsresult NrIceCtx::StartGathering() { this->AddRef(); int r = nr_ice_initialize(ctx_, &NrIceCtx::initialized_cb, diff --git a/media/mtransport/nricectx.h b/media/mtransport/nricectx.h index 479dc40b551..d75e45c7e62 100644 --- a/media/mtransport/nricectx.h +++ b/media/mtransport/nricectx.h @@ -84,6 +84,10 @@ class NrIceCtx { ICE_CTX_FAILED }; + enum Controlling { ICE_CONTROLLING, + ICE_CONTROLLED + }; + static RefPtr Create(const std::string& name, bool offerer, bool set_interface_priorities = true); @@ -111,6 +115,9 @@ class NrIceCtx { // Set the other side's global attributes nsresult ParseGlobalAttributes(std::vector attrs); + // Set whether we are controlling or not. + nsresult SetControlling(Controlling controlling); + // Start ICE gathering nsresult StartGathering(); diff --git a/media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp b/media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp index 566fcac031e..defc3d6307b 100644 --- a/media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp +++ b/media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp @@ -743,7 +743,7 @@ short vcmSetIceCandidate(const char *peerconnection, * @param[in] peerconnection - the peerconnection in use * @return 0 success, error failure */ -static short vcmStartIceChecks_m(const char *peerconnection) +static short vcmStartIceChecks_m(const char *peerconnection, cc_boolean isControlling) { CSFLogDebug( logTag, "%s: PC = %s", __FUNCTION__, peerconnection); @@ -751,6 +751,12 @@ static short vcmStartIceChecks_m(const char *peerconnection) ENSURE_PC(pc, VCM_ERROR); nsresult res; + res = pc.impl()->media()->ice_ctx()->SetControlling( + isControlling ? NrIceCtx::ICE_CONTROLLING : NrIceCtx::ICE_CONTROLLED); + if (!NS_SUCCEEDED(res)) { + CSFLogError( logTag, "%s: couldn't set controlling", __FUNCTION__ ); + return VCM_ERROR; + } nsresult rv = pc.impl()->media()->ice_ctx()->thread()->Dispatch( WrapRunnableRet(pc.impl()->media()->ice_ctx(), &NrIceCtx::StartChecks, &res), NS_DISPATCH_SYNC); @@ -759,12 +765,10 @@ static short vcmStartIceChecks_m(const char *peerconnection) CSFLogError( logTag, "%s(): Could not dispatch to ICE thread", __FUNCTION__); return VCM_ERROR; } - if (!NS_SUCCEEDED(res)) { CSFLogError( logTag, "%s: couldn't start ICE checks", __FUNCTION__ ); return VCM_ERROR; } - return 0; } @@ -776,13 +780,14 @@ static short vcmStartIceChecks_m(const char *peerconnection) * @param[in] peerconnection - the peerconnection in use * @return 0 success, error failure */ -short vcmStartIceChecks(const char *peerconnection) +short vcmStartIceChecks(const char *peerconnection, cc_boolean isControlling) { short ret; VcmSIPCCBinding::getMainThread()->Dispatch( WrapRunnableNMRet(&vcmStartIceChecks_m, peerconnection, + isControlling, &ret), NS_DISPATCH_SYNC); diff --git a/media/webrtc/signaling/src/sipcc/core/gsm/fsmdef.c b/media/webrtc/signaling/src/sipcc/core/gsm/fsmdef.c index c2c28071a57..2410f0ccd48 100755 --- a/media/webrtc/signaling/src/sipcc/core/gsm/fsmdef.c +++ b/media/webrtc/signaling/src/sipcc/core/gsm/fsmdef.c @@ -2888,8 +2888,9 @@ fsmdef_ev_createoffer (sm_event_t *event) { FSM_DEBUG_SM(DEB_F_PREFIX"dcb is NULL.\n", DEB_F_PREFIX_ARGS(FSM, __FUNCTION__)); return SM_RC_CLEANUP; } + dcb->inbound = FALSE; - if (msg->data.session.has_constraints) { + if (msg->data.session.has_constraints) { sess_data_p = (session_data_t *)findhash(msg->data.session.sessionid); if (sess_data_p) { gsmsdp_process_cap_constraints(dcb, sess_data_p->cc_constraints); @@ -2994,6 +2995,7 @@ fsmdef_ev_createanswer (sm_event_t *event) { FSM_DEBUG_SM(DEB_F_PREFIX"dcb is NULL.\n", DEB_F_PREFIX_ARGS(FSM, __FUNCTION__)); return SM_RC_CLEANUP; } + dcb->inbound = TRUE; if (msg->data.session.has_constraints) { sess_data_p = (session_data_t *)findhash(msg->data.session.sessionid); diff --git a/media/webrtc/signaling/src/sipcc/core/gsm/lsm.c b/media/webrtc/signaling/src/sipcc/core/gsm/lsm.c index 5f234c085bb..4440b29578f 100755 --- a/media/webrtc/signaling/src/sipcc/core/gsm/lsm.c +++ b/media/webrtc/signaling/src/sipcc/core/gsm/lsm.c @@ -3996,7 +3996,8 @@ lsm_connected (lsm_lcb_t *lcb, cc_state_data_connected_t *data) /* Start ICE */ if (start_ice) { - short res = vcmStartIceChecks(dcb->peerconnection); + short res = vcmStartIceChecks(dcb->peerconnection, !dcb->inbound); + /* TODO(emannion): Set state to dead here. */ if (res) return CC_RC_SUCCESS; diff --git a/media/webrtc/signaling/src/sipcc/include/vcm.h b/media/webrtc/signaling/src/sipcc/include/vcm.h index e3185747e76..62e9c11f7bd 100755 --- a/media/webrtc/signaling/src/sipcc/include/vcm.h +++ b/media/webrtc/signaling/src/sipcc/include/vcm.h @@ -474,10 +474,10 @@ short vcmSetIceMediaParams(const char *peerconnection, int level, char *ufrag, c /* Start ICE checks * @param[in] peerconnection - the peerconnection in use - * @param[in] level - the m-line + * @param[in] isControlling - true if controlling, false if controlled * @return 0 success, error failure */ -short vcmStartIceChecks(const char *peerconnection); +short vcmStartIceChecks(const char *peerconnection, cc_boolean isControlling);