Bug 1535442 - Part 3: Fire per-transport end-of-candidates signals, with ufrag. r=mjf
authorByron Campen [:bwc] <docfaraday@gmail.com>
Wed, 27 Mar 2019 21:54:16 +0000
changeset 525500 37a419113a397ea893466e1d4b2df2bd6ee68c0e
parent 525499 2ac346fc1029f4d129387648df85ab1b8380cc58
child 525501 3322742f14d540cf554cd98aa28afb10fc0caf9d
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmjf
bugs1535442
milestone68.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 1535442 - Part 3: Fire per-transport end-of-candidates signals, with ufrag. r=mjf Differential Revision: https://phabricator.services.mozilla.com/D24277
media/mtransport/nricectx.cpp
media/mtransport/third_party/nICEr/src/ice/ice_component.c
media/mtransport/third_party/nICEr/src/ice/ice_component.h
media/mtransport/third_party/nICEr/src/ice/ice_ctx.c
media/mtransport/third_party/nICEr/src/ice/ice_media_stream.c
media/mtransport/third_party/nICEr/src/ice/ice_media_stream.h
--- a/media/mtransport/nricectx.cpp
+++ b/media/mtransport/nricectx.cpp
@@ -422,16 +422,21 @@ void NrIceCtx::trickle_cb(void *arg, nr_
   NrIceCtx *ctx = static_cast<NrIceCtx *>(arg);
   RefPtr<NrIceMediaStream> s = ctx->FindStream(stream);
 
   if (!s) {
     // This stream has been removed because it is inactive
     return;
   }
 
+  if (!candidate) {
+    s->SignalCandidate(s, "", stream->ufrag);
+    return;
+  }
+
   // Format the candidate.
   char candidate_str[NR_ICE_MAX_ATTRIBUTE_SIZE];
   int r = nr_ice_format_candidate_attribute(candidate, candidate_str,
                                             sizeof(candidate_str));
   MOZ_ASSERT(!r);
   if (r) return;
 
   MOZ_MTLOG(ML_INFO, "NrIceCtx(" << ctx->name_ << "): trickling candidate "
--- a/media/mtransport/third_party/nICEr/src/ice/ice_component.c
+++ b/media/mtransport/third_party/nICEr/src/ice/ice_component.c
@@ -702,16 +702,30 @@ int nr_ice_component_initialize(struct n
 void nr_ice_component_stop_gathering(nr_ice_component *component)
   {
     nr_ice_candidate *c1,*c2;
     TAILQ_FOREACH_SAFE(c1, &component->candidates, entry_comp, c2){
       nr_ice_candidate_stop_gathering(c1);
     }
   }
 
+int nr_ice_component_is_done_gathering(nr_ice_component *comp)
+  {
+    nr_ice_candidate *cand=TAILQ_FIRST(&comp->candidates);
+    while(cand){
+      if(cand->state != NR_ICE_CAND_STATE_INITIALIZED &&
+         cand->state != NR_ICE_CAND_STATE_FAILED){
+        return 0;
+      }
+      cand=TAILQ_NEXT(cand,entry_comp);
+    }
+    return 1;
+  }
+
+
 static int nr_ice_any_peer_paired(nr_ice_candidate* cand) {
   nr_ice_peer_ctx* pctx=STAILQ_FIRST(&cand->ctx->peers);
   while(pctx && pctx->state == NR_ICE_PEER_STATE_UNPAIRED){
     /* Is it worth actually looking through the check lists? Probably not. */
     pctx=STAILQ_NEXT(pctx,entry);
   }
   return pctx != NULL;
 }
--- a/media/mtransport/third_party/nICEr/src/ice/ice_component.h
+++ b/media/mtransport/third_party/nICEr/src/ice/ice_component.h
@@ -82,16 +82,17 @@ struct nr_ice_component_ {
 };
 
 typedef STAILQ_HEAD(nr_ice_component_head_,nr_ice_component_) nr_ice_component_head;
 
 int nr_ice_component_create(struct nr_ice_media_stream_ *stream, int component_id, nr_ice_component **componentp);
 int nr_ice_component_destroy(nr_ice_component **componentp);
 int nr_ice_component_initialize(struct nr_ice_ctx_ *ctx,nr_ice_component *component);
 void nr_ice_component_stop_gathering(nr_ice_component *component);
+int nr_ice_component_is_done_gathering(nr_ice_component *comp);
 int nr_ice_component_maybe_prune_candidate(nr_ice_ctx *ctx, nr_ice_component *comp, nr_ice_candidate *c1, int *was_pruned);
 int nr_ice_component_pair_candidate(nr_ice_peer_ctx *pctx, nr_ice_component *pcomp, nr_ice_candidate *lcand, int pair_all_remote);
 int nr_ice_component_pair_candidates(nr_ice_peer_ctx *pctx, nr_ice_component *lcomp, nr_ice_component *pcomp);
 int nr_ice_component_service_pre_answer_requests(nr_ice_peer_ctx *pctx, nr_ice_component *pcomp, char *username, int *serviced);
 int nr_ice_component_nominated_pair(nr_ice_component *comp, nr_ice_cand_pair *pair);
 void nr_ice_component_failed_pair(nr_ice_component *comp, nr_ice_cand_pair *pair);
 void nr_ice_component_check_if_failed(nr_ice_component *comp);
 int nr_ice_component_select_pair(nr_ice_peer_ctx *pctx, nr_ice_component *comp);
--- a/media/mtransport/third_party/nICEr/src/ice/ice_ctx.c
+++ b/media/mtransport/third_party/nICEr/src/ice/ice_ctx.c
@@ -506,22 +506,26 @@ int nr_ice_ctx_destroy(nr_ice_ctx **ctxp
     return(0);
   }
 
 void nr_ice_gather_finished_cb(NR_SOCKET s, int h, void *cb_arg)
   {
     int r;
     nr_ice_candidate *cand=cb_arg;
     nr_ice_ctx *ctx;
+    nr_ice_media_stream *stream;
+    int component_id;
 
 
     assert(cb_arg);
     if (!cb_arg)
       return;
     ctx = cand->ctx;
+    stream = cand->stream;
+    component_id = cand->component_id;
 
     ctx->uninitialized_candidates--;
     if (cand->state == NR_ICE_CAND_STATE_FAILED) {
       r_log(LOG_ICE, LOG_WARNING,
             "ICE(%s)/CAND(%s): failed to initialize, %d remaining", ctx->label,
             cand->label, ctx->uninitialized_candidates);
     } else {
       r_log(LOG_ICE, LOG_DEBUG, "ICE(%s)/CAND(%s): initialized, %d remaining",
@@ -535,27 +539,36 @@ void nr_ice_gather_finished_cb(NR_SOCKET
     if (cand->state == NR_ICE_CAND_STATE_INITIALIZED) {
       int was_pruned = 0;
 
       if (r=nr_ice_component_maybe_prune_candidate(ctx, cand->component,
                                                    cand, &was_pruned)) {
           r_log(LOG_ICE, LOG_NOTICE, "ICE(%s): Problem pruning candidates",ctx->label);
       }
 
+      if (was_pruned) {
+        cand = NULL;
+      }
+
       /* If we are initialized, the candidate wasn't pruned,
          and we have a trickle ICE callback fire the callback */
-      if (ctx->trickle_cb && !was_pruned &&
+      if (ctx->trickle_cb && cand &&
           !nr_ice_ctx_hide_candidate(ctx, cand)) {
         ctx->trickle_cb(ctx->trickle_cb_arg, ctx, cand->stream, cand->component_id, cand);
 
         if (nr_ice_ctx_pair_new_trickle_candidates(ctx, cand)) {
           r_log(LOG_ICE,LOG_ERR, "ICE(%s): All could not pair new trickle candidate",ctx->label);
           /* But continue */
         }
       }
+
+      if (nr_ice_media_stream_is_done_gathering(stream) &&
+          ctx->trickle_cb) {
+        ctx->trickle_cb(ctx->trickle_cb_arg, ctx, stream, component_id, NULL);
+      }
     }
 
     if(ctx->uninitialized_candidates==0){
       r_log(LOG_ICE, LOG_INFO, "ICE(%s): All candidates initialized",
             ctx->label);
       if (ctx->done_cb) {
         ctx->done_cb(0,0,ctx->cb_arg);
       }
--- a/media/mtransport/third_party/nICEr/src/ice/ice_media_stream.c
+++ b/media/mtransport/third_party/nICEr/src/ice/ice_media_stream.c
@@ -651,16 +651,29 @@ void nr_ice_media_stream_set_obsolete(nr
 
     STAILQ_FOREACH_SAFE(c1, &str->components, entry, c2){
       nr_ice_component_stop_gathering(c1);
     }
 
     nr_ice_media_stream_stop_checking(str);
   }
 
+int nr_ice_media_stream_is_done_gathering(nr_ice_media_stream *str)
+  {
+    nr_ice_component *comp;
+    comp=STAILQ_FIRST(&str->components);
+    while(comp){
+      if(!nr_ice_component_is_done_gathering(comp)) {
+        return 0;
+      }
+      comp=STAILQ_NEXT(comp,entry);
+    }
+    return 1;
+  }
+
 void nr_ice_media_stream_refresh_consent_all(nr_ice_media_stream *stream)
   {
     nr_ice_component *comp;
 
     comp=STAILQ_FIRST(&stream->components);
     while(comp){
       if(comp->disconnected) {
         nr_ice_component_refresh_consent_now(comp);
--- a/media/mtransport/third_party/nICEr/src/ice/ice_media_stream.h
+++ b/media/mtransport/third_party/nICEr/src/ice/ice_media_stream.h
@@ -98,16 +98,17 @@ void nr_ice_media_stream_component_nomin
 void nr_ice_media_stream_component_failed(nr_ice_media_stream *stream,nr_ice_component *component);
 void nr_ice_media_stream_refresh_consent_all(nr_ice_media_stream *stream);
 void nr_ice_media_stream_disconnect_all_components(nr_ice_media_stream *stream);
 void nr_ice_media_stream_set_disconnected(nr_ice_media_stream *stream, int disconnected);
 int nr_ice_media_stream_check_if_connected(nr_ice_media_stream *stream);
 int nr_ice_media_stream_set_state(nr_ice_media_stream *str, int state);
 void nr_ice_media_stream_stop_checking(nr_ice_media_stream *str);
 void nr_ice_media_stream_set_obsolete(nr_ice_media_stream *str);
+int nr_ice_media_stream_is_done_gathering(nr_ice_media_stream *str);
 int nr_ice_media_stream_get_best_candidate(nr_ice_media_stream *str, int component, nr_ice_candidate **candp);
 int nr_ice_media_stream_send(nr_ice_peer_ctx *pctx, nr_ice_media_stream *str, int component, UCHAR *data, int len);
 int nr_ice_media_stream_get_active(nr_ice_peer_ctx *pctx, nr_ice_media_stream *str, int component, nr_ice_candidate **local, nr_ice_candidate **remote);
 int nr_ice_media_stream_find_component(nr_ice_media_stream *str, int comp_id, nr_ice_component **compp);
 int nr_ice_media_stream_find_pair(nr_ice_media_stream *str, nr_ice_candidate *local, nr_ice_candidate *remote, nr_ice_cand_pair **pair);
 int nr_ice_media_stream_addrs(nr_ice_peer_ctx *pctx, nr_ice_media_stream *str, int component, nr_transport_addr *local, nr_transport_addr *remote);
 int
 nr_ice_peer_ctx_parse_media_stream_attribute(nr_ice_peer_ctx *pctx, nr_ice_media_stream *stream, char *attr);