From 610e50281857fbb494153d0f70efa2c040b9df6f Mon Sep 17 00:00:00 2001 From: Alessandro Toppi Date: Fri, 16 Feb 2024 12:53:32 +0100 Subject: [PATCH 1/2] Add references to publisher's streams when dealing with forwarders --- src/plugins/janus_videoroom.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/plugins/janus_videoroom.c b/src/plugins/janus_videoroom.c index 82ecda14de..c2713c0889 100644 --- a/src/plugins/janus_videoroom.c +++ b/src/plugins/janus_videoroom.c @@ -2391,9 +2391,11 @@ static void janus_videoroom_publisher_destroy(janus_videoroom_publisher *p) { GList *temp = p->streams; while(temp) { ps = (janus_videoroom_publisher_stream *)temp->data; + janus_refcount_increase(&ps->ref); janus_mutex_lock(&ps->rtp_forwarders_mutex); if(g_hash_table_size(ps->rtp_forwarders) == 0) { janus_mutex_unlock(&ps->rtp_forwarders_mutex); + janus_refcount_decrease(&ps->ref); temp = temp->next; continue; } @@ -2410,6 +2412,7 @@ static void janus_videoroom_publisher_destroy(janus_videoroom_publisher *p) { } } janus_mutex_unlock(&ps->rtp_forwarders_mutex); + janus_refcount_decrease(&ps->ref); temp = temp->next; } } @@ -5849,17 +5852,20 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi GList *temp = publisher->streams; while(temp) { janus_videoroom_publisher_stream *ps = (janus_videoroom_publisher_stream *)temp->data; + janus_refcount_increase(&ps->ref); janus_mutex_lock(&ps->rtp_forwarders_mutex); janus_rtp_forwarder *f = g_hash_table_lookup(ps->rtp_forwarders, GUINT_TO_POINTER(stream_id)); if(f != NULL) { if(f->metadata != NULL) { /* This belongs to a remotization, ignore */ janus_mutex_unlock(&ps->rtp_forwarders_mutex); + janus_refcount_decrease(&ps->ref); found = FALSE; break; } g_hash_table_remove(ps->rtp_forwarders, GUINT_TO_POINTER(stream_id)); janus_mutex_unlock(&ps->rtp_forwarders_mutex); + janus_refcount_decrease(&ps->ref); /* Found, remove from global index too */ g_hash_table_remove(publisher->rtp_forwarders, GUINT_TO_POINTER(stream_id)); found = TRUE; @@ -6412,9 +6418,11 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi GList *temp = p->streams; while(temp) { ps = (janus_videoroom_publisher_stream *)temp->data; + janus_refcount_increase(&ps->ref); janus_mutex_lock(&ps->rtp_forwarders_mutex); if(g_hash_table_size(ps->rtp_forwarders) == 0) { janus_mutex_unlock(&ps->rtp_forwarders_mutex); + janus_refcount_decrease(&ps->ref); temp = temp->next; continue; } @@ -6431,6 +6439,7 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi json_array_append_new(flist, fl); } janus_mutex_unlock(&ps->rtp_forwarders_mutex); + janus_refcount_decrease(&ps->ref); temp = temp->next; } janus_mutex_unlock(&p->rtp_forwarders_mutex); @@ -6834,6 +6843,7 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi GList *temp = publisher->streams; while(temp) { janus_videoroom_publisher_stream *ps = (janus_videoroom_publisher_stream *)temp->data; + janus_refcount_increase(&ps->ref); janus_mutex_lock(&ps->rtp_forwarders_mutex); GHashTableIter iter; gpointer value; @@ -6849,6 +6859,7 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi } } janus_mutex_unlock(&ps->rtp_forwarders_mutex); + janus_refcount_decrease(&ps->ref); temp = temp->next; } janus_mutex_unlock(&publisher->rtp_forwarders_mutex); From a4f5c0dadaef3c96a37b3eb6771bb0f6e6586684 Mon Sep 17 00:00:00 2001 From: Lorenzo Miniero Date: Fri, 16 Feb 2024 18:26:02 +0100 Subject: [PATCH 2/2] Add reference to publisher stream when handling incoming RTP/data --- src/plugins/janus_videoroom.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/plugins/janus_videoroom.c b/src/plugins/janus_videoroom.c index c2713c0889..2e5377d678 100644 --- a/src/plugins/janus_videoroom.c +++ b/src/plugins/janus_videoroom.c @@ -7912,9 +7912,13 @@ static void janus_videoroom_incoming_rtp_internal(janus_videoroom_session *sessi /* Find the stream this packet belongs to */ janus_mutex_lock(&participant->streams_mutex); janus_videoroom_publisher_stream *ps = g_hash_table_lookup(participant->streams_byid, GINT_TO_POINTER(pkt->mindex)); + if(ps != NULL) + janus_refcount_increase_nodebug(&ps->ref); janus_mutex_unlock(&participant->streams_mutex); - if(ps == NULL || ps->disabled) { + if(ps == NULL || ps->disabled || g_atomic_int_get(&ps->destroyed)) { /* No stream..? */ + if(ps != NULL) + janus_refcount_decrease_nodebug(&ps->ref); janus_videoroom_publisher_dereference_nodebug(participant); return; } @@ -8151,6 +8155,7 @@ static void janus_videoroom_incoming_rtp_internal(janus_videoroom_session *sessi } } } + janus_refcount_decrease_nodebug(&ps->ref); janus_videoroom_publisher_dereference_nodebug(participant); } @@ -8238,9 +8243,13 @@ static void janus_videoroom_incoming_data_internal(janus_videoroom_session *sess /* Find the stream this packet belongs to */ janus_mutex_lock(&participant->streams_mutex); janus_videoroom_publisher_stream *ps = g_hash_table_lookup(participant->streams_byid, GINT_TO_POINTER(participant->data_mindex)); + if(ps != NULL) + janus_refcount_increase_nodebug(&ps->ref); janus_mutex_unlock(&participant->streams_mutex); - if(ps == NULL || !ps->active || ps->muted) { + if(ps == NULL || !ps->active || ps->muted || g_atomic_int_get(&ps->destroyed)) { /* No or inactive stream..? */ + if(ps != NULL) + janus_refcount_decrease_nodebug(&ps->ref); janus_videoroom_publisher_dereference_nodebug(participant); return; } @@ -8299,6 +8308,7 @@ static void janus_videoroom_incoming_data_internal(janus_videoroom_session *sess janus_mutex_lock_nodebug(&ps->subscribers_mutex); g_slist_foreach(ps->subscribers, janus_videoroom_relay_data_packet, &pkt); janus_mutex_unlock_nodebug(&ps->subscribers_mutex); + janus_refcount_decrease_nodebug(&ps->ref); janus_videoroom_publisher_dereference_nodebug(participant); }