@@ -2302,7 +2302,6 @@ json_t *janus_streaming_query_session(janus_plugin_session *handle) {
2302
2302
janus_mutex_unlock (& sessions_mutex );
2303
2303
/* What is this user watching, if anything? */
2304
2304
json_t * info = json_object ();
2305
- janus_mutex_lock (& session -> mutex );
2306
2305
janus_streaming_mountpoint * mp = session -> mountpoint ;
2307
2306
json_object_set_new (info , "state" , json_string (mp ? "watching" : "idle" ));
2308
2307
if (mp ) {
@@ -2340,7 +2339,6 @@ json_t *janus_streaming_query_session(janus_plugin_session *handle) {
2340
2339
}
2341
2340
janus_refcount_decrease (& mp -> ref );
2342
2341
}
2343
- janus_mutex_unlock (& session -> mutex );
2344
2342
json_object_set_new (info , "hangingup" , json_integer (g_atomic_int_get (& session -> hangingup )));
2345
2343
json_object_set_new (info , "destroyed" , json_integer (g_atomic_int_get (& session -> destroyed )));
2346
2344
janus_refcount_decrease (& session -> ref );
@@ -4404,6 +4402,8 @@ static void janus_streaming_hangup_media_internal(janus_plugin_session *handle)
4404
4402
session -> paused = FALSE;
4405
4403
janus_mutex_lock (& session -> mutex );
4406
4404
janus_streaming_mountpoint * mp = session -> mountpoint ;
4405
+ session -> mountpoint = NULL ;
4406
+ janus_mutex_unlock (& session -> mutex );
4407
4407
if (mp ) {
4408
4408
janus_mutex_lock (& mp -> mutex );
4409
4409
JANUS_LOG (LOG_VERB , " -- Removing the session from the mountpoint viewers\n" );
@@ -4434,8 +4434,6 @@ static void janus_streaming_hangup_media_internal(janus_plugin_session *handle)
4434
4434
}
4435
4435
janus_mutex_unlock (& mp -> mutex );
4436
4436
}
4437
- session -> mountpoint = NULL ;
4438
- janus_mutex_unlock (& session -> mutex );
4439
4437
g_atomic_int_set (& session -> hangingup , 0 );
4440
4438
}
4441
4439
@@ -4542,16 +4540,16 @@ static void *janus_streaming_handler(void *data) {
4542
4540
janus_mutex_unlock (& mountpoints_mutex );
4543
4541
goto error ;
4544
4542
}
4545
- janus_mutex_lock (& session -> mutex );
4546
4543
janus_mutex_lock (& mp -> mutex );
4544
+ janus_mutex_lock (& session -> mutex );
4547
4545
janus_mutex_unlock (& mountpoints_mutex );
4548
4546
/* Check if this is a new viewer, or if an update is taking place (i.e., ICE restart) */
4549
4547
if (do_restart ) {
4550
4548
/* User asked for an ICE restart: provide a new offer */
4551
4549
if (!g_atomic_int_compare_and_exchange (& session -> renegotiating , 0 , 1 )) {
4552
4550
/* Already triggered a renegotiation, and still waiting for an answer */
4553
- janus_mutex_unlock (& mp -> mutex );
4554
4551
janus_mutex_unlock (& session -> mutex );
4552
+ janus_mutex_unlock (& mp -> mutex );
4555
4553
JANUS_LOG (LOG_ERR , "Already renegotiating mountpoint %s\n" , session -> mountpoint -> id_str );
4556
4554
error_code = JANUS_STREAMING_ERROR_INVALID_STATE ;
4557
4555
g_snprintf (error_cause , 512 , "Already renegotiating mountpoint %s" , session -> mountpoint -> id_str );
@@ -4566,33 +4564,33 @@ static void *janus_streaming_handler(void *data) {
4566
4564
if (session -> mountpoint != NULL ) {
4567
4565
if (session -> mountpoint != mp ) {
4568
4566
/* Already watching something else */
4569
- janus_mutex_unlock (& mp -> mutex );
4570
4567
janus_refcount_decrease (& mp -> ref );
4571
4568
JANUS_LOG (LOG_ERR , "Already watching mountpoint %s\n" , session -> mountpoint -> id_str );
4572
4569
error_code = JANUS_STREAMING_ERROR_INVALID_STATE ;
4573
4570
g_snprintf (error_cause , 512 , "Already watching mountpoint %s" , session -> mountpoint -> id_str );
4574
4571
janus_mutex_unlock (& session -> mutex );
4572
+ janus_mutex_unlock (& mp -> mutex );
4575
4573
goto error ;
4576
4574
} else {
4577
4575
/* Make sure it's not an API error */
4578
4576
if (!session -> started ) {
4579
4577
/* Can't be a renegotiation, PeerConnection isn't up yet */
4580
- janus_mutex_unlock (& mp -> mutex );
4581
4578
JANUS_LOG (LOG_ERR , "Already watching mountpoint %s\n" , session -> mountpoint -> id_str );
4582
4579
error_code = JANUS_STREAMING_ERROR_INVALID_STATE ;
4583
4580
g_snprintf (error_cause , 512 , "Already watching mountpoint %s" , session -> mountpoint -> id_str );
4584
4581
janus_refcount_decrease (& mp -> ref );
4585
4582
janus_mutex_unlock (& session -> mutex );
4583
+ janus_mutex_unlock (& mp -> mutex );
4586
4584
goto error ;
4587
4585
}
4588
4586
if (!g_atomic_int_compare_and_exchange (& session -> renegotiating , 0 , 1 )) {
4589
4587
/* Already triggered a renegotiation, and still waiting for an answer */
4590
- janus_mutex_unlock (& mp -> mutex );
4591
4588
JANUS_LOG (LOG_ERR , "Already renegotiating mountpoint %s\n" , session -> mountpoint -> id_str );
4592
4589
error_code = JANUS_STREAMING_ERROR_INVALID_STATE ;
4593
4590
g_snprintf (error_cause , 512 , "Already renegotiating mountpoint %s" , session -> mountpoint -> id_str );
4594
4591
janus_refcount_decrease (& mp -> ref );
4595
4592
janus_mutex_unlock (& session -> mutex );
4593
+ janus_mutex_unlock (& mp -> mutex );
4596
4594
goto error ;
4597
4595
}
4598
4596
/* Simple renegotiation, remove the extra uneeded reference */
@@ -4605,9 +4603,9 @@ static void *janus_streaming_handler(void *data) {
4605
4603
/* New viewer: we send an offer ourselves */
4606
4604
JANUS_LOG (LOG_VERB , "Request to watch mountpoint/stream %s\n" , id_value_str );
4607
4605
if (session -> mountpoint != NULL || g_list_find (mp -> viewers , session ) != NULL ) {
4606
+ janus_mutex_unlock (& session -> mutex );
4608
4607
janus_mutex_unlock (& mp -> mutex );
4609
4608
janus_refcount_decrease (& mp -> ref );
4610
- janus_mutex_unlock (& session -> mutex );
4611
4609
JANUS_LOG (LOG_ERR , "Already watching a stream...\n" );
4612
4610
error_code = JANUS_STREAMING_ERROR_UNKNOWN_ERROR ;
4613
4611
g_snprintf (error_cause , 512 , "Already watching a stream" );
@@ -4631,9 +4629,9 @@ static void *janus_streaming_handler(void *data) {
4631
4629
(!mp -> video || !session -> video ) &&
4632
4630
(!mp -> data || !session -> data )) {
4633
4631
session -> mountpoint = NULL ;
4632
+ janus_mutex_unlock (& session -> mutex );
4634
4633
janus_mutex_unlock (& mp -> mutex );
4635
4634
janus_refcount_decrease (& mp -> ref );
4636
- janus_mutex_unlock (& session -> mutex );
4637
4635
JANUS_LOG (LOG_ERR , "Can't offer an SDP with no audio, video or data for this mountpoint\n" );
4638
4636
error_code = JANUS_STREAMING_ERROR_INVALID_REQUEST ;
4639
4637
g_snprintf (error_cause , 512 , "Can't offer an SDP with no audio, video or data for this mountpoint" );
@@ -4648,11 +4646,11 @@ static void *janus_streaming_handler(void *data) {
4648
4646
g_thread_try_new (tname , & janus_streaming_ondemand_thread , session , & error );
4649
4647
if (error != NULL ) {
4650
4648
session -> mountpoint = NULL ;
4651
- janus_mutex_unlock (& mp -> mutex );
4649
+ janus_mutex_unlock (& session -> mutex );
4652
4650
janus_refcount_decrease (& session -> ref ); /* This is for the failed thread */
4651
+ janus_mutex_unlock (& mp -> mutex );
4653
4652
janus_refcount_decrease (& mp -> ref ); /* This is for the failed thread */
4654
4653
janus_refcount_decrease (& mp -> ref );
4655
- janus_mutex_unlock (& session -> mutex );
4656
4654
JANUS_LOG (LOG_ERR , "Got error %d (%s) trying to launch the on-demand thread...\n" ,
4657
4655
error -> code , error -> message ? error -> message : "??" );
4658
4656
error_code = JANUS_STREAMING_ERROR_UNKNOWN_ERROR ;
@@ -4668,9 +4666,9 @@ static void *janus_streaming_handler(void *data) {
4668
4666
JANUS_STREAMING_ERROR_MISSING_ELEMENT , JANUS_STREAMING_ERROR_INVALID_ELEMENT );
4669
4667
if (error_code != 0 ) {
4670
4668
session -> mountpoint = NULL ;
4669
+ janus_mutex_unlock (& session -> mutex );
4671
4670
janus_mutex_unlock (& mp -> mutex );
4672
4671
janus_refcount_decrease (& mp -> ref );
4673
- janus_mutex_unlock (& session -> mutex );
4674
4672
goto error ;
4675
4673
}
4676
4674
/* In case this mountpoint is simulcasting, let's aim high by default */
@@ -4706,9 +4704,9 @@ static void *janus_streaming_handler(void *data) {
4706
4704
JANUS_STREAMING_ERROR_MISSING_ELEMENT , JANUS_STREAMING_ERROR_INVALID_ELEMENT );
4707
4705
if (error_code != 0 ) {
4708
4706
session -> mountpoint = NULL ;
4707
+ janus_mutex_unlock (& session -> mutex );
4709
4708
janus_mutex_unlock (& mp -> mutex );
4710
4709
janus_refcount_decrease (& mp -> ref );
4711
- janus_mutex_unlock (& session -> mutex );
4712
4710
goto error ;
4713
4711
}
4714
4712
/* In case this mountpoint is doing VP9-SVC, let's aim high by default */
@@ -4845,8 +4843,8 @@ static void *janus_streaming_handler(void *data) {
4845
4843
}
4846
4844
}
4847
4845
}
4848
- janus_mutex_unlock (& mp -> mutex );
4849
4846
janus_mutex_unlock (& session -> mutex );
4847
+ janus_mutex_unlock (& mp -> mutex );
4850
4848
} else if (!strcasecmp (request_text , "start" )) {
4851
4849
if (session -> mountpoint == NULL ) {
4852
4850
JANUS_LOG (LOG_VERB , "Can't start: no mountpoint set\n" );
@@ -5077,6 +5075,8 @@ static void *janus_streaming_handler(void *data) {
5077
5075
JANUS_LOG (LOG_VERB , "Request to switch to mountpoint/stream %s (old: %s)\n" , mp -> id_str , oldmp -> id_str );
5078
5076
session -> paused = TRUE;
5079
5077
/* Unsubscribe from the previous mountpoint and subscribe to the new one */
5078
+ session -> mountpoint = NULL ;
5079
+ janus_mutex_unlock (& session -> mutex );
5080
5080
janus_mutex_lock (& oldmp -> mutex );
5081
5081
oldmp -> viewers = g_list_remove_all (oldmp -> viewers , session );
5082
5082
/* Remove the viewer from the helper threads too, if any */
@@ -5100,6 +5100,7 @@ static void *janus_streaming_handler(void *data) {
5100
5100
janus_mutex_unlock (& oldmp -> mutex );
5101
5101
/* Subscribe to the new one */
5102
5102
janus_mutex_lock (& mp -> mutex );
5103
+ janus_mutex_lock (& session -> mutex );
5103
5104
mp -> viewers = g_list_append (mp -> viewers , session );
5104
5105
/* If we're using helper threads, add the viewer to one of those */
5105
5106
if (mp -> helper_threads > 0 ) {
@@ -5120,10 +5121,10 @@ static void *janus_streaming_handler(void *data) {
5120
5121
helper -> num_viewers ++ ;
5121
5122
janus_mutex_unlock (& helper -> mutex );
5122
5123
}
5123
- janus_mutex_unlock (& mp -> mutex );
5124
5124
session -> mountpoint = mp ;
5125
5125
session -> paused = FALSE;
5126
5126
janus_mutex_unlock (& session -> mutex );
5127
+ janus_mutex_unlock (& mp -> mutex );
5127
5128
/* Done */
5128
5129
janus_refcount_decrease (& oldmp -> ref ); /* This is for the request being done with it */
5129
5130
result = json_object ();
0 commit comments