@@ -2239,6 +2239,13 @@ typedef struct janus_videoroom_subscriber_stream {
2239
2239
janus_refcount ref;
2240
2240
} janus_videoroom_subscriber_stream;
2241
2241
2242
+ typedef struct janus_videoroom_stream_mapping {
2243
+ janus_videoroom_publisher_stream *ps;
2244
+ janus_videoroom_subscriber *subscriber;
2245
+ janus_videoroom_subscriber_stream *ss;
2246
+ gboolean unref_ss;
2247
+ } janus_videoroom_stream_mapping;
2248
+
2242
2249
typedef struct janus_videoroom_rtp_relay_packet {
2243
2250
janus_videoroom_publisher_stream *source;
2244
2251
janus_rtp_header *data;
@@ -8469,7 +8476,7 @@ static void janus_videoroom_hangup_media_internal(gpointer session_data) {
8469
8476
participant->e2ee = FALSE;
8470
8477
/* Get rid of streams */
8471
8478
janus_mutex_lock(&participant->streams_mutex);
8472
- GList *subscribers = NULL;
8479
+ GList *subscribers = NULL, *mappings = NULL ;
8473
8480
GList *temp = participant->streams;
8474
8481
while(temp) {
8475
8482
janus_videoroom_publisher_stream *ps = (janus_videoroom_publisher_stream *)temp->data;
@@ -8486,8 +8493,16 @@ static void janus_videoroom_hangup_media_internal(gpointer session_data) {
8486
8493
janus_refcount_increase(&ss->subscriber->session->ref);
8487
8494
subscribers = g_list_append(subscribers, ss->subscriber);
8488
8495
}
8489
- /* Remove the subscription (turns the m-line to inactive) */
8490
- janus_videoroom_subscriber_stream_remove(ss, ps, FALSE);
8496
+ /* Take note of the subscription to remove */
8497
+ janus_videoroom_stream_mapping *m = g_malloc(sizeof(janus_videoroom_stream_mapping));
8498
+ janus_refcount_increase(&ps->ref);
8499
+ janus_refcount_increase(&ss->ref);
8500
+ janus_refcount_increase(&ss->subscriber->ref);
8501
+ m->ps = ps;
8502
+ m->ss = ss;
8503
+ m->unref_ss = (g_slist_find(ps->subscribers, ss) != NULL);
8504
+ m->subscriber = ss->subscriber;
8505
+ mappings = g_list_append(mappings, m);
8491
8506
}
8492
8507
}
8493
8508
g_slist_free(ps->subscribers);
@@ -8498,6 +8513,28 @@ static void janus_videoroom_hangup_media_internal(gpointer session_data) {
8498
8513
janus_mutex_unlock(&ps->subscribers_mutex);
8499
8514
temp = temp->next;
8500
8515
}
8516
+ if(mappings) {
8517
+ temp = mappings;
8518
+ while(temp) {
8519
+ janus_videoroom_stream_mapping *m = (janus_videoroom_stream_mapping *)temp->data;
8520
+ /* Remove the subscription (turns the m-line to inactive) */
8521
+ janus_videoroom_publisher_stream *ps = m->ps;
8522
+ janus_videoroom_subscriber *subscriber = m->subscriber;
8523
+ janus_videoroom_subscriber_stream *ss = m->ss;
8524
+ if(subscriber) {
8525
+ janus_mutex_lock(&subscriber->streams_mutex);
8526
+ janus_videoroom_subscriber_stream_remove(ss, ps, TRUE);
8527
+ janus_mutex_unlock(&subscriber->streams_mutex);
8528
+ if(m->unref_ss)
8529
+ janus_refcount_decrease(&ss->ref);
8530
+ janus_refcount_decrease(&subscriber->ref);
8531
+ }
8532
+ janus_refcount_decrease(&ss->ref);
8533
+ janus_refcount_decrease(&ps->ref);
8534
+ temp = temp->next;
8535
+ }
8536
+ g_list_free_full(mappings, (GDestroyNotify)g_free);
8537
+ }
8501
8538
/* Any subscriber session to update? */
8502
8539
janus_videoroom *room = participant->room;
8503
8540
if(subscribers != NULL) {
@@ -8595,8 +8632,8 @@ static void janus_videoroom_hangup_media_internal(gpointer session_data) {
8595
8632
}
8596
8633
list = list->next;
8597
8634
}
8598
- janus_videoroom_subscriber_stream_remove(s, NULL, TRUE);
8599
8635
temp = temp->next;
8636
+ janus_videoroom_subscriber_stream_remove(s, NULL, TRUE);
8600
8637
}
8601
8638
/* Free streams */
8602
8639
g_list_free(subscriber->streams);
@@ -9649,8 +9686,8 @@ static void *janus_videoroom_handler(void *data) {
9649
9686
GList *temp = subscriber->streams;
9650
9687
while(temp) {
9651
9688
janus_videoroom_subscriber_stream *s = (janus_videoroom_subscriber_stream *)temp->data;
9652
- janus_videoroom_subscriber_stream_remove(s, NULL, TRUE);
9653
9689
temp = temp->next;
9690
+ janus_videoroom_subscriber_stream_remove(s, NULL, TRUE);
9654
9691
}
9655
9692
g_list_free(subscriber->streams);
9656
9693
subscriber->streams = NULL;
@@ -10432,10 +10469,10 @@ static void *janus_videoroom_handler(void *data) {
10432
10469
list = list->next;
10433
10470
continue;
10434
10471
}
10435
- janus_videoroom_subscriber_stream_remove(stream, ps, TRUE);
10436
10472
if(stream->type != JANUS_VIDEOROOM_MEDIA_DATA)
10437
10473
changes++;
10438
10474
list = list->next;
10475
+ janus_videoroom_subscriber_stream_remove(stream, ps, TRUE);
10439
10476
}
10440
10477
temp = temp->next;
10441
10478
}
0 commit comments