Skip to content

Commit

Permalink
Close nice agent resources asynchronously (meetecho#2492)
Browse files Browse the repository at this point in the history
  • Loading branch information
fbellet committed Jan 20, 2021
1 parent 79038e0 commit f994f7c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,12 @@ AC_CHECK_LIB([nice],
[AC_MSG_NOTICE([libnice version does not support TCP candidates])]
)

AC_CHECK_LIB([nice],
[nice_agent_close_async],
[AC_DEFINE(HAVE_CLOSE_ASYNC)],
[AC_MSG_NOTICE([libnice version does not have nice_agent_close_async])]
)

AC_CHECK_LIB([dl],
[dlopen],
[JANUS_MANUAL_LIBS="${JANUS_MANUAL_LIBS} -ldl"],
Expand Down
26 changes: 26 additions & 0 deletions ice.c
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,19 @@ static void janus_ice_handle_free(const janus_refcount *handle_ref) {
g_free(handle);
}

#ifdef HAVE_CLOSE_ASYNC
static void janus_ice_cb_agent_closed(GObject *src, GAsyncResult *result, gpointer data) {
janus_ice_outgoing_traffic *t = (janus_ice_outgoing_traffic *)data;
janus_ice_handle *handle = t->handle;

JANUS_LOG(LOG_VERB, "[%"SCNu64"] Disposing nice agent %p\n", handle->handle_id, handle->agent);
g_object_unref(handle->agent);
handle->agent = NULL;
g_source_unref((GSource *)t);
janus_refcount_decrease(&handle->ref);
}
#endif

static void janus_ice_plugin_session_free(const janus_refcount *app_handle_ref) {
janus_plugin_session *app_handle = janus_refcount_containerof(app_handle_ref, janus_plugin_session, ref);
/* This app handle can be destroyed, free all the resources */
Expand Down Expand Up @@ -1436,9 +1449,22 @@ static void janus_ice_webrtc_free(janus_ice_handle *handle) {
handle->stream = NULL;
}
if(handle->agent != NULL) {
#ifdef HAVE_CLOSE_ASYNC
if(G_IS_OBJECT(handle->agent)) {
JANUS_LOG(LOG_VERB, "[%"SCNu64"] Removing stream %d from agent %p\n",
handle->handle_id, handle->stream_id, handle->agent);
nice_agent_remove_stream(handle->agent, handle->stream_id);
handle->stream_id = 0;
JANUS_LOG(LOG_VERB, "[%"SCNu64"] Closing nice agent %p\n", handle->handle_id, handle->agent);
janus_refcount_increase(&handle->ref);
g_source_ref(handle->rtp_source);
nice_agent_close_async(handle->agent, janus_ice_cb_agent_closed, handle->rtp_source);
}
#else
if(G_IS_OBJECT(handle->agent))
g_object_unref(handle->agent);
handle->agent = NULL;
#endif
}
if(handle->pending_trickles) {
while(handle->pending_trickles) {
Expand Down

0 comments on commit f994f7c

Please sign in to comment.