Skip to content

Commit

Permalink
Update to notify speaking participant (#2172)
Browse files Browse the repository at this point in the history
When the code detects a speaker is talking, an event is now sent to them too, and not just the other participants as before
  • Loading branch information
maxboehm committed May 26, 2020
1 parent 63c027c commit acd414c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions plugins/janus_videoroom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand All @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit acd414c

Please sign in to comment.