Skip to content

Commit

Permalink
Add references to publisher's streams when dealing with forwarders (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
atoppi committed Feb 27, 2024
1 parent b98e3bb commit 2bfc7f9
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/plugins/janus_videoroom.c
Expand Up @@ -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;
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -7901,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;
}
Expand Down Expand Up @@ -8140,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);
}

Expand Down Expand Up @@ -8227,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;
}
Expand Down Expand Up @@ -8288,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);
}

Expand Down

0 comments on commit 2bfc7f9

Please sign in to comment.