Bug 1024028 - Part 2: Add an ice_checking callback that is fired when checking actually starts. r=drno
authorByron Campen [:bwc] <docfaraday@gmail.com>
Wed, 06 Aug 2014 11:34:55 -0700
changeset 200712 12c48b15b3f5a56e0647e4248493c41e4333bf49
parent 200711 ecc417b9cba8cd214b3d339b69c1df97e725eeb7
child 200713 2954187fdb957e32e8dad122adfdfc3b43c9c125
push id47979
push userkwierso@gmail.com
push dateThu, 21 Aug 2014 01:01:52 +0000
treeherdermozilla-inbound@226406642515 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdrno
bugs1024028
milestone34.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 1024028 - Part 2: Add an ice_checking callback that is fired when checking actually starts. r=drno
media/mtransport/nricectx.cpp
media/mtransport/nricectx.h
media/mtransport/third_party/nICEr/src/ice/ice_handler.h
media/mtransport/third_party/nICEr/src/ice/ice_media_stream.c
media/mtransport/third_party/nICEr/src/ice/ice_peer_ctx.c
media/mtransport/third_party/nICEr/src/ice/ice_peer_ctx.h
--- a/media/mtransport/nricectx.cpp
+++ b/media/mtransport/nricectx.cpp
@@ -313,16 +313,27 @@ int NrIceCtx::stream_failed(void *obj, n
   // Streams which do not exist should never fail.
   MOZ_ASSERT(s);
 
   ctx->SetConnectionState(ICE_CTX_FAILED);
   s -> SignalFailed(s);
   return 0;
 }
 
