[Pkg-voip-commits] [janus] 107/282: Improve iceloop lifecycle management.
Jonas Smedegaard
dr at jones.dk
Wed Dec 20 21:53:32 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag debian/0.2.6-1
in repository janus.
commit f98498e6844061f48f5a39f8b8905f45d9f7b1fa
Author: Alessandro Toppi <atoppi at meetecho.com>
Date: Wed Sep 13 16:59:50 2017 +0200
Improve iceloop lifecycle management.
---
ice.c | 40 +++++++++++++++++++++++-----------------
1 file changed, 23 insertions(+), 17 deletions(-)
diff --git a/ice.c b/ice.c
index 7942e94..a6802f1 100644
--- a/ice.c
+++ b/ice.c
@@ -1074,7 +1074,7 @@ gint janus_ice_handle_destroy(void *gateway_session, guint64 handle_id) {
/* There was no plugin attached, probably something went wrong there */
janus_flags_set(&handle->webrtc_flags, JANUS_ICE_HANDLE_WEBRTC_ALERT);
janus_flags_set(&handle->webrtc_flags, JANUS_ICE_HANDLE_WEBRTC_STOP);
- if(handle->iceloop != NULL && g_main_loop_is_running(handle->iceloop)) {
+ if(handle->iceloop != NULL) {
if(handle->audio_id > 0) {
nice_agent_attach_recv(handle->agent, handle->audio_id, 1, g_main_loop_get_context (handle->iceloop), NULL, NULL);
if(!janus_flags_is_set(&handle->webrtc_flags, JANUS_ICE_HANDLE_WEBRTC_RTCPMUX))
@@ -1088,7 +1088,9 @@ gint janus_ice_handle_destroy(void *gateway_session, guint64 handle_id) {
if(handle->data_id > 0) {
nice_agent_attach_recv(handle->agent, handle->data_id, 1, g_main_loop_get_context (handle->iceloop), NULL, NULL);
}
- g_main_loop_quit(handle->iceloop);
+ if(g_main_loop_is_running(handle->iceloop)) {
+ g_main_loop_quit(handle->iceloop);
+ }
}
return 0;
}
@@ -1110,7 +1112,7 @@ gint janus_ice_handle_destroy(void *gateway_session, guint64 handle_id) {
}
janus_flags_set(&handle->webrtc_flags, JANUS_ICE_HANDLE_WEBRTC_ALERT);
janus_flags_set(&handle->webrtc_flags, JANUS_ICE_HANDLE_WEBRTC_STOP);
- if(handle->iceloop != NULL && g_main_loop_is_running(handle->iceloop)) {
+ if(handle->iceloop != NULL) {
if(handle->audio_id > 0) {
nice_agent_attach_recv(handle->agent, handle->audio_id, 1, g_main_loop_get_context (handle->iceloop), NULL, NULL);
if(!janus_flags_is_set(&handle->webrtc_flags, JANUS_ICE_HANDLE_WEBRTC_RTCPMUX))
@@ -1124,7 +1126,9 @@ gint janus_ice_handle_destroy(void *gateway_session, guint64 handle_id) {
if(handle->data_id > 0) {
nice_agent_attach_recv(handle->agent, handle->data_id, 1, g_main_loop_get_context (handle->iceloop), NULL, NULL);
}
- g_main_loop_quit(handle->iceloop);
+ if(g_main_loop_is_running(handle->iceloop)) {
+ g_main_loop_quit(handle->iceloop);
+ }
}
/* Prepare JSON event to notify user/application */
@@ -1200,7 +1204,7 @@ void janus_ice_webrtc_hangup(janus_ice_handle *handle, const char *reason) {
g_async_queue_push(handle->queued_packets, &janus_ice_dtls_alert);
if(handle->send_thread == NULL) {
/* Get rid of the loop */
- if(handle->iceloop != NULL && g_main_loop_is_running(handle->iceloop)) {
+ if(handle->iceloop != NULL) {
if(handle->audio_id > 0) {
nice_agent_attach_recv(handle->agent, handle->audio_id, 1, g_main_loop_get_context (handle->iceloop), NULL, NULL);
if(!janus_flags_is_set(&handle->webrtc_flags, JANUS_ICE_HANDLE_WEBRTC_RTCPMUX))
@@ -1224,7 +1228,7 @@ void janus_ice_webrtc_hangup(janus_ice_handle *handle, const char *reason) {
break;
}
}
- if(handle->iceloop != NULL && g_main_loop_is_running(handle->iceloop)) {
+ if(g_main_loop_is_running(handle->iceloop)) {
JANUS_LOG(LOG_VERB, "[%"SCNu64"] Forcing ICE loop to quit (%s)\n", handle->handle_id, g_main_loop_is_running(handle->iceloop) ? "running" : "NOT running");
g_main_loop_quit(handle->iceloop);
g_main_context_wakeup(handle->icectx);
@@ -1240,6 +1244,9 @@ void janus_ice_webrtc_free(janus_ice_handle *handle) {
janus_mutex_lock(&handle->mutex);
janus_flags_clear(&handle->webrtc_flags, JANUS_ICE_HANDLE_WEBRTC_READY);
if(handle->iceloop != NULL) {
+ if(g_main_loop_is_running(handle->iceloop)) {
+ g_main_loop_quit(handle->iceloop);
+ }
g_main_loop_unref (handle->iceloop);
handle->iceloop = NULL;
}
@@ -2414,7 +2421,6 @@ void *janus_ice_thread(void *data) {
g_thread_unref(g_thread_self());
return NULL;
}
- g_usleep (100000);
JANUS_LOG(LOG_DBG, "[%"SCNu64"] Looping (ICE)...\n", handle->handle_id);
g_main_loop_run (loop);
janus_flags_set(&handle->webrtc_flags, JANUS_ICE_HANDLE_WEBRTC_CLEANING);
@@ -2804,16 +2810,6 @@ int janus_ice_setup_local(janus_ice_handle *handle, int offer, int audio, int vi
handle->icectx = g_main_context_new();
handle->iceloop = g_main_loop_new(handle->icectx, FALSE);
- GError *error = NULL;
- char tname[16];
- g_snprintf(tname, sizeof(tname), "iceloop %"SCNu64, handle->handle_id);
- handle->icethread = g_thread_try_new(tname, &janus_ice_thread, handle, &error);
- if(error != NULL) {
- /* FIXME We should clear some resources... */
- JANUS_LOG(LOG_ERR, "[%"SCNu64"] Got error %d (%s) trying to launch the ICE thread...\n", handle->handle_id, error->code, error->message ? error->message : "??");
- janus_flags_clear(&handle->webrtc_flags, JANUS_ICE_HANDLE_WEBRTC_HAS_AGENT);
- return -1;
- }
/* Note: NICE_COMPATIBILITY_RFC5245 is only available in more recent versions of libnice */
handle->controlling = janus_ice_lite_enabled ? FALSE : !offer;
JANUS_LOG(LOG_INFO, "[%"SCNu64"] Creating ICE agent (ICE %s mode, %s)\n", handle->handle_id,
@@ -3363,6 +3359,16 @@ int janus_ice_setup_local(janus_ice_handle *handle, int offer, int audio, int vi
turnrest_credentials = NULL;
}
#endif
+ GError *error = NULL;
+ char tname[16];
+ g_snprintf(tname, sizeof(tname), "iceloop %"SCNu64, handle->handle_id);
+ handle->icethread = g_thread_try_new(tname, &janus_ice_thread, handle, &error);
+ if(error != NULL) {
+ /* FIXME We should clear some resources... */
+ JANUS_LOG(LOG_ERR, "[%"SCNu64"] Got error %d (%s) trying to launch the ICE thread...\n", handle->handle_id, error->code, error->message ? error->message : "??");
+ janus_flags_clear(&handle->webrtc_flags, JANUS_ICE_HANDLE_WEBRTC_HAS_AGENT);
+ return -1;
+ }
return 0;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-voip/janus.git
More information about the Pkg-voip-commits
mailing list