@@ -1370,6 +1370,7 @@ typedef struct janus_audiobridge_participant {
1370
1370
/* Plain RTP, in case this is not a WebRTC participant */
1371
1371
gboolean plainrtp ; /* Whether this is a WebRTC participant, or a plain RTP one */
1372
1372
janus_audiobridge_plainrtp_media plainrtp_media ;
1373
+ janus_mutex pmutex ;
1373
1374
/* Opus stuff */
1374
1375
OpusEncoder * encoder ; /* Opus encoder instance */
1375
1376
OpusDecoder * decoder ; /* Opus decoder instance */
@@ -1442,7 +1443,9 @@ static void janus_audiobridge_participant_free(const janus_refcount *participant
1442
1443
#ifdef HAVE_LIBOGG
1443
1444
janus_audiobridge_file_free (participant -> annc );
1444
1445
#endif
1446
+ janus_mutex_lock (& participant -> pmutex );
1445
1447
janus_audiobridge_plainrtp_media_cleanup (& participant -> plainrtp_media );
1448
+ janus_mutex_unlock (& participant -> pmutex );
1446
1449
g_free (participant );
1447
1450
}
1448
1451
@@ -5512,6 +5515,7 @@ static void *janus_audiobridge_handler(void *data) {
5512
5515
janus_mutex_init (& participant -> qmutex );
5513
5516
participant -> arc = NULL ;
5514
5517
janus_audiobridge_plainrtp_media_cleanup (& participant -> plainrtp_media );
5518
+ janus_mutex_init (& participant -> pmutex );
5515
5519
janus_mutex_init (& participant -> rec_mutex );
5516
5520
}
5517
5521
participant -> session = session ;
@@ -5598,7 +5602,6 @@ static void *janus_audiobridge_handler(void *data) {
5598
5602
}
5599
5603
participant -> reset = FALSE;
5600
5604
/* If this is a plain RTP participant, create the socket */
5601
- janus_audiobridge_plainrtp_media_cleanup (& participant -> plainrtp_media );
5602
5605
if (rtp != NULL ) {
5603
5606
const char * ip = json_string_value (json_object_get (rtp , "ip" ));
5604
5607
uint16_t port = json_integer_value (json_object_get (rtp , "port" ));
@@ -5615,6 +5618,8 @@ static void *janus_audiobridge_handler(void *data) {
5615
5618
opus_encoder_ctl (participant -> encoder , OPUS_SET_INBAND_FEC (participant -> fec ));
5616
5619
}
5617
5620
/* Create the socket */
5621
+ janus_mutex_lock (& participant -> pmutex );
5622
+ janus_audiobridge_plainrtp_media_cleanup (& participant -> plainrtp_media );
5618
5623
if (janus_audiobridge_plainrtp_allocate_port (& participant -> plainrtp_media ) < 0 ) {
5619
5624
JANUS_LOG (LOG_ERR , "[AudioBridge-%p] Couldn't bind to local port\n" , session );
5620
5625
} else if (ip != NULL && port > 0 ) {
@@ -5647,6 +5652,7 @@ static void *janus_audiobridge_handler(void *data) {
5647
5652
}
5648
5653
}
5649
5654
}
5655
+ janus_mutex_unlock (& participant -> pmutex );
5650
5656
}
5651
5657
/* Finally, start the encoding thread if it hasn't already */
5652
5658
if (participant -> thread == NULL ) {
@@ -7492,7 +7498,9 @@ static void *janus_audiobridge_plainrtp_relay_thread(void *data) {
7492
7498
}
7493
7499
/* Cleanup the media session */
7494
7500
participant -> plainrtp_media .thread = NULL ;
7501
+ janus_mutex_lock (& participant -> pmutex );
7495
7502
janus_audiobridge_plainrtp_media_cleanup (& participant -> plainrtp_media );
7503
+ janus_mutex_unlock (& participant -> pmutex );
7496
7504
/* Done */
7497
7505
JANUS_LOG (LOG_INFO , "[AudioBridge-%p] Leaving Plain RTP participant thread\n" , session );
7498
7506
janus_refcount_decrease (& participant -> ref );
0 commit comments