Skip to content

Commit

Permalink
audiobridge: cleanup participant's queue and jitter buffer when muted…
Browse files Browse the repository at this point in the history
… property changes or the whole room is muted (#3368)
  • Loading branch information
atoppi authored Sep 4, 2024
1 parent 9d360ca commit 65216f2
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/plugins/janus_audiobridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -4278,6 +4278,7 @@ static json_t *janus_audiobridge_process_synchronous_request(janus_audiobridge_s
goto prepare_response;
}

janus_mutex_lock(&participant->qmutex);
if(participant->muted == muted) {
/* If someone trying to mute an already muted user, or trying to unmute a user that is not mute),
then we should do nothing */
Expand All @@ -4287,12 +4288,12 @@ static json_t *janus_audiobridge_process_synchronous_request(janus_audiobridge_s
json_object_set_new(response, "audiobridge", json_string("success"));

/* Done */
janus_mutex_unlock(&participant->qmutex);
janus_mutex_unlock(&audiobridge->mutex);
janus_refcount_decrease(&audiobridge->ref);
goto prepare_response;
}

janus_mutex_lock(&participant->qmutex);
participant->muted = muted;
JANUS_LOG(LOG_VERB, "Setting muted property: %s (room %s, user %s)\n",
participant->muted ? "true" : "false", participant->room->room_id_str, participant->user_id_str);
Expand Down Expand Up @@ -4430,6 +4431,13 @@ static json_t *janus_audiobridge_process_synchronous_request(janus_audiobridge_s
g_hash_table_iter_init(&iter, audiobridge->participants);
while(g_hash_table_iter_next(&iter, NULL, &value)) {
janus_audiobridge_participant *p = value;
janus_mutex_lock(&p->qmutex);
if(p->muted != audiobridge->muted) {
/* Clear the queued packets waiting to be handled */
janus_audiobridge_participant_clear_jitter_buffer(p);
janus_audiobridge_participant_clear_inbuf(p);
}
janus_mutex_unlock(&p->qmutex);
if(g_atomic_int_get(&p->paused_events))
continue;
JANUS_LOG(LOG_VERB, "Notifying participant %s (%s)\n", p->user_id_str, p->display ? p->display : "??");
Expand Down Expand Up @@ -7140,10 +7148,10 @@ static void *janus_audiobridge_handler(void *data) {
if(muted || display || (participant->stereo && spatial) || denoise) {
if(muted) {
janus_mutex_lock(&participant->qmutex);
participant->muted = json_is_true(muted);
JANUS_LOG(LOG_VERB, "Setting muted property: %s (room %s, user %s)\n",
participant->muted ? "true" : "false", participant->room->room_id_str, participant->user_id_str);
if(participant->muted) {
if(participant->muted != json_is_true(muted)) {
participant->muted = json_is_true(muted);
JANUS_LOG(LOG_VERB, "Setting muted property: %s (room %s, user %s)\n",
participant->muted ? "true" : "false", participant->room->room_id_str, participant->user_id_str);
/* Clear the queued packets waiting to be handled */
janus_audiobridge_participant_clear_jitter_buffer(participant);
janus_audiobridge_participant_clear_inbuf(participant);
Expand Down Expand Up @@ -7626,7 +7634,11 @@ static void *janus_audiobridge_handler(void *data) {
g_free(participant->display);
participant->display = display_text ? g_strdup(display_text) : NULL;
participant->room = audiobridge;
janus_mutex_lock(&participant->qmutex);
participant->muted = muted ? json_is_true(muted) : FALSE; /* When switching to a new room, you're unmuted by default */
janus_audiobridge_participant_clear_jitter_buffer(participant);
janus_audiobridge_participant_clear_inbuf(participant);
janus_mutex_unlock(&participant->qmutex);
if(suspended && json_is_true(suspended)) {
janus_mutex_lock(&participant->suspend_cond_mutex);
g_atomic_int_set(&participant->suspended, 1);
Expand Down

0 comments on commit 65216f2

Please sign in to comment.