Skip to content

Commit 2bfc7f9

Browse files
authored
Add references to publisher's streams when dealing with forwarders (#3331)
1 parent b98e3bb commit 2bfc7f9

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/plugins/janus_videoroom.c

+23-2
Original file line numberDiff line numberDiff line change
@@ -2391,9 +2391,11 @@ static void janus_videoroom_publisher_destroy(janus_videoroom_publisher *p) {
23912391
GList *temp = p->streams;
23922392
while(temp) {
23932393
ps = (janus_videoroom_publisher_stream *)temp->data;
2394+
janus_refcount_increase(&ps->ref);
23942395
janus_mutex_lock(&ps->rtp_forwarders_mutex);
23952396
if(g_hash_table_size(ps->rtp_forwarders) == 0) {
23962397
janus_mutex_unlock(&ps->rtp_forwarders_mutex);
2398+
janus_refcount_decrease(&ps->ref);
23972399
temp = temp->next;
23982400
continue;
23992401
}
@@ -2410,6 +2412,7 @@ static void janus_videoroom_publisher_destroy(janus_videoroom_publisher *p) {
24102412
}
24112413
}
24122414
janus_mutex_unlock(&ps->rtp_forwarders_mutex);
2415+
janus_refcount_decrease(&ps->ref);
24132416
temp = temp->next;
24142417
}
24152418
}
@@ -5849,17 +5852,20 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi
58495852
GList *temp = publisher->streams;
58505853
while(temp) {
58515854
janus_videoroom_publisher_stream *ps = (janus_videoroom_publisher_stream *)temp->data;
5855+
janus_refcount_increase(&ps->ref);
58525856
janus_mutex_lock(&ps->rtp_forwarders_mutex);
58535857
janus_rtp_forwarder *f = g_hash_table_lookup(ps->rtp_forwarders, GUINT_TO_POINTER(stream_id));
58545858
if(f != NULL) {
58555859
if(f->metadata != NULL) {
58565860
/* This belongs to a remotization, ignore */
58575861
janus_mutex_unlock(&ps->rtp_forwarders_mutex);
5862+
janus_refcount_decrease(&ps->ref);
58585863
found = FALSE;
58595864
break;
58605865
}
58615866
g_hash_table_remove(ps->rtp_forwarders, GUINT_TO_POINTER(stream_id));
58625867
janus_mutex_unlock(&ps->rtp_forwarders_mutex);
5868+
janus_refcount_decrease(&ps->ref);
58635869
/* Found, remove from global index too */
58645870
g_hash_table_remove(publisher->rtp_forwarders, GUINT_TO_POINTER(stream_id));
58655871
found = TRUE;
@@ -6412,9 +6418,11 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi
64126418
GList *temp = p->streams;
64136419
while(temp) {
64146420
ps = (janus_videoroom_publisher_stream *)temp->data;
6421+
janus_refcount_increase(&ps->ref);
64156422
janus_mutex_lock(&ps->rtp_forwarders_mutex);
64166423
if(g_hash_table_size(ps->rtp_forwarders) == 0) {
64176424
janus_mutex_unlock(&ps->rtp_forwarders_mutex);
6425+
janus_refcount_decrease(&ps->ref);
64186426
temp = temp->next;
64196427
continue;
64206428
}
@@ -6431,6 +6439,7 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi
64316439
json_array_append_new(flist, fl);
64326440
}
64336441
janus_mutex_unlock(&ps->rtp_forwarders_mutex);
6442+
janus_refcount_decrease(&ps->ref);
64346443
temp = temp->next;
64356444
}
64366445
janus_mutex_unlock(&p->rtp_forwarders_mutex);
@@ -6834,6 +6843,7 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi
68346843
GList *temp = publisher->streams;
68356844
while(temp) {
68366845
janus_videoroom_publisher_stream *ps = (janus_videoroom_publisher_stream *)temp->data;
6846+
janus_refcount_increase(&ps->ref);
68376847
janus_mutex_lock(&ps->rtp_forwarders_mutex);
68386848
GHashTableIter iter;
68396849
gpointer value;
@@ -6849,6 +6859,7 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi
68496859
}
68506860
}
68516861
janus_mutex_unlock(&ps->rtp_forwarders_mutex);
6862+
janus_refcount_decrease(&ps->ref);
68526863
temp = temp->next;
68536864
}
68546865
janus_mutex_unlock(&publisher->rtp_forwarders_mutex);
@@ -7901,9 +7912,13 @@ static void janus_videoroom_incoming_rtp_internal(janus_videoroom_session *sessi
79017912
/* Find the stream this packet belongs to */
79027913
janus_mutex_lock(&participant->streams_mutex);
79037914
janus_videoroom_publisher_stream *ps = g_hash_table_lookup(participant->streams_byid, GINT_TO_POINTER(pkt->mindex));
7915+
if(ps != NULL)
7916+
janus_refcount_increase_nodebug(&ps->ref);
79047917
janus_mutex_unlock(&participant->streams_mutex);
7905-
if(ps == NULL || ps->disabled) {
7918+
if(ps == NULL || ps->disabled || g_atomic_int_get(&ps->destroyed)) {
79067919
/* No stream..? */
7920+
if(ps != NULL)
7921+
janus_refcount_decrease_nodebug(&ps->ref);
79077922
janus_videoroom_publisher_dereference_nodebug(participant);
79087923
return;
79097924
}
@@ -8140,6 +8155,7 @@ static void janus_videoroom_incoming_rtp_internal(janus_videoroom_session *sessi
81408155
}
81418156
}
81428157
}
8158+
janus_refcount_decrease_nodebug(&ps->ref);
81438159
janus_videoroom_publisher_dereference_nodebug(participant);
81448160
}
81458161

@@ -8227,9 +8243,13 @@ static void janus_videoroom_incoming_data_internal(janus_videoroom_session *sess
82278243
/* Find the stream this packet belongs to */
82288244
janus_mutex_lock(&participant->streams_mutex);
82298245
janus_videoroom_publisher_stream *ps = g_hash_table_lookup(participant->streams_byid, GINT_TO_POINTER(participant->data_mindex));
8246+
if(ps != NULL)
8247+
janus_refcount_increase_nodebug(&ps->ref);
82308248
janus_mutex_unlock(&participant->streams_mutex);
8231-
if(ps == NULL || !ps->active || ps->muted) {
8249+
if(ps == NULL || !ps->active || ps->muted || g_atomic_int_get(&ps->destroyed)) {
82328250
/* No or inactive stream..? */
8251+
if(ps != NULL)
8252+
janus_refcount_decrease_nodebug(&ps->ref);
82338253
janus_videoroom_publisher_dereference_nodebug(participant);
82348254
return;
82358255
}
@@ -8288,6 +8308,7 @@ static void janus_videoroom_incoming_data_internal(janus_videoroom_session *sess
82888308
janus_mutex_lock_nodebug(&ps->subscribers_mutex);
82898309
g_slist_foreach(ps->subscribers, janus_videoroom_relay_data_packet, &pkt);
82908310
janus_mutex_unlock_nodebug(&ps->subscribers_mutex);
8311+
janus_refcount_decrease_nodebug(&ps->ref);
82918312
janus_videoroom_publisher_dereference_nodebug(participant);
82928313
}
82938314

0 commit comments

Comments
 (0)