@@ -4318,9 +4318,7 @@ static void janus_videoroom_notify_about_publisher(janus_videoroom_publisher *p,
4318
4318
janus_videoroom *room = p->room;
4319
4319
if(room && !g_atomic_int_get(&room->destroyed)) {
4320
4320
janus_refcount_increase(&room->ref);
4321
- janus_mutex_lock(&room->mutex);
4322
4321
janus_videoroom_notify_participants(p, pub, FALSE);
4323
- janus_mutex_unlock(&room->mutex);
4324
4322
janus_refcount_decrease(&room->ref);
4325
4323
}
4326
4324
json_decref(pub);
@@ -7975,7 +7973,6 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi
7975
7973
publisher->display = new_display;
7976
7974
g_free(old_display);
7977
7975
}
7978
- janus_mutex_unlock(&videoroom->mutex);
7979
7976
janus_mutex_lock(&publisher->streams_mutex);
7980
7977
janus_videoroom_publisher_stream *ps = NULL;
7981
7978
int changes = FALSE;
@@ -8115,6 +8112,7 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi
8115
8112
janus_videoroom_notify_about_publisher(publisher, TRUE);
8116
8113
}
8117
8114
janus_mutex_unlock(&publisher->streams_mutex);
8115
+ janus_mutex_unlock(&videoroom->mutex);
8118
8116
/* Done */
8119
8117
janus_refcount_decrease(&publisher->ref);
8120
8118
janus_refcount_decrease(&videoroom->ref);
@@ -8380,9 +8378,16 @@ void janus_videoroom_setup_media(janus_plugin_session *handle) {
8380
8378
if(session->participant_type == janus_videoroom_p_type_publisher) {
8381
8379
janus_videoroom_publisher *participant = janus_videoroom_session_get_publisher(session);
8382
8380
/* Notify all other participants that there's a new boy in town */
8381
+ janus_videoroom *room = participant->room;
8382
+ if(room && !g_atomic_int_get(&room->destroyed)) {
8383
+ janus_refcount_increase(&room->ref);
8384
+ janus_mutex_lock(&room->mutex);
8385
+ }
8383
8386
janus_mutex_lock(&participant->rec_mutex);
8384
8387
janus_mutex_lock(&participant->streams_mutex);
8385
- janus_videoroom_notify_about_publisher(participant, FALSE);
8388
+ if(room) {
8389
+ janus_videoroom_notify_about_publisher(participant, FALSE);
8390
+ }
8386
8391
/* Check if we need to start recording */
8387
8392
if((participant->room && participant->room->record) || participant->recording_active) {
8388
8393
GList *temp = participant->streams;
@@ -8395,6 +8400,10 @@ void janus_videoroom_setup_media(janus_plugin_session *handle) {
8395
8400
}
8396
8401
janus_mutex_unlock(&participant->streams_mutex);
8397
8402
janus_mutex_unlock(&participant->rec_mutex);
8403
+ if(room) {
8404
+ janus_mutex_unlock(&room->mutex);
8405
+ janus_refcount_decrease(&room->ref);
8406
+ }
8398
8407
janus_refcount_decrease(&participant->ref);
8399
8408
} else if(session->participant_type == janus_videoroom_p_type_subscriber) {
8400
8409
janus_videoroom_subscriber *s = janus_videoroom_session_get_subscriber(session);
@@ -10811,6 +10820,7 @@ static void *janus_videoroom_handler(void *data) {
10811
10820
* a renegotiation is involved, descriptions are updated later */
10812
10821
gboolean desc_updated = FALSE;
10813
10822
size_t i = 0;
10823
+ janus_mutex_lock(&participant->room->mutex);
10814
10824
janus_mutex_lock(&participant->streams_mutex);
10815
10825
for(i=0; i<json_array_size(descriptions); i++) {
10816
10826
json_t *d = json_array_get(descriptions, i);
@@ -10829,6 +10839,7 @@ static void *janus_videoroom_handler(void *data) {
10829
10839
if(desc_updated)
10830
10840
janus_videoroom_notify_about_publisher(participant, TRUE);
10831
10841
janus_mutex_unlock(&participant->streams_mutex);
10842
+ janus_mutex_unlock(&participant->room->mutex);
10832
10843
}
10833
10844
/* Done */
10834
10845
event = json_object();
@@ -11138,6 +11149,7 @@ static void *janus_videoroom_handler(void *data) {
11138
11149
* handle the unsubscribe first, and the subscribe only after that */
11139
11150
int changes = 0;
11140
11151
size_t i = 0;
11152
+ janus_mutex_lock(&subscriber->room->mutex);
11141
11153
janus_mutex_lock(&subscriber->streams_mutex);
11142
11154
if(unsubscribe) {
11143
11155
/* Remove the specified subscriptions */
@@ -11165,10 +11177,8 @@ static void *janus_videoroom_handler(void *data) {
11165
11177
janus_videoroom_subscriber_stream_remove(stream, NULL, TRUE);
11166
11178
changes++;
11167
11179
} else if(feed_id_str != NULL) {
11168
- janus_mutex_lock(&subscriber->room->mutex);
11169
11180
janus_videoroom_publisher *publisher = g_hash_table_lookup(subscriber->room->participants,
11170
11181
string_ids ? (gpointer)feed_id_str : (gpointer)&feed_id);
11171
- janus_mutex_unlock(&subscriber->room->mutex);
11172
11182
if(publisher == NULL || g_atomic_int_get(&publisher->destroyed) ||
11173
11183
!g_atomic_int_get(&publisher->session->started)) {
11174
11184
JANUS_LOG(LOG_WARN, "Publisher '%s' not found, not unsubscribing...\n", feed_id_str);
@@ -11219,10 +11229,8 @@ static void *janus_videoroom_handler(void *data) {
11219
11229
} else {
11220
11230
feed_id_str = (char *)json_string_value(feed);
11221
11231
}
11222
- janus_mutex_lock(&subscriber->room->mutex);
11223
11232
janus_videoroom_publisher *publisher = g_hash_table_lookup(subscriber->room->participants,
11224
11233
string_ids ? (gpointer)feed_id_str : (gpointer)&feed_id);
11225
- janus_mutex_unlock(&subscriber->room->mutex);
11226
11234
if(publisher == NULL || g_atomic_int_get(&publisher->destroyed) ||
11227
11235
!g_atomic_int_get(&publisher->session->started)) {
11228
11236
JANUS_LOG(LOG_WARN, "Publisher '%s' not found, not subscribing...\n", feed_id_str);
@@ -11379,6 +11387,7 @@ static void *janus_videoroom_handler(void *data) {
11379
11387
changes++;
11380
11388
if(changes == 0) {
11381
11389
janus_mutex_unlock(&subscriber->streams_mutex);
11390
+ janus_mutex_unlock(&subscriber->room->mutex);
11382
11391
/* Nothing changed, just ack and don't do anything else */
11383
11392
JANUS_LOG(LOG_VERB, "No change made, skipping renegotiation\n");
11384
11393
event = json_object();
@@ -11406,6 +11415,7 @@ static void *janus_videoroom_handler(void *data) {
11406
11415
/* We're still waiting for an answer to a previous offer, postpone this */
11407
11416
g_atomic_int_set(&subscriber->pending_offer, 1);
11408
11417
janus_mutex_unlock(&subscriber->streams_mutex);
11418
+ janus_mutex_unlock(&subscriber->room->mutex);
11409
11419
JANUS_LOG(LOG_VERB, "Post-poning new offer, waiting for previous answer\n");
11410
11420
/* Send a temporary event */
11411
11421
event = json_object();
@@ -11437,6 +11447,7 @@ static void *janus_videoroom_handler(void *data) {
11437
11447
/* Generate a new offer */
11438
11448
json_t *jsep = janus_videoroom_subscriber_offer(subscriber);
11439
11449
janus_mutex_unlock(&subscriber->streams_mutex);
11450
+ janus_mutex_unlock(&subscriber->room->mutex);
11440
11451
/* How long will the Janus core take to push the event? */
11441
11452
gint64 start = janus_get_monotonic_time();
11442
11453
int res = gateway->push_event(msg->handle, &janus_videoroom_plugin, msg->transaction, event, jsep);
@@ -12023,6 +12034,7 @@ static void *janus_videoroom_handler(void *data) {
12023
12034
* notice that no renegotiation happens, we just switch the sources */
12024
12035
int changes = 0;
12025
12036
gboolean update = FALSE;
12037
+ janus_mutex_lock(&subscriber->room->mutex);
12026
12038
janus_mutex_lock(&subscriber->streams_mutex);
12027
12039
for(i=0; i<json_array_size(feeds); i++) {
12028
12040
json_t *s = json_array_get(feeds, i);
@@ -12045,10 +12057,8 @@ static void *janus_videoroom_handler(void *data) {
12045
12057
feed_id_str = (char *)json_string_value(feed);
12046
12058
}
12047
12059
const char *mid = json_string_value(json_object_get(s, "mid"));
12048
- janus_mutex_lock(&subscriber->room->mutex);
12049
12060
janus_videoroom_publisher *publisher = g_hash_table_lookup(subscriber->room->participants,
12050
12061
string_ids ? (gpointer)feed_id_str : (gpointer)&feed_id);
12051
- janus_mutex_unlock(&subscriber->room->mutex);
12052
12062
if(publisher == NULL || g_atomic_int_get(&publisher->destroyed) ||
12053
12063
!g_atomic_int_get(&publisher->session->started)) {
12054
12064
JANUS_LOG(LOG_WARN, "Publisher '%s' not found, not switching...\n", feed_id_str);
@@ -12197,6 +12207,7 @@ static void *janus_videoroom_handler(void *data) {
12197
12207
janus_refcount_decrease(&stream->ref);
12198
12208
}
12199
12209
janus_mutex_unlock(&subscriber->streams_mutex);
12210
+ janus_mutex_unlock(&subscriber->room->mutex);
12200
12211
/* Decrease the references we took before */
12201
12212
while(publishers) {
12202
12213
janus_videoroom_publisher *publisher = (janus_videoroom_publisher *)publishers->data;
@@ -12952,9 +12963,11 @@ static void *janus_videoroom_handler(void *data) {
12952
12963
/* If this is an update/renegotiation, notify participants about this */
12953
12964
if(sdp_update && g_atomic_int_get(&session->started)) {
12954
12965
/* Notify all other participants this publisher's media has changed */
12966
+ janus_mutex_lock(&videoroom->mutex);
12955
12967
janus_mutex_lock(&participant->streams_mutex);
12956
12968
janus_videoroom_notify_about_publisher(participant, TRUE);
12957
12969
janus_mutex_unlock(&participant->streams_mutex);
12970
+ janus_mutex_unlock(&videoroom->mutex);
12958
12971
}
12959
12972
/* Done */
12960
12973
if(res != JANUS_OK) {
@@ -13511,13 +13524,15 @@ static void *janus_videoroom_remote_publisher_thread(void *user_data) {
13511
13524
janus_refcount_increase(&publisher->session->ref);
13512
13525
janus_videoroom *videoroom = publisher->room;
13513
13526
janus_refcount_increase(&videoroom->ref);
13527
+ janus_mutex_lock(&videoroom->mutex);
13514
13528
g_hash_table_insert(videoroom->participants,
13515
13529
string_ids ? (gpointer)g_strdup(publisher->user_id_str) : (gpointer)janus_uint64_dup(publisher->user_id),
13516
13530
publisher);
13517
13531
/* Let's also notify all other participants that the publisher is here */
13518
13532
janus_mutex_lock(&publisher->streams_mutex);
13519
13533
janus_videoroom_notify_about_publisher(publisher, FALSE);
13520
13534
janus_mutex_unlock(&publisher->streams_mutex);
13535
+ janus_mutex_unlock(&videoroom->mutex);
13521
13536
13522
13537
/* Loop */
13523
13538
int num = 0, i = 0;
0 commit comments