Bug 817430: Set initial controlled/controlling values, based on inbound T/F. r=jesup
authorEKR <ekr@rtfm.com>
Sun, 02 Dec 2012 13:49:56 -0800
changeset 125697 e48db20a0a46fe1b72f1c81ebc96dd94fac20560
parent 125696 60f6033378d4b07d1e1c507bf3bcdd6957d50e57
child 125698 47debf3f344cd1feff97922f59a35466c6d9d1a0
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs817430
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 817430: Set initial controlled/controlling values, based on inbound T/F. r=jesup
media/mtransport/nricectx.cpp
media/mtransport/nricectx.h
media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp
media/webrtc/signaling/src/sipcc/core/gsm/fsmdef.c
media/webrtc/signaling/src/sipcc/core/gsm/lsm.c
media/webrtc/signaling/src/sipcc/include/vcm.h
--- a/media/mtransport/nricectx.cpp
+++ b/media/mtransport/nricectx.cpp
@@ -344,16 +344,24 @@ NrIceCtx::CreateStream(const std::string
 
   return stream;
 }
 
 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,
                             this);
 
   if (r && r != R_WOULDBLOCK) {
       MOZ_MTLOG(PR_LOG_ERROR, "Couldn't gather ICE candidates for '"
            << name_ << "'");
--- a/media/mtransport/nricectx.h
+++ b/media/mtransport/nricectx.h
@@ -79,16 +79,20 @@ class NrIceCtx {
   enum State { ICE_CTX_INIT,
                ICE_CTX_GATHERING,
                ICE_CTX_GATHERED,
                ICE_CTX_CHECKING,
                ICE_CTX_OPEN,
                ICE_CTX_FAILED
   };
 
+  enum Controlling { ICE_CONTROLLING,
+                     ICE_CONTROLLED
+  };
+
   static RefPtr<NrIceCtx> Create(const std::string& name,
                                           bool offerer,
                                           bool set_interface_priorities = true);
   virtual ~NrIceCtx();
 
   nr_ice_ctx *ctx() { return ctx_; }
   nr_ice_peer_ctx *peer() { return peer_; }
 
@@ -106,16 +110,19 @@ class NrIceCtx {
   State state() const { return state_; }
 
   // Get the global attributes
   std::vector<std::string> GetGlobalAttributes();
 
   // Set the other side's global attributes
   nsresult ParseGlobalAttributes(std::vector<std::string> attrs);
 
+  // Set whether we are controlling or not.
+  nsresult SetControlling(Controlling controlling);
+
   // Start ICE gathering
   nsresult StartGathering();
 
   // Start checking
   nsresult StartChecks();
 
   // Finalize the ICE negotiation. I.e., there will be no
   // more forking.
--- a/media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp
+++ b/media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp
@@ -738,56 +738,61 @@ short vcmSetIceCandidate(const char *pee
   return ret;
 }
 
 
 /* Start ICE checks
  *  @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);
 
   sipcc::PeerConnectionWrapper pc(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);
 
   if (!NS_SUCCEEDED(rv)) {
     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;
 }
 
 
 /* Start ICE checks
  *
  * This is a thunk to vcmStartIceChecks_m
  *
  *  @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);
 
   return ret;
 }
 
 /* Set remote ICE media-level parameters.
  *
--- a/media/webrtc/signaling/src/sipcc/core/gsm/fsmdef.c
+++ b/media/webrtc/signaling/src/sipcc/core/gsm/fsmdef.c
@@ -2883,18 +2883,19 @@ fsmdef_ev_createoffer (sm_event_t *event
       /* Force clean up call without sending release */
       return (fsmdef_release(fcb, cause, FALSE));
     }
 
     if (dcb == NULL) {
       FSM_DEBUG_SM(DEB_F_PREFIX"dcb is NULL.\n", DEB_F_PREFIX_ARGS(FSM, __FUNCTION__));
       return SM_RC_CLEANUP;
     }
-
-   if (msg->data.session.has_constraints) {
+    dcb->inbound = FALSE;
+
+    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);
 
             if (0 > delhash(msg->data.session.sessionid)) {
                 FSM_DEBUG_SM (DEB_F_PREFIX"failed to delete hash sessid=0x%08x\n",
                 DEB_F_PREFIX_ARGS(SIP_CC_PROV, __FUNCTION__), msg->data.session.sessionid);
             }
@@ -2989,16 +2990,17 @@ fsmdef_ev_createanswer (sm_event_t *even
     if (!sdpmode) {
         return (fsmdef_release(fcb, cause, FALSE));
     }
 
     if (dcb == NULL) {
         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);
         if (sess_data_p) {
             gsmsdp_process_cap_constraints(dcb, sess_data_p->cc_constraints);
 
             if (0 > delhash(msg->data.session.sessionid)) {
                 FSM_DEBUG_SM (DEB_F_PREFIX"failed to delete hash sessid=0x%08x\n",
--- a/media/webrtc/signaling/src/sipcc/core/gsm/lsm.c
+++ b/media/webrtc/signaling/src/sipcc/core/gsm/lsm.c
@@ -3991,17 +3991,18 @@ lsm_connected (lsm_lcb_t *lcb, cc_state_
 
     if (!sdpmode) {
         if (tone_stop_bool == TRUE)
             (void) lsm_stop_tone(lcb, NULL);
     }
 
     /* 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;
     }
 
     /*
      * Open the RTP receive channel.
      */
--- a/media/webrtc/signaling/src/sipcc/include/vcm.h
+++ b/media/webrtc/signaling/src/sipcc/include/vcm.h
@@ -469,20 +469,20 @@ short vcmSetIceCandidate(const char *pee
  *  @param[in]  candidate_ct - the number of candidates
  *  @return 0 success, error failure
  */
 short vcmSetIceMediaParams(const char *peerconnection, int level, char *ufrag, char *pwd,
                       char **candidates, int candidate_ct);
 
 /* 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);
 
 
 
 /*
  * Create a remote stream
  *
  *  @param[in] mcap_id - group identifier to which stream belongs.
  *  @param[in]  peerconnection - the peerconnection in use