[Pkg-voip-commits] [janus] 261/282: Make close_pc and end_session calls truly asynchronous (see #1109)

Jonas Smedegaard dr at jones.dk
Wed Dec 20 21:53:47 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 86fdddf80c1e61e5f93d87f5cf7fc3de17772ee9
Author: Lorenzo Miniero <lminiero at gmail.com>
Date:   Fri Dec 15 13:31:29 2017 +0100

    Make close_pc and end_session calls truly asynchronous (see #1109)
---
 janus.c                   | 44 +++++++++++++++++++++++++++++++++-----------
 plugins/janus_videoroom.c | 33 ++++++++++++++++++++++++++-------
 2 files changed, 59 insertions(+), 18 deletions(-)

diff --git a/janus.c b/janus.c
index 724b179..5de85dd 100644
--- a/janus.c
+++ b/janus.c
@@ -3203,40 +3203,62 @@ void janus_plugin_relay_data(janus_plugin_session *plugin_session, char *buf, in
 #endif
 }
 
-void janus_plugin_close_pc(janus_plugin_session *plugin_session) {
-	/* A plugin asked to get rid of a PeerConnection */
+static gboolean janus_plugin_close_pc_internal(gpointer user_data) {
+	/* We actually enforce the close_pc here */
+	janus_plugin_session *plugin_session = (janus_plugin_session *) user_data;
 	if((plugin_session < (janus_plugin_session *)0x1000) || !janus_plugin_session_is_alive(plugin_session) || plugin_session->stopped)
-		return;
+		return G_SOURCE_REMOVE;
 	janus_ice_handle *ice_handle = (janus_ice_handle *)plugin_session->gateway_handle;
 	if(!ice_handle)
-		return;
+		return G_SOURCE_REMOVE;
 	if(janus_flags_is_set(&ice_handle->webrtc_flags, JANUS_ICE_HANDLE_WEBRTC_STOP)
 			|| janus_flags_is_set(&ice_handle->webrtc_flags, JANUS_ICE_HANDLE_WEBRTC_ALERT))
-		return;
+		return G_SOURCE_REMOVE;
 	janus_session *session = (janus_session *)ice_handle->session;
 	if(!session)
-		return;
+		return G_SOURCE_REMOVE;
 
 	JANUS_LOG(LOG_VERB, "[%"SCNu64"] Plugin asked to hangup PeerConnection: sending alert\n", ice_handle->handle_id);
 	/* Send an alert on all the DTLS connections */
 	janus_ice_webrtc_hangup(ice_handle, "Close PC");
+
+	return G_SOURCE_REMOVE;
 }
 
-void janus_plugin_end_session(janus_plugin_session *plugin_session) {
-	/* A plugin asked to get rid of a handle */
+void janus_plugin_close_pc(janus_plugin_session *plugin_session) {
+	/* A plugin asked to get rid of a PeerConnection: enqueue it as a timed source */
+	GSource *timeout_source = g_timeout_source_new_seconds(0);
+	g_source_set_callback(timeout_source, janus_plugin_close_pc_internal, plugin_session, NULL);
+	g_source_attach(timeout_source, sessions_watchdog_context);
+	g_source_unref(timeout_source);
+}
+
+static gboolean janus_plugin_end_session_internal(gpointer user_data) {
+	/* We actually enforce the end_session here */
+	janus_plugin_session *plugin_session = (janus_plugin_session *) user_data;
 	if((plugin_session < (janus_plugin_session *)0x1000) || !janus_plugin_session_is_alive(plugin_session) || plugin_session->stopped)
-		return;
+		return G_SOURCE_REMOVE;
 	janus_ice_handle *ice_handle = (janus_ice_handle *)plugin_session->gateway_handle;
 	if(!ice_handle)
-		return;
+		return G_SOURCE_REMOVE;
 	janus_session *session = (janus_session *)ice_handle->session;
 	if(!session)
-		return;
+		return G_SOURCE_REMOVE;
 	/* Destroy the handle */
 	janus_mutex_lock(&session->mutex);
 	janus_ice_handle_destroy(session, ice_handle->handle_id);
 	g_hash_table_remove(session->ice_handles, &ice_handle->handle_id);
 	janus_mutex_unlock(&session->mutex);
+
+	return G_SOURCE_REMOVE;
+}
+
+void janus_plugin_end_session(janus_plugin_session *plugin_session) {
+	/* A plugin asked to get rid of a handle: enqueue it as a timed source */
+	GSource *timeout_source = g_timeout_source_new_seconds(0);
+	g_source_set_callback(timeout_source, janus_plugin_end_session_internal, plugin_session, NULL);
+	g_source_attach(timeout_source, sessions_watchdog_context);
+	g_source_unref(timeout_source);
 }
 
 void janus_plugin_notify_event(janus_plugin *plugin, janus_plugin_session *plugin_session, json_t *event) {
diff --git a/plugins/janus_videoroom.c b/plugins/janus_videoroom.c
index 85cbf34..8ad0011 100644
--- a/plugins/janus_videoroom.c
+++ b/plugins/janus_videoroom.c
@@ -1231,7 +1231,7 @@ static void janus_videoroom_notify_participants(janus_videoroom_participant *par
 	GHashTableIter iter;
 	gpointer value;
 	g_hash_table_iter_init(&iter, participant->room->participants);
-	while (!participant->room->destroyed && g_hash_table_iter_next(&iter, NULL, &value)) {
+	while (participant->room && !participant->room->destroyed && g_hash_table_iter_next(&iter, NULL, &value)) {
 		janus_videoroom_participant *p = value;
 		if(p && p->session && p != participant) {
 			JANUS_LOG(LOG_VERB, "Notifying participant %"SCNu64" (%s)\n", p->user_id, p->display ? p->display : "??");
@@ -1352,7 +1352,7 @@ json_t *janus_videoroom_query_session(janus_plugin_session *handle) {
 		} else if(session->participant_type == janus_videoroom_p_type_publisher) {
 			json_object_set_new(info, "type", json_string("publisher"));
 			janus_videoroom_participant *participant = (janus_videoroom_participant *)session->participant;
-			if(participant) {
+			if(participant && participant->room) {
 				janus_videoroom *room = participant->room; 
 				json_object_set_new(info, "room", room ? json_integer(room->room_id) : NULL);
 				json_object_set_new(info, "id", json_integer(participant->user_id));
@@ -1391,9 +1391,9 @@ json_t *janus_videoroom_query_session(janus_plugin_session *handle) {
 		} else if(session->participant_type == janus_videoroom_p_type_subscriber) {
 			json_object_set_new(info, "type", json_string("listener"));
 			janus_videoroom_listener *participant = (janus_videoroom_listener *)session->participant;
-			if(participant) {
+			if(participant && participant->room) {
 				janus_videoroom_participant *feed = (janus_videoroom_participant *)participant->feed;
-				if(feed) {
+				if(feed && feed->room) {
 					janus_videoroom *room = feed->room; 
 					json_object_set_new(info, "room", room ? json_integer(room->room_id) : NULL);
 					json_object_set_new(info, "private_id", json_integer(participant->pvt_id));
@@ -2114,11 +2114,12 @@ struct janus_plugin_result *janus_videoroom_handle_message(janus_plugin_session
 		while (g_hash_table_iter_next(&iter, NULL, &value)) {
 			janus_videoroom_participant *p = value;
 			if(p && p->session) {
+				p->room = NULL;
 				/* Notify the user we're going to destroy the room... */
 				int ret = gateway->push_event(p->session->handle, &janus_videoroom_plugin, NULL, destroyed, NULL);
 				JANUS_LOG(LOG_VERB, "  >> %d (%s)\n", ret, janus_get_api_error(ret));
-				/* ... and then ask the core to remove the handle */
-				gateway->end_session(p->session->handle);
+				/* ... and then ask the core to close the PeerConnection */
+				gateway->close_pc(p->session->handle);
 			}
 		}
 		json_decref(destroyed);
@@ -2891,7 +2892,7 @@ void janus_videoroom_incoming_rtp(janus_plugin_session *handle, int video, char
 	janus_videoroom_participant *participant = (janus_videoroom_participant *)session->participant;
 	janus_videoroom *videoroom = participant->room;
 
-	if(participant->kicked)
+	if(participant->kicked || videoroom == NULL)
 		return;
 	/* In case this is an audio packet and we're doing talk detection, check the audio level extension */
 	if(!video && videoroom->audiolevel_event && participant->audio_active) {
@@ -3348,6 +3349,9 @@ static void janus_videoroom_hangup_media_internal(janus_plugin_session *handle)
 			if(l) {
 				participant->listeners = g_slist_remove(participant->listeners, l);
 				l->feed = NULL;
+				l->room = NULL;
+				if(l->session)
+					gateway->close_pc(l->session->handle);
 			}
 		}
 		janus_mutex_unlock(&participant->listeners_mutex);
@@ -3808,6 +3812,12 @@ static void *janus_videoroom_handler(void *data) {
 				g_snprintf(error_cause, 512, "Invalid participant instance");
 				goto error;
 			}
+			if(participant->room == NULL) {
+				JANUS_LOG(LOG_ERR, "No such room\n");
+				error_code = JANUS_VIDEOROOM_ERROR_NO_SUCH_ROOM;
+				g_snprintf(error_cause, 512, "No such room");
+				goto error;
+			}
 			if(!strcasecmp(request_text, "join") || !strcasecmp(request_text, "joinandconfigure")) {
 				JANUS_LOG(LOG_ERR, "Already in as a publisher on this handle\n");
 				error_code = JANUS_VIDEOROOM_ERROR_ALREADY_JOINED;
@@ -4051,6 +4061,12 @@ static void *janus_videoroom_handler(void *data) {
 				g_snprintf(error_cause, 512, "Invalid listener instance");
 				goto error;
 			}
+			if(listener->room == NULL) {
+				JANUS_LOG(LOG_ERR, "No such room\n");
+				error_code = JANUS_VIDEOROOM_ERROR_NO_SUCH_ROOM;
+				g_snprintf(error_cause, 512, "No such room");
+				goto error;
+			}
 			if(!strcasecmp(request_text, "join")) {
 				JANUS_LOG(LOG_ERR, "Already in as a listener on this handle\n");
 				error_code = JANUS_VIDEOROOM_ERROR_ALREADY_JOINED;
@@ -5049,6 +5065,9 @@ static void janus_videoroom_participant_free(janus_videoroom_participant *p) {
 		if(l) {
 			p->listeners = g_slist_remove(p->listeners, l);
 			l->feed = NULL;
+			l->room = NULL;
+			if(l->session)
+				gateway->close_pc(l->session->handle);
 		}
 	}
 	g_slist_free(p->subscriptions);

-- 
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