Skip to content

Commit

Permalink
Protect participant->muted with qmutex
Browse files Browse the repository at this point in the history
  • Loading branch information
atoppi committed May 14, 2024
1 parent b26429f commit f138058
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/plugins/janus_audiobridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -4244,6 +4244,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 @@ -4253,19 +4254,19 @@ 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;
}

participant->muted = muted;
JANUS_LOG(LOG_VERB, "Setting muted property: %s (room %s, user %s)\n",
muted ? "true" : "false", participant->room->room_id_str, participant->user_id_str);
/* Clear the queued packets waiting to be handled */
janus_mutex_lock(&participant->qmutex);
janus_audiobridge_participant_clear_jitter_buffer(participant);
janus_audiobridge_participant_clear_inbuf(participant);
janus_mutex_unlock(&participant->qmutex);
participant->muted = muted;

json_t *list = json_array();
json_t *pl = json_object();
Expand Down Expand Up @@ -4394,13 +4395,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_mutex_lock(&p->qmutex);
janus_audiobridge_participant_clear_jitter_buffer(p);
janus_audiobridge_participant_clear_inbuf(p);
janus_mutex_unlock(&p->qmutex);
}
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 @@ -7039,15 +7040,17 @@ static void *janus_audiobridge_handler(void *data) {
participant->group = group_id;
}
if(muted || display || (participant->stereo && spatial) || denoise) {
if(muted && participant->muted != json_is_true(muted)) {
JANUS_LOG(LOG_VERB, "Setting muted property: %s (room %s, user %s)\n",
json_is_true(muted) ? "true" : "false", participant->room->room_id_str, participant->user_id_str);
/* Clear the queued packets waiting to be handled */
if(muted) {
janus_mutex_lock(&participant->qmutex);
janus_audiobridge_participant_clear_jitter_buffer(participant);
janus_audiobridge_participant_clear_inbuf(participant);
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",
json_is_true(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);
}
janus_mutex_unlock(&participant->qmutex);
participant->muted = json_is_true(muted);
}
if(display) {
char *old_display = participant->display;
Expand Down Expand Up @@ -7525,8 +7528,8 @@ static void *janus_audiobridge_handler(void *data) {
g_free(participant->display);
participant->display = display_text ? g_strdup(display_text) : NULL;
participant->room = audiobridge;
participant->muted = muted ? json_is_true(muted) : FALSE; /* When switching to a new room, you're unmuted by default */
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);
Expand Down

0 comments on commit f138058

Please sign in to comment.