Skip to content

Commit f994f7c

Browse files
authored
Close nice agent resources asynchronously (#2492)
1 parent 79038e0 commit f994f7c

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

configure.ac

+6
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,12 @@ AC_CHECK_LIB([nice],
395395
[AC_MSG_NOTICE([libnice version does not support TCP candidates])]
396396
)
397397

398+
AC_CHECK_LIB([nice],
399+
[nice_agent_close_async],
400+
[AC_DEFINE(HAVE_CLOSE_ASYNC)],
401+
[AC_MSG_NOTICE([libnice version does not have nice_agent_close_async])]
402+
)
403+
398404
AC_CHECK_LIB([dl],
399405
[dlopen],
400406
[JANUS_MANUAL_LIBS="${JANUS_MANUAL_LIBS} -ldl"],

ice.c

+26
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,19 @@ static void janus_ice_handle_free(const janus_refcount *handle_ref) {
13771377
g_free(handle);
13781378
}
13791379

1380+
#ifdef HAVE_CLOSE_ASYNC
1381+
static void janus_ice_cb_agent_closed(GObject *src, GAsyncResult *result, gpointer data) {
1382+
janus_ice_outgoing_traffic *t = (janus_ice_outgoing_traffic *)data;
1383+
janus_ice_handle *handle = t->handle;
1384+
1385+
JANUS_LOG(LOG_VERB, "[%"SCNu64"] Disposing nice agent %p\n", handle->handle_id, handle->agent);
1386+
g_object_unref(handle->agent);
1387+
handle->agent = NULL;
1388+
g_source_unref((GSource *)t);
1389+
janus_refcount_decrease(&handle->ref);
1390+
}
1391+
#endif
1392+
13801393
static void janus_ice_plugin_session_free(const janus_refcount *app_handle_ref) {
13811394
janus_plugin_session *app_handle = janus_refcount_containerof(app_handle_ref, janus_plugin_session, ref);
13821395
/* This app handle can be destroyed, free all the resources */
@@ -1436,9 +1449,22 @@ static void janus_ice_webrtc_free(janus_ice_handle *handle) {
14361449
handle->stream = NULL;
14371450
}
14381451
if(handle->agent != NULL) {
1452+
#ifdef HAVE_CLOSE_ASYNC
1453+
if(G_IS_OBJECT(handle->agent)) {
1454+
JANUS_LOG(LOG_VERB, "[%"SCNu64"] Removing stream %d from agent %p\n",
1455+
handle->handle_id, handle->stream_id, handle->agent);
1456+
nice_agent_remove_stream(handle->agent, handle->stream_id);
1457+
handle->stream_id = 0;
1458+
JANUS_LOG(LOG_VERB, "[%"SCNu64"] Closing nice agent %p\n", handle->handle_id, handle->agent);
1459+
janus_refcount_increase(&handle->ref);
1460+
g_source_ref(handle->rtp_source);
1461+
nice_agent_close_async(handle->agent, janus_ice_cb_agent_closed, handle->rtp_source);
1462+
}
1463+
#else
14391464
if(G_IS_OBJECT(handle->agent))
14401465
g_object_unref(handle->agent);
14411466
handle->agent = NULL;
1467+
#endif
14421468
}
14431469
if(handle->pending_trickles) {
14441470
while(handle->pending_trickles) {

0 commit comments

Comments
 (0)