+int NrIceCtx::ice_checking(void *obj, nr_ice_peer_ctx *pctx) {
+  MOZ_MTLOG(ML_DEBUG, "ice_checking called");
+
+  // Get the ICE ctx
+  NrIceCtx *ctx = static_cast<NrIceCtx *>(obj);
+
+  ctx->SetConnectionState(ICE_CTX_CHECKING);
+
+  return 0;
+}
+
 int NrIceCtx::ice_completed(void *obj, nr_ice_peer_ctx *pctx) {
   MOZ_MTLOG(ML_DEBUG, "ice_completed called");
 
   // Get the ICE ctx
   NrIceCtx *ctx = static_cast<NrIceCtx *>(obj);
 
   // This is called even on failed contexts.
   if (ctx->connection_state() != ICE_CTX_FAILED) {
@@ -462,16 +473,17 @@ RefPtr<NrIceCtx> NrIceCtx::Create(const 
 
   // Create the handler objects
   ctx->ice_handler_vtbl_ = new nr_ice_handler_vtbl();
   ctx->ice_handler_vtbl_->select_pair = &NrIceCtx::select_pair;
   ctx->ice_handler_vtbl_->stream_ready = &NrIceCtx::stream_ready;
   ctx->ice_handler_vtbl_->stream_failed = &NrIceCtx::stream_failed;
   ctx->ice_handler_vtbl_->ice_completed = &NrIceCtx::ice_completed;
   ctx->ice_handler_vtbl_->msg_recvd = &NrIceCtx::msg_recvd;
+  ctx->ice_handler_vtbl_->ice_checking = &NrIceCtx::ice_checking;
 
   ctx->ice_handler_ = new nr_ice_handler();
   ctx->ice_handler_->vtbl = ctx->ice_handler_vtbl_;
   ctx->ice_handler_->obj = ctx;
 
   // Create the peer ctx. Because we do not support parallel forking, we
   // only have one peer ctx.
   std::string peer_name = name + ":default";
@@ -684,18 +696,16 @@ nsresult NrIceCtx::StartChecks() {
       MOZ_MTLOG(ML_ERROR, "Couldn't start peer checks on "
                 << name_ << "' assuming trickle ICE");
     } else {
       MOZ_MTLOG(ML_ERROR, "Couldn't start peer checks on "
                 << name_ << "'");
       SetConnectionState(ICE_CTX_FAILED);
       return NS_ERROR_FAILURE;
     }
-  } else {
-    SetConnectionState(ICE_CTX_CHECKING);
   }
 
   return NS_OK;
 }
 
 
 void NrIceCtx::initialized_cb(NR_SOCKET s, int h, void *arg) {
   NrIceCtx *ctx = static_cast<NrIceCtx *>(arg);
--- a/media/mtransport/nricectx.h
+++ b/media/mtransport/nricectx.h
@@ -287,16 +287,17 @@ class NrIceCtx {
   static void initialized_cb(NR_SOCKET s, int h, void *arg);  // ICE initialized
 
   // Handler implementation
   static int select_pair(void *obj,nr_ice_media_stream *stream,
                          int component_id, nr_ice_cand_pair **potentials,
                          int potential_ct);
   static int stream_ready(void *obj, nr_ice_media_stream *stream);
   static int stream_failed(void *obj, nr_ice_media_stream *stream);
+  static int ice_checking(void *obj, nr_ice_peer_ctx *pctx);
   static int ice_completed(void *obj, nr_ice_peer_ctx *pctx);
   static int msg_recvd(void *obj, nr_ice_peer_ctx *pctx,
                        nr_ice_media_stream *stream, int component_id,
                        unsigned char *msg, int len);
   static void trickle_cb(void *arg, nr_ice_ctx *ctx, nr_ice_media_stream *stream,
                          int component_id, nr_ice_candidate *candidate);
 
   // Find a media stream by stream ptr. Gross
--- a/media/mtransport/third_party/nICEr/src/ice/ice_handler.h
+++ b/media/mtransport/third_party/nICEr/src/ice/ice_handler.h
@@ -61,16 +61,19 @@ int component_id, nr_ice_cand_pair **pot
 
   /* ICE is completed for this peer ctx
      if need_update is nonzero, a SIP update is required
    */
   int (*ice_completed)(void *obj, nr_ice_peer_ctx *pctx);
 
   /* A message was delivered to us */
   int (*msg_recvd)(void *obj, nr_ice_peer_ctx *pctx, nr_ice_media_stream *stream, int component_id, UCHAR *msg, int len);
+
+  /* ICE has started checking. */
+  int (*ice_checking)(void *obj, nr_ice_peer_ctx *pctx);
 } nr_ice_handler_vtbl;
 
 typedef struct nr_ice_handler_ {
   void *obj;
   nr_ice_handler_vtbl *vtbl;
 } nr_ice_handler;
 
 #ifdef __cplusplus
--- a/media/mtransport/third_party/nICEr/src/ice/ice_media_stream.c
+++ b/media/mtransport/third_party/nICEr/src/ice/ice_media_stream.c
@@ -405,16 +405,18 @@ int nr_ice_media_stream_start_checks(nr_
     if(r=nr_ice_media_stream_set_state(stream,NR_ICE_MEDIA_STREAM_CHECKS_ACTIVE))
       ABORT(r);
 
     if (!stream->timer) {
       r_log(LOG_ICE,LOG_INFO,"ICE-PEER(%s)/ICE-STREAM(%s): Starting check timer for stream.",pctx->label,stream->label);
       nr_ice_media_stream_check_timer_cb(0,0,stream);
     }
 
+    nr_ice_peer_ctx_stream_started_checks(pctx, stream);
+
     _status=0;
   abort:
     return(_status);
   }
 
 /* Start checks for this media stream (aka check list) S 5.7 */
 int nr_ice_media_stream_unfreeze_pairs(nr_ice_peer_ctx *pctx, nr_ice_media_stream *stream)
   {
--- a/media/mtransport/third_party/nICEr/src/ice/ice_peer_ctx.c
+++ b/media/mtransport/third_party/nICEr/src/ice/ice_peer_ctx.c
@@ -566,16 +566,27 @@ int nr_ice_peer_ctx_start_checks2(nr_ice
       ABORT(R_NOT_FOUND);
     }
 
     _status=0;
   abort:
     return(_status);
   }
 
+void nr_ice_peer_ctx_stream_started_checks(nr_ice_peer_ctx *pctx, nr_ice_media_stream *stream)
+  {
+    if (!pctx->checks_started) {
+      r_log(LOG_ICE,LOG_NOTICE,"ICE(%s): peer (%s) is now checking",pctx->ctx->label,pctx->label);
+      pctx->checks_started = 1;
+      if (pctx->handler && pctx->handler->vtbl->ice_checking) {
+        pctx->handler->vtbl->ice_checking(pctx->handler->obj, pctx);
+      }
+    }
+  }
+
 #ifndef NDEBUG
 int nr_ice_peer_ctx_dump_state(nr_ice_peer_ctx *pctx,FILE *out)
   {
     int r,_status;
     nr_ice_media_stream *stream;
 
     fprintf(out,"PEER %s STATE DUMP\n",pctx->label);
     fprintf(out,"==========================================\n");
--- a/media/mtransport/third_party/nICEr/src/ice/ice_peer_ctx.h
+++ b/media/mtransport/third_party/nICEr/src/ice/ice_peer_ctx.h
@@ -55,16 +55,17 @@ struct nr_ice_peer_ctx_ {
   char *peer_ufrag;
   char *peer_pwd;
   int peer_lite;
   int peer_ice_mismatch;
 
   nr_ice_media_stream_head peer_streams;
   int active_streams;
   int waiting_pairs;
+  UCHAR checks_started;
 
   void *done_cb_timer;
   UCHAR reported_done;
   void *trickle_grace_period_timer;
 
   STAILQ_ENTRY(nr_ice_peer_ctx_) entry;
 };
 
@@ -75,16 +76,17 @@ int nr_ice_peer_ctx_destroy(nr_ice_peer_
 int nr_ice_peer_ctx_parse_stream_attributes(nr_ice_peer_ctx *pctx, nr_ice_media_stream *stream, char **attrs, int attr_ct);
 int nr_ice_peer_ctx_find_pstream(nr_ice_peer_ctx *pctx, nr_ice_media_stream *stream, nr_ice_media_stream **pstreamp);
 int nr_ice_peer_ctx_parse_trickle_candidate(nr_ice_peer_ctx *pctx, nr_ice_media_stream *stream, char *cand);
 
 int nr_ice_peer_ctx_pair_candidates(nr_ice_peer_ctx *pctx);
 int nr_ice_peer_ctx_parse_global_attributes(nr_ice_peer_ctx *pctx, char **attrs, int attr_ct);
 int nr_ice_peer_ctx_start_checks(nr_ice_peer_ctx *pctx);
 int nr_ice_peer_ctx_start_checks2(nr_ice_peer_ctx *pctx, int allow_non_first);
+void nr_ice_peer_ctx_stream_started_checks(nr_ice_peer_ctx *pctx, nr_ice_media_stream *stream);
 int nr_ice_peer_ctx_dump_state(nr_ice_peer_ctx *pctx,FILE *out);
 int nr_ice_peer_ctx_log_state(nr_ice_peer_ctx *pctx);
 int nr_ice_peer_ctx_stream_done(nr_ice_peer_ctx *pctx, nr_ice_media_stream *stream);
 int nr_ice_peer_ctx_find_component(nr_ice_peer_ctx *pctx, nr_ice_media_stream *str, int component_id, nr_ice_component **compp);
 int nr_ice_peer_ctx_deliver_packet_maybe(nr_ice_peer_ctx *pctx, nr_ice_component *comp, nr_transport_addr *source_addr, UCHAR *data, int len);
 int nr_ice_peer_ctx_disable_component(nr_ice_peer_ctx *pctx, nr_ice_media_stream *lstream, int component_id);
 int nr_ice_peer_ctx_pair_new_trickle_candidate(nr_ice_ctx *ctx, nr_ice_peer_ctx *pctx, nr_ice_candidate *cand);
 void nr_ice_peer_ctx_switch_controlling_role(nr_ice_peer_ctx *pctx);