From bf5f1288e90fd177e778a9b0cdef1b50c71ff5b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20B=C3=B6hm?= Date: Mon, 25 May 2020 11:51:39 +0200 Subject: [PATCH] Update to notify speaking participant Notify the speak itself, so we can reduce the javascript code on speaker side --- plugins/janus_videoroom.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/plugins/janus_videoroom.c b/plugins/janus_videoroom.c index a9ee42f916..db493457b9 100644 --- a/plugins/janus_videoroom.c +++ b/plugins/janus_videoroom.c @@ -2510,7 +2510,7 @@ static janus_videoroom_publisher *janus_videoroom_session_get_publisher_nodebug( return publisher; } -static void janus_videoroom_notify_participants(janus_videoroom_publisher *participant, json_t *msg) { +static void janus_videoroom_notify_participants(janus_videoroom_publisher *participant, json_t *msg, gboolean notify_source_participant) { /* participant->room->mutex has to be locked. */ if(participant->room == NULL) return; @@ -2519,7 +2519,11 @@ static void janus_videoroom_notify_participants(janus_videoroom_publisher *parti g_hash_table_iter_init(&iter, participant->room->participants); while (participant->room && !g_atomic_int_get(&participant->room->destroyed) && g_hash_table_iter_next(&iter, NULL, &value)) { janus_videoroom_publisher *p = value; - if(p && p->session && p != participant) { + /* + Normally, only participants which are not the source of the event are notified + Exception: To save cpu time one the client side, the speaking event is also sent to the speak + */ + if(p && p->session && (p != participant || notify_source_participant)) { JANUS_LOG(LOG_VERB, "Notifying participant %s (%s)\n", p->user_id_str, p->display ? p->display : "??"); int ret = gateway->push_event(p->session->handle, &janus_videoroom_plugin, NULL, msg, NULL); JANUS_LOG(LOG_VERB, " >> %d (%s)\n", ret, janus_get_api_error(ret)); @@ -2541,7 +2545,7 @@ static void janus_videoroom_participant_joining(janus_videoroom_publisher *p) { json_object_set_new(event, "videoroom", json_string("event")); json_object_set_new(event, "room", string_ids ? json_string(p->room_id_str) : json_integer(p->room_id)); json_object_set_new(event, "joining", user); - janus_videoroom_notify_participants(p, event); + janus_videoroom_notify_participants(p, event, FALSE); /* user gets deref-ed by the owner event */ json_decref(event); } @@ -2573,7 +2577,7 @@ static void janus_videoroom_leave_or_unpublish(janus_videoroom_publisher *partic json_object_set_new(event, "room", string_ids ? json_string(participant->room_id_str) : json_integer(participant->room_id)); json_object_set_new(event, is_leaving ? (kicked ? "kicked" : "leaving") : "unpublished", string_ids ? json_string(participant->user_id_str) : json_integer(participant->user_id)); - janus_videoroom_notify_participants(participant, event); + janus_videoroom_notify_participants(participant, event, FALSE); /* Also notify event handlers */ if(notify_events && gateway->events_is_enabled()) { json_t *info = json_object(); @@ -4786,7 +4790,7 @@ void janus_videoroom_setup_media(janus_plugin_session *handle) { json_object_set_new(pub, "publishers", list); if (participant->room) { janus_mutex_lock(&participant->room->mutex); - janus_videoroom_notify_participants(participant, pub); + janus_videoroom_notify_participants(participant, pub, FALSE); janus_mutex_unlock(&participant->room->mutex); } json_decref(pub); @@ -4871,7 +4875,7 @@ void janus_videoroom_incoming_rtp(janus_plugin_session *handle, janus_plugin_rtp json_object_set_new(event, "room", string_ids ? json_string(videoroom->room_id_str) : json_integer(videoroom->room_id)); json_object_set_new(event, "id", string_ids ? json_string(participant->user_id_str) : json_integer(participant->user_id)); json_object_set_new(event, "audio-level-dBov-avg", json_real(audio_dBov_avg)); - janus_videoroom_notify_participants(participant, event); + janus_videoroom_notify_participants(participant, event, TRUE); json_decref(event); janus_mutex_unlock(&videoroom->mutex); /* Also notify event handlers */ @@ -6333,7 +6337,7 @@ static void *janus_videoroom_handler(void *data) { json_object_set_new(display_event, "id", string_ids ? json_string(participant->user_id_str) : json_integer(participant->user_id)); json_object_set_new(display_event, "display", json_string(participant->display)); if(participant->room && !g_atomic_int_get(&participant->room->destroyed)) { - janus_videoroom_notify_participants(participant, display_event); + janus_videoroom_notify_participants(participant, display_event, FALSE); } janus_mutex_unlock(&participant->room->mutex); json_decref(display_event);