Skip to content

Commit

Permalink
Add references to publisher's streams when dealing with forwarders (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
atoppi authored and RSATom committed Feb 27, 2024
1 parent 2a50e8a commit d1ce079
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/plugins/janus_videoroom.c
Original file line number Diff line number Diff line change
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 @@ -5843,17 +5846,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 @@ -6406,9 +6412,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 @@ -6425,6 +6433,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 @@ -6828,6 +6837,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 @@ -6843,6 +6853,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 @@ -7895,9 +7906,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 @@ -8134,6 +8149,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 @@ -8221,9 +8237,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 @@ -8282,6 +8302,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 d1ce079

Please sign in to comment.