@@ -5733,11 +5733,11 @@ static void *janus_streaming_handler(void *data) {
5733
5733
janus_streaming_message_free (msg );
5734
5734
continue ;
5735
5735
}
5736
- janus_mutex_unlock (& sessions_mutex );
5737
5736
/* Handle request */
5738
5737
error_code = 0 ;
5739
5738
root = NULL ;
5740
5739
if (msg -> message == NULL ) {
5740
+ janus_mutex_unlock (& sessions_mutex );
5741
5741
JANUS_LOG (LOG_ERR , "No message??\n" );
5742
5742
error_code = JANUS_STREAMING_ERROR_NO_MESSAGE ;
5743
5743
g_snprintf (error_cause , 512 , "%s" , "No message??" );
@@ -5748,8 +5748,10 @@ static void *janus_streaming_handler(void *data) {
5748
5748
JANUS_VALIDATE_JSON_OBJECT (root , request_parameters ,
5749
5749
error_code , error_cause , TRUE,
5750
5750
JANUS_STREAMING_ERROR_MISSING_ELEMENT , JANUS_STREAMING_ERROR_INVALID_ELEMENT );
5751
- if (error_code != 0 )
5751
+ if (error_code != 0 ) {
5752
+ janus_mutex_unlock (& sessions_mutex );
5752
5753
goto error ;
5754
+ }
5753
5755
json_t * request = json_object_get (root , "request" );
5754
5756
const char * request_text = json_string_value (request );
5755
5757
json_t * result = NULL ;
@@ -5763,8 +5765,10 @@ static void *janus_streaming_handler(void *data) {
5763
5765
JANUS_VALIDATE_JSON_OBJECT (root , watch_parameters ,
5764
5766
error_code , error_cause , TRUE,
5765
5767
JANUS_STREAMING_ERROR_MISSING_ELEMENT , JANUS_STREAMING_ERROR_INVALID_ELEMENT );
5766
- if (error_code != 0 )
5768
+ if (error_code != 0 ) {
5769
+ janus_mutex_unlock (& sessions_mutex );
5767
5770
goto error ;
5771
+ }
5768
5772
if (!string_ids ) {
5769
5773
JANUS_VALIDATE_JSON_OBJECT (root , id_parameters ,
5770
5774
error_code , error_cause , TRUE,
@@ -5774,8 +5778,10 @@ static void *janus_streaming_handler(void *data) {
5774
5778
error_code , error_cause , TRUE,
5775
5779
JANUS_STREAMING_ERROR_MISSING_ELEMENT , JANUS_STREAMING_ERROR_INVALID_ELEMENT );
5776
5780
}
5777
- if (error_code != 0 )
5781
+ if (error_code != 0 ) {
5782
+ janus_mutex_unlock (& sessions_mutex );
5778
5783
goto error ;
5784
+ }
5779
5785
json_t * id = json_object_get (root , "id" );
5780
5786
guint64 id_value = 0 ;
5781
5787
char id_num [30 ], * id_value_str = NULL ;
@@ -5794,6 +5800,7 @@ static void *janus_streaming_handler(void *data) {
5794
5800
for (i = 0 ; i < json_array_size (mids ); i ++ ) {
5795
5801
json_t * s = json_array_get (mids , i );
5796
5802
if (!json_is_string (s )) {
5803
+ janus_mutex_unlock (& sessions_mutex );
5797
5804
error_code = JANUS_STREAMING_ERROR_INVALID_ELEMENT ;
5798
5805
g_snprintf (error_cause , 512 , "The media array must only contain strings (mid values)" );
5799
5806
goto error ;
@@ -5814,6 +5821,7 @@ static void *janus_streaming_handler(void *data) {
5814
5821
string_ids ? (gpointer )id_value_str : (gpointer )& id_value );
5815
5822
if (mp == NULL ) {
5816
5823
janus_mutex_unlock (& mountpoints_mutex );
5824
+ janus_mutex_unlock (& sessions_mutex );
5817
5825
JANUS_LOG (LOG_VERB , "No such mountpoint/stream %s\n" , id_value_str );
5818
5826
error_code = JANUS_STREAMING_ERROR_NO_SUCH_MOUNTPOINT ;
5819
5827
g_snprintf (error_cause , 512 , "No such mountpoint/stream %s" , id_value_str );
@@ -5826,6 +5834,7 @@ static void *janus_streaming_handler(void *data) {
5826
5834
if (error_code != 0 ) {
5827
5835
janus_refcount_decrease (& mp -> ref );
5828
5836
janus_mutex_unlock (& mountpoints_mutex );
5837
+ janus_mutex_unlock (& sessions_mutex );
5829
5838
goto error ;
5830
5839
}
5831
5840
janus_mutex_lock (& mp -> mutex );
@@ -5839,6 +5848,7 @@ static void *janus_streaming_handler(void *data) {
5839
5848
/* Already triggered a renegotiation, and still waiting for an answer */
5840
5849
janus_mutex_unlock (& session -> mutex );
5841
5850
janus_mutex_unlock (& mp -> mutex );
5851
+ janus_mutex_unlock (& sessions_mutex );
5842
5852
JANUS_LOG (LOG_ERR , "Already renegotiating mountpoint %s\n" , session -> mountpoint -> id_str );
5843
5853
error_code = JANUS_STREAMING_ERROR_INVALID_STATE ;
5844
5854
g_snprintf (error_cause , 512 , "Already renegotiating mountpoint %s" , session -> mountpoint -> id_str );
@@ -5858,6 +5868,7 @@ static void *janus_streaming_handler(void *data) {
5858
5868
g_snprintf (error_cause , 512 , "Already watching mountpoint %s" , session -> mountpoint -> id_str );
5859
5869
janus_mutex_unlock (& session -> mutex );
5860
5870
janus_mutex_unlock (& mp -> mutex );
5871
+ janus_mutex_unlock (& sessions_mutex );
5861
5872
janus_refcount_decrease (& mp -> ref );
5862
5873
goto error ;
5863
5874
} else {
@@ -5870,6 +5881,7 @@ static void *janus_streaming_handler(void *data) {
5870
5881
janus_refcount_decrease (& mp -> ref );
5871
5882
janus_mutex_unlock (& session -> mutex );
5872
5883
janus_mutex_unlock (& mp -> mutex );
5884
+ janus_mutex_unlock (& sessions_mutex );
5873
5885
goto error ;
5874
5886
}
5875
5887
if (!g_atomic_int_compare_and_exchange (& session -> renegotiating , 0 , 1 )) {
@@ -5880,6 +5892,7 @@ static void *janus_streaming_handler(void *data) {
5880
5892
janus_refcount_decrease (& mp -> ref );
5881
5893
janus_mutex_unlock (& session -> mutex );
5882
5894
janus_mutex_unlock (& mp -> mutex );
5895
+ janus_mutex_unlock (& sessions_mutex );
5883
5896
goto error ;
5884
5897
}
5885
5898
/* Simple renegotiation, remove the extra uneeded reference */
@@ -5894,6 +5907,7 @@ static void *janus_streaming_handler(void *data) {
5894
5907
if (g_list_find (mp -> viewers , session ) != NULL ) {
5895
5908
janus_mutex_unlock (& session -> mutex );
5896
5909
janus_mutex_unlock (& mp -> mutex );
5910
+ janus_mutex_unlock (& sessions_mutex );
5897
5911
janus_refcount_decrease (& mp -> ref );
5898
5912
JANUS_LOG (LOG_ERR , "Already watching a stream (found %p in %s's viewers)...\n" , session , id_value_str );
5899
5913
error_code = JANUS_STREAMING_ERROR_UNKNOWN_ERROR ;
@@ -5926,6 +5940,7 @@ static void *janus_streaming_handler(void *data) {
5926
5940
session -> mountpoint = NULL ;
5927
5941
janus_mutex_unlock (& session -> mutex );
5928
5942
janus_mutex_unlock (& mp -> mutex );
5943
+ janus_mutex_unlock (& sessions_mutex );
5929
5944
janus_refcount_decrease (& mp -> ref );
5930
5945
JANUS_LOG (LOG_ERR , "Can't offer an SDP with no audio, video or data for this mountpoint\n" );
5931
5946
error_code = JANUS_STREAMING_ERROR_INVALID_REQUEST ;
@@ -5959,6 +5974,7 @@ static void *janus_streaming_handler(void *data) {
5959
5974
janus_mutex_unlock (& session -> mutex );
5960
5975
janus_refcount_decrease (& session -> ref ); /* This is for the failed thread */
5961
5976
janus_mutex_unlock (& mp -> mutex );
5977
+ janus_mutex_unlock (& sessions_mutex );
5962
5978
janus_refcount_decrease (& mp -> ref ); /* This is for the failed thread */
5963
5979
janus_refcount_decrease (& mp -> ref );
5964
5980
JANUS_LOG (LOG_ERR , "Got error %d (%s) trying to launch the on-demand thread...\n" ,
@@ -6018,7 +6034,8 @@ static void *janus_streaming_handler(void *data) {
6018
6034
session -> mountpoint = NULL ;
6019
6035
janus_mutex_unlock (& session -> mutex );
6020
6036
janus_mutex_unlock (& mp -> mutex );
6021
- janus_refcount_decrease (& mp -> ref );
6037
+ janus_mutex_unlock (& sessions_mutex );
6038
+ janus_refcount_decrease (& mp -> ref );
6022
6039
goto error ;
6023
6040
}
6024
6041
/* In case this mountpoint is simulcasting, let's aim high by default */
@@ -6057,6 +6074,7 @@ static void *janus_streaming_handler(void *data) {
6057
6074
session -> mountpoint = NULL ;
6058
6075
janus_mutex_unlock (& session -> mutex );
6059
6076
janus_mutex_unlock (& mp -> mutex );
6077
+ janus_mutex_unlock (& sessions_mutex );
6060
6078
janus_refcount_decrease (& mp -> ref );
6061
6079
goto error ;
6062
6080
}
@@ -6202,10 +6220,12 @@ static void *janus_streaming_handler(void *data) {
6202
6220
}
6203
6221
janus_mutex_unlock (& session -> mutex );
6204
6222
janus_mutex_unlock (& mp -> mutex );
6223
+ janus_mutex_unlock (& sessions_mutex );
6205
6224
} else if (!strcasecmp (request_text , "watch" ) && jsep_sdp != NULL ) {
6206
6225
/* New subscriber provided an offer, plugin will answer */
6207
6226
if (sdp_type == NULL || strcasecmp (sdp_type , "offer" )) {
6208
6227
/* This isn't an offer, respond with an error */
6228
+ janus_mutex_unlock (& sessions_mutex );
6209
6229
JANUS_LOG (LOG_ERR , "User provided SDP for a watch request must be an offer\n" );
6210
6230
error_code = JANUS_STREAMING_ERROR_INVALID_SDP ;
6211
6231
g_snprintf (error_cause , 512 , "User provided SDP for a watch request must be an offer" );
@@ -6214,6 +6234,7 @@ static void *janus_streaming_handler(void *data) {
6214
6234
char error_str [512 ];
6215
6235
janus_sdp * parsed_sdp = janus_sdp_parse (jsep_sdp , error_str , sizeof (error_str ));
6216
6236
if (parsed_sdp == NULL ) {
6237
+ janus_mutex_unlock (& sessions_mutex );
6217
6238
JANUS_LOG (LOG_ERR , "Error parsing SDP: %s\n" , error_str );
6218
6239
error_code = JANUS_STREAMING_ERROR_INVALID_SDP ;
6219
6240
g_snprintf (error_cause , 512 , "Error parsing SDP: %s" , error_str );
@@ -6226,6 +6247,7 @@ static void *janus_streaming_handler(void *data) {
6226
6247
error_code , error_cause , TRUE,
6227
6248
JANUS_STREAMING_ERROR_MISSING_ELEMENT , JANUS_STREAMING_ERROR_INVALID_ELEMENT );
6228
6249
if (error_code != 0 ) {
6250
+ janus_mutex_unlock (& sessions_mutex );
6229
6251
janus_sdp_destroy (parsed_sdp );
6230
6252
goto error ;
6231
6253
}
@@ -6239,6 +6261,7 @@ static void *janus_streaming_handler(void *data) {
6239
6261
JANUS_STREAMING_ERROR_MISSING_ELEMENT , JANUS_STREAMING_ERROR_INVALID_ELEMENT );
6240
6262
}
6241
6263
if (error_code != 0 ) {
6264
+ janus_mutex_unlock (& sessions_mutex );
6242
6265
janus_sdp_destroy (parsed_sdp );
6243
6266
goto error ;
6244
6267
}
@@ -6258,6 +6281,7 @@ static void *janus_streaming_handler(void *data) {
6258
6281
string_ids ? (gpointer )id_value_str : (gpointer )& id_value );
6259
6282
if (mp == NULL ) {
6260
6283
janus_mutex_unlock (& mountpoints_mutex );
6284
+ janus_mutex_unlock (& sessions_mutex );
6261
6285
janus_sdp_destroy (parsed_sdp );
6262
6286
JANUS_LOG (LOG_VERB , "No such mountpoint/stream %s\n" , id_value_str );
6263
6287
error_code = JANUS_STREAMING_ERROR_NO_SUCH_MOUNTPOINT ;
@@ -6271,6 +6295,7 @@ static void *janus_streaming_handler(void *data) {
6271
6295
if (error_code != 0 ) {
6272
6296
janus_refcount_decrease (& mp -> ref );
6273
6297
janus_mutex_unlock (& mountpoints_mutex );
6298
+ janus_mutex_unlock (& sessions_mutex );
6274
6299
janus_sdp_destroy (parsed_sdp );
6275
6300
goto error ;
6276
6301
}
@@ -6284,13 +6309,15 @@ static void *janus_streaming_handler(void *data) {
6284
6309
g_snprintf (error_cause , 512 , "Already watching mountpoint %s" , session -> mountpoint -> id_str );
6285
6310
janus_mutex_unlock (& session -> mutex );
6286
6311
janus_mutex_unlock (& mp -> mutex );
6312
+ janus_mutex_unlock (& sessions_mutex );
6287
6313
janus_refcount_decrease (& mp -> ref );
6288
6314
janus_sdp_destroy (parsed_sdp );
6289
6315
goto error ;
6290
6316
}
6291
6317
if (g_list_find (mp -> viewers , session ) != NULL ) {
6292
6318
janus_mutex_unlock (& session -> mutex );
6293
6319
janus_mutex_unlock (& mp -> mutex );
6320
+ janus_mutex_unlock (& sessions_mutex );
6294
6321
janus_refcount_decrease (& mp -> ref );
6295
6322
JANUS_LOG (LOG_ERR , "Already watching a stream (found %p in %s's viewers)...\n" , session , id_value_str );
6296
6323
error_code = JANUS_STREAMING_ERROR_UNKNOWN_ERROR ;
@@ -6495,7 +6522,9 @@ static void *janus_streaming_handler(void *data) {
6495
6522
janus_refcount_increase (& session -> ref );
6496
6523
janus_mutex_unlock (& session -> mutex );
6497
6524
janus_mutex_unlock (& mp -> mutex );
6525
+ janus_mutex_unlock (& sessions_mutex );
6498
6526
} else if (!strcasecmp (request_text , "start" )) {
6527
+ janus_mutex_unlock (& sessions_mutex );
6499
6528
if (session -> mountpoint == NULL ) {
6500
6529
JANUS_LOG (LOG_VERB , "Can't start: no mountpoint set\n" );
6501
6530
error_code = JANUS_STREAMING_ERROR_NO_SUCH_MOUNTPOINT ;
@@ -6529,6 +6558,7 @@ static void *janus_streaming_handler(void *data) {
6529
6558
gateway -> notify_event (& janus_streaming_plugin , session -> handle , info );
6530
6559
}
6531
6560
} else if (!strcasecmp (request_text , "pause" )) {
6561
+ janus_mutex_unlock (& sessions_mutex );
6532
6562
if (session -> mountpoint == NULL ) {
6533
6563
JANUS_LOG (LOG_VERB , "Can't pause: no mountpoint set\n" );
6534
6564
error_code = JANUS_STREAMING_ERROR_NO_SUCH_MOUNTPOINT ;
@@ -6549,6 +6579,7 @@ static void *janus_streaming_handler(void *data) {
6549
6579
gateway -> notify_event (& janus_streaming_plugin , session -> handle , info );
6550
6580
}
6551
6581
} else if (!strcasecmp (request_text , "configure" )) {
6582
+ janus_mutex_unlock (& sessions_mutex );
6552
6583
janus_streaming_mountpoint * mp = session -> mountpoint ;
6553
6584
if (mp == NULL ) {
6554
6585
JANUS_LOG (LOG_VERB , "Can't configure: not on a mountpoint\n" );
@@ -6563,7 +6594,7 @@ static void *janus_streaming_handler(void *data) {
6563
6594
json_t * audio = json_object_get (root , "audio" );
6564
6595
json_t * video = json_object_get (root , "video" );
6565
6596
json_t * data = json_object_get (root , "data" );
6566
-
6597
+
6567
6598
/* We use an array of streams to state the changes we want to make,
6568
6599
* were for each stream we specify the 'mid' to impact (e.g., send) */
6569
6600
json_t * streams = json_object_get (root , "streams" );
@@ -6604,7 +6635,7 @@ static void *janus_streaming_handler(void *data) {
6604
6635
json_array_append_new (streams , stream );
6605
6636
json_object_set_new (root , "streams" , streams );
6606
6637
}
6607
-
6638
+
6608
6639
size_t i = 0 ;
6609
6640
size_t streams_size = json_array_size (streams );
6610
6641
for (i = 0 ; i < streams_size ; i ++ ) {
@@ -6651,7 +6682,7 @@ static void *janus_streaming_handler(void *data) {
6651
6682
if (error_code != 0 ) {
6652
6683
goto error ;
6653
6684
}
6654
-
6685
+
6655
6686
if (mp -> streaming_source == janus_streaming_source_rtp ) {
6656
6687
/* Enforce the requested changes */
6657
6688
for (i = 0 ; i < json_array_size (streams ); i ++ ) {
@@ -6811,6 +6842,7 @@ static void *janus_streaming_handler(void *data) {
6811
6842
janus_streaming_mountpoint * oldmp = session -> mountpoint ;
6812
6843
if (oldmp == NULL ) {
6813
6844
janus_mutex_unlock (& session -> mutex );
6845
+ janus_mutex_unlock (& sessions_mutex );
6814
6846
JANUS_LOG (LOG_VERB , "Can't switch: not on a mountpoint\n" );
6815
6847
error_code = JANUS_STREAMING_ERROR_NO_SUCH_MOUNTPOINT ;
6816
6848
g_snprintf (error_cause , 512 , "Can't switch: not on a mountpoint" );
@@ -6819,6 +6851,7 @@ static void *janus_streaming_handler(void *data) {
6819
6851
if (oldmp -> streaming_type != janus_streaming_type_live ||
6820
6852
oldmp -> streaming_source != janus_streaming_source_rtp ) {
6821
6853
janus_mutex_unlock (& session -> mutex );
6854
+ janus_mutex_unlock (& sessions_mutex );
6822
6855
JANUS_LOG (LOG_VERB , "Can't switch: not on a live RTP mountpoint\n" );
6823
6856
error_code = JANUS_STREAMING_ERROR_CANT_SWITCH ;
6824
6857
g_snprintf (error_cause , 512 , "Can't switch: not on a live RTP mountpoint" );
@@ -6836,6 +6869,7 @@ static void *janus_streaming_handler(void *data) {
6836
6869
}
6837
6870
if (error_code != 0 ) {
6838
6871
janus_mutex_unlock (& session -> mutex );
6872
+ janus_mutex_unlock (& sessions_mutex );
6839
6873
janus_refcount_decrease (& oldmp -> ref );
6840
6874
goto error ;
6841
6875
}
@@ -6855,6 +6889,7 @@ static void *janus_streaming_handler(void *data) {
6855
6889
if (mp == NULL || g_atomic_int_get (& mp -> destroyed )) {
6856
6890
janus_mutex_unlock (& mountpoints_mutex );
6857
6891
janus_mutex_unlock (& session -> mutex );
6892
+ janus_mutex_unlock (& sessions_mutex );
6858
6893
JANUS_LOG (LOG_VERB , "No such mountpoint/stream %s\n" , id_value_str );
6859
6894
error_code = JANUS_STREAMING_ERROR_NO_SUCH_MOUNTPOINT ;
6860
6895
g_snprintf (error_cause , 512 , "No such mountpoint/stream %s" , id_value_str );
@@ -6867,6 +6902,7 @@ static void *janus_streaming_handler(void *data) {
6867
6902
janus_refcount_decrease (& mp -> ref );
6868
6903
janus_mutex_unlock (& mountpoints_mutex );
6869
6904
janus_mutex_unlock (& session -> mutex );
6905
+ janus_mutex_unlock (& sessions_mutex );
6870
6906
JANUS_LOG (LOG_VERB , "Can't switch: target is not a live RTP mountpoint\n" );
6871
6907
error_code = JANUS_STREAMING_ERROR_CANT_SWITCH ;
6872
6908
g_snprintf (error_cause , 512 , "Can't switch: target is not a live RTP mountpoint" );
@@ -6937,6 +6973,7 @@ static void *janus_streaming_handler(void *data) {
6937
6973
g_atomic_int_set (& session -> paused , 0 );
6938
6974
janus_mutex_unlock (& session -> mutex );
6939
6975
janus_mutex_unlock (& mp -> mutex );
6976
+ janus_mutex_unlock (& sessions_mutex );
6940
6977
/* Done with the request, remove the references we took for that */
6941
6978
janus_refcount_decrease (& oldmp -> ref );
6942
6979
janus_refcount_decrease (& mp -> ref );
@@ -6951,6 +6988,7 @@ static void *janus_streaming_handler(void *data) {
6951
6988
gateway -> notify_event (& janus_streaming_plugin , session -> handle , info );
6952
6989
}
6953
6990
} else if (!strcasecmp (request_text , "stop" )) {
6991
+ janus_mutex_unlock (& sessions_mutex );
6954
6992
if (g_atomic_int_get (& session -> stopping ) || !g_atomic_int_get (& session -> started )) {
6955
6993
/* Been there, done that: ignore */
6956
6994
janus_streaming_message_free (msg );
@@ -6971,6 +7009,7 @@ static void *janus_streaming_handler(void *data) {
6971
7009
/* Tell the core to tear down the PeerConnection, hangup_media will do the rest */
6972
7010
gateway -> close_pc (session -> handle );
6973
7011
} else {
7012
+ janus_mutex_unlock (& sessions_mutex );
6974
7013
JANUS_LOG (LOG_VERB , "Unknown request '%s'\n" , request_text );
6975
7014
error_code = JANUS_STREAMING_ERROR_INVALID_REQUEST ;
6976
7015
g_snprintf (error_cause , 512 , "Unknown request '%s'" , request_text );
0 commit comments