Skip to content

Commit

Permalink
More checks when hanging up VideoRoom subscriber (see #2087)
Browse files Browse the repository at this point in the history
  • Loading branch information
lminiero committed Apr 22, 2020
1 parent f3ef0cf commit f629ab0
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions plugins/janus_videoroom.c
Original file line number Diff line number Diff line change
Expand Up @@ -5156,22 +5156,25 @@ void janus_videoroom_hangup_media(janus_plugin_session *handle) {
janus_videoroom_hangup_media_internal(handle);
}

static void janus_videoroom_hangup_subscriber(janus_videoroom_subscriber * s) {
static void janus_videoroom_hangup_subscriber(janus_videoroom_subscriber *s) {
/* Already hung up */
if (!s->feed) {
return;
}
/* Check if the owner needs to be cleaned up */
if(s->pvt_id > 0 && s->room != NULL) {
janus_mutex_lock(&s->room->mutex);
janus_videoroom_publisher *owner = g_hash_table_lookup(s->room->private_ids, GUINT_TO_POINTER(s->pvt_id));
janus_videoroom *room = s->room;
if(room != NULL)
janus_refcount_increase(&room->ref);
if(s->pvt_id > 0 && room != NULL) {
janus_mutex_lock(&room->mutex);
janus_videoroom_publisher *owner = g_hash_table_lookup(room->private_ids, GUINT_TO_POINTER(s->pvt_id));
if(owner != NULL) {
janus_mutex_lock(&owner->subscribers_mutex);
/* Note: we should refcount these subscription-publisher mappings as well */
owner->subscriptions = g_slist_remove(owner->subscriptions, s);
janus_mutex_unlock(&owner->subscribers_mutex);
}
janus_mutex_unlock(&s->room->mutex);
janus_mutex_unlock(&room->mutex);
}
/* TODO: are we sure this is okay as other handlers use feed directly without synchronization */
if(s->feed)
Expand All @@ -5185,6 +5188,8 @@ static void janus_videoroom_hangup_subscriber(janus_videoroom_subscriber * s) {
/* Remove the reference we added when "joining" the room */
janus_refcount_decrease(&s->ref);
}
if(room != NULL)
janus_refcount_decrease(&room->ref);
}

static void janus_videoroom_hangup_media_internal(janus_plugin_session *handle) {
Expand Down

0 comments on commit f629ab0

Please sign in to comment.