summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormannol <eniz_vukovic@hotmail.com>2014-07-05 17:36:12 +0200
committermannol <eniz_vukovic@hotmail.com>2014-07-05 17:36:12 +0200
commit9af7c335e7f198e6ac2ebe7554be2b30ffcbfbb4 (patch)
tree0a76a98410dc4221a618cfe5c305bfd25cd4c78f
parentebdc236d51b569b4817771fe0251ee86c1fee257 (diff)
This might be causing problems
-rw-r--r--toxav/msi.c108
-rw-r--r--toxav/msi.h4
-rw-r--r--toxav/toxav.c42
3 files changed, 77 insertions, 77 deletions
diff --git a/toxav/msi.c b/toxav/msi.c
index 71a138d2..999f86b6 100644
--- a/toxav/msi.c
+++ b/toxav/msi.c
@@ -1082,7 +1082,7 @@ MSICall *init_call ( MSISession *session, int peers, int ringing_timeout )
1082 1082
1083 call->ringing_tout_ms = ringing_timeout; 1083 call->ringing_tout_ms = ringing_timeout;
1084 1084
1085 pthread_mutex_init ( call->mutex, NULL ); 1085 pthread_mutex_init ( &call->mutex, NULL );
1086 1086
1087 LOGGER_DEBUG("Started new call with index: %u", call_idx); 1087 LOGGER_DEBUG("Started new call with index: %u", call_idx);
1088 return call; 1088 return call;
@@ -1104,7 +1104,7 @@ int terminate_call ( MSISession *session, MSICall *call )
1104 return -1; 1104 return -1;
1105 } 1105 }
1106 1106
1107 int rc = pthread_mutex_trylock(session->mutex); /* Lock if not locked */ 1107 int rc = pthread_mutex_trylock(&session->mutex); /* Lock if not locked */
1108 1108
1109 LOGGER_DEBUG("Terminated call id: %d", call->call_idx); 1109 LOGGER_DEBUG("Terminated call id: %d", call->call_idx);
1110 /* Check event loop and cancel timed events if there are any 1110 /* Check event loop and cancel timed events if there are any
@@ -1115,7 +1115,7 @@ int terminate_call ( MSISession *session, MSICall *call )
1115 timer_release ( session->timer_handler, call->ringing_timer_id ); 1115 timer_release ( session->timer_handler, call->ringing_timer_id );
1116 1116
1117 /* Get a handle */ 1117 /* Get a handle */
1118 pthread_mutex_lock ( call->mutex ); 1118 pthread_mutex_lock ( &call->mutex );
1119 1119
1120 session->calls[call->call_idx] = NULL; 1120 session->calls[call->call_idx] = NULL;
1121 1121
@@ -1123,14 +1123,14 @@ int terminate_call ( MSISession *session, MSICall *call )
1123 free ( call->peers); 1123 free ( call->peers);
1124 1124
1125 /* Release handle */ 1125 /* Release handle */
1126 pthread_mutex_unlock ( call->mutex ); 1126 pthread_mutex_unlock ( &call->mutex );
1127 1127
1128 pthread_mutex_destroy ( call->mutex ); 1128 pthread_mutex_destroy ( &call->mutex );
1129 1129
1130 free ( call ); 1130 free ( call );
1131 1131
1132 if ( rc != EBUSY ) /* Unlock if locked by this call */ 1132 if ( rc != EBUSY ) /* Unlock if locked by this call */
1133 pthread_mutex_unlock(session->mutex); 1133 pthread_mutex_unlock(&session->mutex);
1134 1134
1135 return 0; 1135 return 0;
1136} 1136}
@@ -1174,7 +1174,7 @@ int handle_recv_invite ( MSISession *session, MSICall *call, MSIMessage *msg )
1174{ 1174{
1175 LOGGER_DEBUG("Session: %p Handling 'invite' on call: %s", session, call ? (char *)call->id : "making new"); 1175 LOGGER_DEBUG("Session: %p Handling 'invite' on call: %s", session, call ? (char *)call->id : "making new");
1176 1176
1177 pthread_mutex_lock(session->mutex); 1177 pthread_mutex_lock(&session->mutex);
1178 1178
1179 1179
1180 if ( call ) { 1180 if ( call ) {
@@ -1194,27 +1194,27 @@ int handle_recv_invite ( MSISession *session, MSICall *call, MSIMessage *msg )
1194 call = init_call ( session, 1, 0 ); 1194 call = init_call ( session, 1, 0 );
1195 1195
1196 if ( !call ) { 1196 if ( !call ) {
1197 pthread_mutex_unlock(session->mutex); 1197 pthread_mutex_unlock(&session->mutex);
1198 LOGGER_ERROR("Starting call"); 1198 LOGGER_ERROR("Starting call");
1199 return 0; 1199 return 0;
1200 } 1200 }
1201 1201
1202 } else { 1202 } else {
1203 pthread_mutex_unlock(session->mutex); 1203 pthread_mutex_unlock(&session->mutex);
1204 return 0; /* Wait for ringing from peer */ 1204 return 0; /* Wait for ringing from peer */
1205 } 1205 }
1206 1206
1207 } else { 1207 } else {
1208 send_error ( session, call, error_busy, msg->friend_id ); /* TODO: Ugh*/ 1208 send_error ( session, call, error_busy, msg->friend_id ); /* TODO: Ugh*/
1209 terminate_call(session, call); 1209 terminate_call(session, call);
1210 pthread_mutex_unlock(session->mutex); 1210 pthread_mutex_unlock(&session->mutex);
1211 return 0; 1211 return 0;
1212 } 1212 }
1213 } else { 1213 } else {
1214 call = init_call ( session, 1, 0 ); 1214 call = init_call ( session, 1, 0 );
1215 1215
1216 if ( !call ) { 1216 if ( !call ) {
1217 pthread_mutex_unlock(session->mutex); 1217 pthread_mutex_unlock(&session->mutex);
1218 LOGGER_ERROR("Starting call"); 1218 LOGGER_ERROR("Starting call");
1219 return 0; 1219 return 0;
1220 } 1220 }
@@ -1223,7 +1223,7 @@ int handle_recv_invite ( MSISession *session, MSICall *call, MSIMessage *msg )
1223 if ( !msg->callid.header_value ) { 1223 if ( !msg->callid.header_value ) {
1224 send_error ( session, call, error_no_callid, msg->friend_id ); 1224 send_error ( session, call, error_no_callid, msg->friend_id );
1225 terminate_call(session, call); 1225 terminate_call(session, call);
1226 pthread_mutex_unlock(session->mutex); 1226 pthread_mutex_unlock(&session->mutex);
1227 return 0; 1227 return 0;
1228 } 1228 }
1229 1229
@@ -1238,7 +1238,7 @@ int handle_recv_invite ( MSISession *session, MSICall *call, MSIMessage *msg )
1238 send_message ( session, call, _msg_ringing, msg->friend_id ); 1238 send_message ( session, call, _msg_ringing, msg->friend_id );
1239 free_message ( _msg_ringing ); 1239 free_message ( _msg_ringing );
1240 1240
1241 pthread_mutex_unlock(session->mutex); 1241 pthread_mutex_unlock(&session->mutex);
1242 1242
1243 invoke_callback(call->call_idx, MSI_OnInvite); 1243 invoke_callback(call->call_idx, MSI_OnInvite);
1244 1244
@@ -1253,13 +1253,13 @@ int handle_recv_start ( MSISession *session, MSICall *call, MSIMessage *msg )
1253 1253
1254 LOGGER_DEBUG("Session: %p Handling 'start' on call: %s, friend id: %d", session, call->id, msg->friend_id ); 1254 LOGGER_DEBUG("Session: %p Handling 'start' on call: %s, friend id: %d", session, call->id, msg->friend_id );
1255 1255
1256 pthread_mutex_lock(session->mutex); 1256 pthread_mutex_lock(&session->mutex);
1257 1257
1258 call->state = call_active; 1258 call->state = call_active;
1259 1259
1260 flush_peer_type ( call, msg, 0 ); 1260 flush_peer_type ( call, msg, 0 );
1261 1261
1262 pthread_mutex_unlock(session->mutex); 1262 pthread_mutex_unlock(&session->mutex);
1263 1263
1264 invoke_callback(call->call_idx, MSI_OnStart); 1264 invoke_callback(call->call_idx, MSI_OnStart);
1265 return 1; 1265 return 1;
@@ -1273,14 +1273,14 @@ int handle_recv_reject ( MSISession *session, MSICall *call, MSIMessage *msg )
1273 1273
1274 LOGGER_DEBUG("Session: %p Handling 'reject' on call: %s", session, call->id); 1274 LOGGER_DEBUG("Session: %p Handling 'reject' on call: %s", session, call->id);
1275 1275
1276 pthread_mutex_lock(session->mutex); 1276 pthread_mutex_lock(&session->mutex);
1277 1277
1278 MSIMessage *_msg_ending = msi_new_message ( TYPE_RESPONSE, stringify_response ( ending ) ); 1278 MSIMessage *_msg_ending = msi_new_message ( TYPE_RESPONSE, stringify_response ( ending ) );
1279 send_message ( session, call, _msg_ending, msg->friend_id ); 1279 send_message ( session, call, _msg_ending, msg->friend_id );
1280 free_message ( _msg_ending ); 1280 free_message ( _msg_ending );
1281 1281
1282 1282
1283 pthread_mutex_unlock(session->mutex); 1283 pthread_mutex_unlock(&session->mutex);
1284 1284
1285 invoke_callback(call->call_idx, MSI_OnReject); 1285 invoke_callback(call->call_idx, MSI_OnReject);
1286 1286
@@ -1296,11 +1296,11 @@ int handle_recv_cancel ( MSISession *session, MSICall *call, MSIMessage *msg )
1296 1296
1297 LOGGER_DEBUG("Session: %p Handling 'cancel' on call: %s", session, call->id ); 1297 LOGGER_DEBUG("Session: %p Handling 'cancel' on call: %s", session, call->id );
1298 1298
1299 pthread_mutex_lock(session->mutex); 1299 pthread_mutex_lock(&session->mutex);
1300 1300
1301 /* Act as end message */ 1301 /* Act as end message */
1302 1302
1303 pthread_mutex_unlock(session->mutex); 1303 pthread_mutex_unlock(&session->mutex);
1304 invoke_callback(call->call_idx, MSI_OnCancel); 1304 invoke_callback(call->call_idx, MSI_OnCancel);
1305 1305
1306 terminate_call ( session, call ); 1306 terminate_call ( session, call );
@@ -1315,13 +1315,13 @@ int handle_recv_end ( MSISession *session, MSICall *call, MSIMessage *msg )
1315 1315
1316 LOGGER_DEBUG("Session: %p Handling 'end' on call: %s", session, call->id ); 1316 LOGGER_DEBUG("Session: %p Handling 'end' on call: %s", session, call->id );
1317 1317
1318 pthread_mutex_lock(session->mutex); 1318 pthread_mutex_lock(&session->mutex);
1319 1319
1320 MSIMessage *_msg_ending = msi_new_message ( TYPE_RESPONSE, stringify_response ( ending ) ); 1320 MSIMessage *_msg_ending = msi_new_message ( TYPE_RESPONSE, stringify_response ( ending ) );
1321 send_message ( session, call, _msg_ending, msg->friend_id ); 1321 send_message ( session, call, _msg_ending, msg->friend_id );
1322 free_message ( _msg_ending ); 1322 free_message ( _msg_ending );
1323 1323
1324 pthread_mutex_unlock(session->mutex); 1324 pthread_mutex_unlock(&session->mutex);
1325 1325
1326 invoke_callback(call->call_idx, MSI_OnEnd); 1326 invoke_callback(call->call_idx, MSI_OnEnd);
1327 1327
@@ -1337,11 +1337,11 @@ int handle_recv_ringing ( MSISession *session, MSICall *call, MSIMessage *msg )
1337 return 0; 1337 return 0;
1338 } 1338 }
1339 1339
1340 pthread_mutex_lock(session->mutex); 1340 pthread_mutex_lock(&session->mutex);
1341 1341
1342 if ( call->ringing_timer_id ) { 1342 if ( call->ringing_timer_id ) {
1343 LOGGER_WARNING("Call already ringing"); 1343 LOGGER_WARNING("Call already ringing");
1344 pthread_mutex_unlock(session->mutex); 1344 pthread_mutex_unlock(&session->mutex);
1345 return 0; 1345 return 0;
1346 } 1346 }
1347 1347
@@ -1349,7 +1349,7 @@ int handle_recv_ringing ( MSISession *session, MSICall *call, MSIMessage *msg )
1349 1349
1350 call->ringing_timer_id = timer_alloc ( session->timer_handler, handle_timeout, call, call->ringing_tout_ms ); 1350 call->ringing_timer_id = timer_alloc ( session->timer_handler, handle_timeout, call, call->ringing_tout_ms );
1351 1351
1352 pthread_mutex_unlock(session->mutex); 1352 pthread_mutex_unlock(&session->mutex);
1353 1353
1354 invoke_callback(call->call_idx, MSI_OnRinging); 1354 invoke_callback(call->call_idx, MSI_OnRinging);
1355 return 1; 1355 return 1;
@@ -1361,7 +1361,7 @@ int handle_recv_starting ( MSISession *session, MSICall *call, MSIMessage *msg )
1361 return 0; 1361 return 0;
1362 } 1362 }
1363 1363
1364 pthread_mutex_lock(session->mutex); 1364 pthread_mutex_lock(&session->mutex);
1365 1365
1366 LOGGER_DEBUG("Session: %p Handling 'starting' on call: %s", session, call->id ); 1366 LOGGER_DEBUG("Session: %p Handling 'starting' on call: %s", session, call->id );
1367 1367
@@ -1375,7 +1375,7 @@ int handle_recv_starting ( MSISession *session, MSICall *call, MSIMessage *msg )
1375 1375
1376 1376
1377 timer_release ( session->timer_handler, call->ringing_timer_id ); 1377 timer_release ( session->timer_handler, call->ringing_timer_id );
1378 pthread_mutex_unlock(session->mutex); 1378 pthread_mutex_unlock(&session->mutex);
1379 1379
1380 invoke_callback(call->call_idx, MSI_OnStarting); 1380 invoke_callback(call->call_idx, MSI_OnStarting);
1381 return 1; 1381 return 1;
@@ -1387,14 +1387,14 @@ int handle_recv_ending ( MSISession *session, MSICall *call, MSIMessage *msg )
1387 return 0; 1387 return 0;
1388 } 1388 }
1389 1389
1390 pthread_mutex_lock(session->mutex); 1390 pthread_mutex_lock(&session->mutex);
1391 1391
1392 LOGGER_DEBUG("Session: %p Handling 'ending' on call: %s", session, call->id ); 1392 LOGGER_DEBUG("Session: %p Handling 'ending' on call: %s", session, call->id );
1393 1393
1394 /* Stop timer */ 1394 /* Stop timer */
1395 timer_release ( session->timer_handler, call->request_timer_id ); 1395 timer_release ( session->timer_handler, call->request_timer_id );
1396 1396
1397 pthread_mutex_unlock(session->mutex); 1397 pthread_mutex_unlock(&session->mutex);
1398 1398
1399 invoke_callback(call->call_idx, MSI_OnEnding); 1399 invoke_callback(call->call_idx, MSI_OnEnding);
1400 1400
@@ -1405,11 +1405,11 @@ int handle_recv_ending ( MSISession *session, MSICall *call, MSIMessage *msg )
1405} 1405}
1406int handle_recv_error ( MSISession *session, MSICall *call, MSIMessage *msg ) 1406int handle_recv_error ( MSISession *session, MSICall *call, MSIMessage *msg )
1407{ 1407{
1408 pthread_mutex_lock(session->mutex); 1408 pthread_mutex_lock(&session->mutex);
1409 1409
1410 if ( !call ) { 1410 if ( !call ) {
1411 LOGGER_WARNING("Handling 'error' on non-existing call!"); 1411 LOGGER_WARNING("Handling 'error' on non-existing call!");
1412 pthread_mutex_unlock(session->mutex); 1412 pthread_mutex_unlock(&session->mutex);
1413 return -1; 1413 return -1;
1414 } 1414 }
1415 1415
@@ -1422,7 +1422,7 @@ int handle_recv_error ( MSISession *session, MSICall *call, MSIMessage *msg )
1422 LOGGER_DEBUG("Error reason: %s", session->last_error_str); 1422 LOGGER_DEBUG("Error reason: %s", session->last_error_str);
1423 } 1423 }
1424 1424
1425 pthread_mutex_unlock(session->mutex); 1425 pthread_mutex_unlock(&session->mutex);
1426 1426
1427 invoke_callback(call->call_idx, MSI_OnEnding); 1427 invoke_callback(call->call_idx, MSI_OnEnding);
1428 1428
@@ -1631,7 +1631,7 @@ MSISession *msi_init_session ( Messenger *messenger, int32_t max_calls )
1631 /* This is called when remote terminates session */ 1631 /* This is called when remote terminates session */
1632 m_callback_connectionstatus_internal_av(messenger, handle_remote_connection_change, retu); 1632 m_callback_connectionstatus_internal_av(messenger, handle_remote_connection_change, retu);
1633 1633
1634 pthread_mutex_init(retu->mutex, NULL); 1634 pthread_mutex_init(&retu->mutex, NULL);
1635 1635
1636 LOGGER_DEBUG("New msi session: %p max calls: %u", retu, max_calls); 1636 LOGGER_DEBUG("New msi session: %p max calls: %u", retu, max_calls);
1637 return retu; 1637 return retu;
@@ -1651,9 +1651,9 @@ int msi_terminate_session ( MSISession *session )
1651 return -1; 1651 return -1;
1652 } 1652 }
1653 1653
1654 pthread_mutex_lock(session->mutex); 1654 pthread_mutex_lock(&session->mutex);
1655 m_callback_msi_packet((struct Messenger *) session->messenger_handle, NULL, NULL); 1655 m_callback_msi_packet((struct Messenger *) session->messenger_handle, NULL, NULL);
1656 pthread_mutex_unlock(session->mutex); 1656 pthread_mutex_unlock(&session->mutex);
1657 1657
1658 int _status = 0; 1658 int _status = 0;
1659 1659
@@ -1671,7 +1671,7 @@ int msi_terminate_session ( MSISession *session )
1671 1671
1672 timer_terminate_session(session->timer_handler); 1672 timer_terminate_session(session->timer_handler);
1673 1673
1674 pthread_mutex_destroy(session->mutex); 1674 pthread_mutex_destroy(&session->mutex);
1675 1675
1676 LOGGER_DEBUG("Terminated session: %p", session); 1676 LOGGER_DEBUG("Terminated session: %p", session);
1677 free ( session ); 1677 free ( session );
@@ -1690,7 +1690,7 @@ int msi_terminate_session ( MSISession *session )
1690 */ 1690 */
1691int msi_invite ( MSISession *session, int32_t *call_index, MSICallType call_type, uint32_t rngsec, uint32_t friend_id ) 1691int msi_invite ( MSISession *session, int32_t *call_index, MSICallType call_type, uint32_t rngsec, uint32_t friend_id )
1692{ 1692{
1693 pthread_mutex_lock(session->mutex); 1693 pthread_mutex_lock(&session->mutex);
1694 1694
1695 LOGGER_DEBUG("Session: %p Inviting friend: %u", session, friend_id); 1695 LOGGER_DEBUG("Session: %p Inviting friend: %u", session, friend_id);
1696 1696
@@ -1698,7 +1698,7 @@ int msi_invite ( MSISession *session, int32_t *call_index, MSICallType call_type
1698 MSICall *_call = init_call ( session, 1, rngsec ); /* Just one peer for now */ 1698 MSICall *_call = init_call ( session, 1, rngsec ); /* Just one peer for now */
1699 1699
1700 if ( !_call ) { 1700 if ( !_call ) {
1701 pthread_mutex_unlock(session->mutex); 1701 pthread_mutex_unlock(&session->mutex);
1702 LOGGER_ERROR("Cannot handle more calls"); 1702 LOGGER_ERROR("Cannot handle more calls");
1703 return -1; 1703 return -1;
1704 } 1704 }
@@ -1729,7 +1729,7 @@ int msi_invite ( MSISession *session, int32_t *call_index, MSICallType call_type
1729 1729
1730 LOGGER_DEBUG("Invite sent"); 1730 LOGGER_DEBUG("Invite sent");
1731 1731
1732 pthread_mutex_unlock(session->mutex); 1732 pthread_mutex_unlock(&session->mutex);
1733 1733
1734 return 0; 1734 return 0;
1735} 1735}
@@ -1746,18 +1746,18 @@ int msi_invite ( MSISession *session, int32_t *call_index, MSICallType call_type
1746 */ 1746 */
1747int msi_hangup ( MSISession *session, int32_t call_index ) 1747int msi_hangup ( MSISession *session, int32_t call_index )
1748{ 1748{
1749 pthread_mutex_lock(session->mutex); 1749 pthread_mutex_lock(&session->mutex);
1750 LOGGER_DEBUG("Session: %p Hanging up call: %u", session, call_index); 1750 LOGGER_DEBUG("Session: %p Hanging up call: %u", session, call_index);
1751 1751
1752 if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ) { 1752 if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ) {
1753 LOGGER_ERROR("Invalid call index!"); 1753 LOGGER_ERROR("Invalid call index!");
1754 pthread_mutex_unlock(session->mutex); 1754 pthread_mutex_unlock(&session->mutex);
1755 return -1; 1755 return -1;
1756 } 1756 }
1757 1757
1758 if ( !session->calls[call_index] || session->calls[call_index]->state != call_active ) { 1758 if ( !session->calls[call_index] || session->calls[call_index]->state != call_active ) {
1759 LOGGER_ERROR("No call with such index or call is not active!"); 1759 LOGGER_ERROR("No call with such index or call is not active!");
1760 pthread_mutex_unlock(session->mutex); 1760 pthread_mutex_unlock(&session->mutex);
1761 return -1; 1761 return -1;
1762 } 1762 }
1763 1763
@@ -1776,7 +1776,7 @@ int msi_hangup ( MSISession *session, int32_t call_index )
1776 session->calls[call_index]->request_timer_id = 1776 session->calls[call_index]->request_timer_id =
1777 timer_alloc ( session->timer_handler, handle_timeout, session->calls[call_index], m_deftout ); 1777 timer_alloc ( session->timer_handler, handle_timeout, session->calls[call_index], m_deftout );
1778 1778
1779 pthread_mutex_unlock(session->mutex); 1779 pthread_mutex_unlock(&session->mutex);
1780 return 0; 1780 return 0;
1781} 1781}
1782 1782
@@ -1791,12 +1791,12 @@ int msi_hangup ( MSISession *session, int32_t call_index )
1791 */ 1791 */
1792int msi_answer ( MSISession *session, int32_t call_index, MSICallType call_type ) 1792int msi_answer ( MSISession *session, int32_t call_index, MSICallType call_type )
1793{ 1793{
1794 pthread_mutex_lock(session->mutex); 1794 pthread_mutex_lock(&session->mutex);
1795 LOGGER_DEBUG("Session: %p Answering call: %u", session, call_index); 1795 LOGGER_DEBUG("Session: %p Answering call: %u", session, call_index);
1796 1796
1797 if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ) { 1797 if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ) {
1798 LOGGER_ERROR("Invalid call index!"); 1798 LOGGER_ERROR("Invalid call index!");
1799 pthread_mutex_unlock(session->mutex); 1799 pthread_mutex_unlock(&session->mutex);
1800 return -1; 1800 return -1;
1801 } 1801 }
1802 1802
@@ -1818,7 +1818,7 @@ int msi_answer ( MSISession *session, int32_t call_index, MSICallType call_type
1818 1818
1819 session->calls[call_index]->state = call_active; 1819 session->calls[call_index]->state = call_active;
1820 1820
1821 pthread_mutex_unlock(session->mutex); 1821 pthread_mutex_unlock(&session->mutex);
1822 return 0; 1822 return 0;
1823} 1823}
1824 1824
@@ -1833,12 +1833,12 @@ int msi_answer ( MSISession *session, int32_t call_index, MSICallType call_type
1833 */ 1833 */
1834int msi_cancel ( MSISession *session, int32_t call_index, uint32_t peer, const char *reason ) 1834int msi_cancel ( MSISession *session, int32_t call_index, uint32_t peer, const char *reason )
1835{ 1835{
1836 pthread_mutex_lock(session->mutex); 1836 pthread_mutex_lock(&session->mutex);
1837 LOGGER_DEBUG("Session: %p Canceling call: %u; reason:", session, call_index, reason ? reason : "Unknown"); 1837 LOGGER_DEBUG("Session: %p Canceling call: %u; reason:", session, call_index, reason ? reason : "Unknown");
1838 1838
1839 if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ) { 1839 if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ) {
1840 LOGGER_ERROR("Invalid call index!"); 1840 LOGGER_ERROR("Invalid call index!");
1841 pthread_mutex_unlock(session->mutex); 1841 pthread_mutex_unlock(&session->mutex);
1842 return -1; 1842 return -1;
1843 } 1843 }
1844 1844
@@ -1852,7 +1852,7 @@ int msi_cancel ( MSISession *session, int32_t call_index, uint32_t peer, const c
1852 /*session->calls[call_index]->state = call_hanged_up; 1852 /*session->calls[call_index]->state = call_hanged_up;
1853 session->calls[call_index]->request_timer_id = timer_alloc ( handle_timeout, session->calls[call_index], m_deftout );*/ 1853 session->calls[call_index]->request_timer_id = timer_alloc ( handle_timeout, session->calls[call_index], m_deftout );*/
1854 terminate_call ( session, session->calls[call_index] ); 1854 terminate_call ( session, session->calls[call_index] );
1855 pthread_mutex_unlock(session->mutex); 1855 pthread_mutex_unlock(&session->mutex);
1856 1856
1857 return 0; 1857 return 0;
1858} 1858}
@@ -1867,12 +1867,12 @@ int msi_cancel ( MSISession *session, int32_t call_index, uint32_t peer, const c
1867 */ 1867 */
1868int msi_reject ( MSISession *session, int32_t call_index, const uint8_t *reason ) 1868int msi_reject ( MSISession *session, int32_t call_index, const uint8_t *reason )
1869{ 1869{
1870 pthread_mutex_lock(session->mutex); 1870 pthread_mutex_lock(&session->mutex);
1871 LOGGER_DEBUG("Session: %p Rejecting call: %u; reason:", session, call_index, reason ? (char *)reason : "Unknown"); 1871 LOGGER_DEBUG("Session: %p Rejecting call: %u; reason:", session, call_index, reason ? (char *)reason : "Unknown");
1872 1872
1873 if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ) { 1873 if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ) {
1874 LOGGER_ERROR("Invalid call index!"); 1874 LOGGER_ERROR("Invalid call index!");
1875 pthread_mutex_unlock(session->mutex); 1875 pthread_mutex_unlock(&session->mutex);
1876 return -1; 1876 return -1;
1877 } 1877 }
1878 1878
@@ -1889,7 +1889,7 @@ int msi_reject ( MSISession *session, int32_t call_index, const uint8_t *reason
1889 session->calls[call_index]->request_timer_id = 1889 session->calls[call_index]->request_timer_id =
1890 timer_alloc ( session->timer_handler, handle_timeout, session->calls[call_index], m_deftout ); 1890 timer_alloc ( session->timer_handler, handle_timeout, session->calls[call_index], m_deftout );
1891 1891
1892 pthread_mutex_unlock(session->mutex); 1892 pthread_mutex_unlock(&session->mutex);
1893 return 0; 1893 return 0;
1894} 1894}
1895 1895
@@ -1903,11 +1903,11 @@ int msi_reject ( MSISession *session, int32_t call_index, const uint8_t *reason
1903 */ 1903 */
1904int msi_stopcall ( MSISession *session, int32_t call_index ) 1904int msi_stopcall ( MSISession *session, int32_t call_index )
1905{ 1905{
1906 pthread_mutex_lock(session->mutex); 1906 pthread_mutex_lock(&session->mutex);
1907 LOGGER_DEBUG("Session: %p Stopping call index: %u", session, call_index); 1907 LOGGER_DEBUG("Session: %p Stopping call index: %u", session, call_index);
1908 1908
1909 if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ) { 1909 if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ) {
1910 pthread_mutex_unlock(session->mutex); 1910 pthread_mutex_unlock(&session->mutex);
1911 return -1; 1911 return -1;
1912 } 1912 }
1913 1913
@@ -1915,6 +1915,6 @@ int msi_stopcall ( MSISession *session, int32_t call_index )
1915 1915
1916 terminate_call ( session, session->calls[call_index] ); 1916 terminate_call ( session, session->calls[call_index] );
1917 1917
1918 pthread_mutex_unlock(session->mutex); 1918 pthread_mutex_unlock(&session->mutex);
1919 return 0; 1919 return 0;
1920} 1920}
diff --git a/toxav/msi.h b/toxav/msi.h
index 428f7d9c..0020df4c 100644
--- a/toxav/msi.h
+++ b/toxav/msi.h
@@ -77,7 +77,7 @@ typedef struct _MSICall { /* Call info structure */
77 int ringing_timer_id; /* Timer id for ringing timeout */ 77 int ringing_timer_id; /* Timer id for ringing timeout */
78 78
79 79
80 pthread_mutex_t mutex[1]; /* */ 80 pthread_mutex_t mutex; /* */
81 uint32_t *peers; 81 uint32_t *peers;
82 uint16_t peer_count; 82 uint16_t peer_count;
83 83
@@ -104,7 +104,7 @@ typedef struct _MSISession {
104 uint32_t frequ; 104 uint32_t frequ;
105 uint32_t call_timeout; /* Time of the timeout for some action to end; 0 if infinite */ 105 uint32_t call_timeout; /* Time of the timeout for some action to end; 0 if infinite */
106 106
107 pthread_mutex_t mutex[1]; 107 pthread_mutex_t mutex;
108 108
109 void *timer_handler; 109 void *timer_handler;
110} MSISession; 110} MSISession;
diff --git a/toxav/toxav.c b/toxav/toxav.c
index 6ffef077..36053fd5 100644
--- a/toxav/toxav.c
+++ b/toxav/toxav.c
@@ -68,7 +68,7 @@ typedef struct _CallSpecific {
68 void *frame_buf; /* buffer for split video payloads */ 68 void *frame_buf; /* buffer for split video payloads */
69 69
70 _Bool call_active; 70 _Bool call_active;
71 pthread_mutex_t mutex[1]; 71 pthread_mutex_t mutex;
72} CallSpecific; 72} CallSpecific;
73 73
74 74
@@ -354,7 +354,7 @@ int toxav_prepare_transmission ( ToxAv *av, int32_t call_index, ToxAvCodecSettin
354 codec_settings->video_height, 354 codec_settings->video_height,
355 codec_settings->video_bitrate) )) { 355 codec_settings->video_bitrate) )) {
356 356
357 if ( pthread_mutex_init(call->mutex, NULL) != 0 ) goto error; 357 if ( pthread_mutex_init(&call->mutex, NULL) != 0 ) goto error;
358 358
359 call->call_active = 1; 359 call->call_active = 1;
360 360
@@ -388,7 +388,7 @@ int toxav_kill_transmission ( ToxAv *av, int32_t call_index )
388 388
389 CallSpecific *call = &av->calls[call_index]; 389 CallSpecific *call = &av->calls[call_index];
390 390
391 pthread_mutex_lock(call->mutex); 391 pthread_mutex_lock(&call->mutex);
392 392
393 call->call_active = 0; 393 call->call_active = 0;
394 394
@@ -397,8 +397,8 @@ int toxav_kill_transmission ( ToxAv *av, int32_t call_index )
397 terminate_queue(call->j_buf); call->j_buf = NULL; 397 terminate_queue(call->j_buf); call->j_buf = NULL;
398 codec_terminate_session(call->cs); call->cs = NULL; 398 codec_terminate_session(call->cs); call->cs = NULL;
399 399
400 pthread_mutex_unlock(call->mutex); 400 pthread_mutex_unlock(&call->mutex);
401 pthread_mutex_destroy(call->mutex); 401 pthread_mutex_destroy(&call->mutex);
402 402
403 return ErrorNone; 403 return ErrorNone;
404} 404}
@@ -534,7 +534,7 @@ inline__ int toxav_recv_video ( ToxAv *av, int32_t call_index, vpx_image_t **out
534 534
535 535
536 CallSpecific *call = &av->calls[call_index]; 536 CallSpecific *call = &av->calls[call_index];
537 pthread_mutex_lock(call->mutex); 537 pthread_mutex_lock(&call->mutex);
538 538
539 uint8_t packet [RTP_PAYLOAD_SIZE]; 539 uint8_t packet [RTP_PAYLOAD_SIZE];
540 int recved_size; 540 int recved_size;
@@ -587,7 +587,7 @@ inline__ int toxav_recv_video ( ToxAv *av, int32_t call_index, vpx_image_t **out
587 587
588 *output = img; 588 *output = img;
589 589
590 pthread_mutex_unlock(call->mutex); 590 pthread_mutex_unlock(&call->mutex);
591 return ErrorNone; 591 return ErrorNone;
592} 592}
593 593
@@ -608,9 +608,9 @@ inline__ int toxav_send_video ( ToxAv *av, int32_t call_index, const uint8_t *fr
608 } 608 }
609 609
610 610
611 pthread_mutex_lock(av->calls[call_index].mutex); 611 pthread_mutex_lock(&av->calls[call_index].mutex);
612 int rc = toxav_send_rtp_payload(av, call_index, TypeVideo, frame, frame_size); 612 int rc = toxav_send_rtp_payload(av, call_index, TypeVideo, frame, frame_size);
613 pthread_mutex_unlock(av->calls[call_index].mutex); 613 pthread_mutex_unlock(&av->calls[call_index].mutex);
614 614
615 return rc; 615 return rc;
616} 616}
@@ -635,7 +635,7 @@ inline__ int toxav_prepare_video_frame(ToxAv *av, int32_t call_index, uint8_t *d
635 635
636 636
637 CallSpecific *call = &av->calls[call_index]; 637 CallSpecific *call = &av->calls[call_index];
638 pthread_mutex_lock(call->mutex); 638 pthread_mutex_lock(&call->mutex);
639 639
640 reconfigure_video_encoder_resolution(call->cs, input->d_w, input->d_h); 640 reconfigure_video_encoder_resolution(call->cs, input->d_w, input->d_h);
641 641
@@ -643,7 +643,7 @@ inline__ int toxav_prepare_video_frame(ToxAv *av, int32_t call_index, uint8_t *d
643 643
644 if ( rc != VPX_CODEC_OK) { 644 if ( rc != VPX_CODEC_OK) {
645 LOGGER_ERROR("Could not encode video frame: %s\n", vpx_codec_err_to_string(rc)); 645 LOGGER_ERROR("Could not encode video frame: %s\n", vpx_codec_err_to_string(rc));
646 pthread_mutex_unlock(call->mutex); 646 pthread_mutex_unlock(&call->mutex);
647 return ErrorInternal; 647 return ErrorInternal;
648 } 648 }
649 649
@@ -656,7 +656,7 @@ inline__ int toxav_prepare_video_frame(ToxAv *av, int32_t call_index, uint8_t *d
656 while ( (pkt = vpx_codec_get_cx_data(&call->cs->v_encoder, &iter)) ) { 656 while ( (pkt = vpx_codec_get_cx_data(&call->cs->v_encoder, &iter)) ) {
657 if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) { 657 if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) {
658 if ( copied + pkt->data.frame.sz > dest_max ) { 658 if ( copied + pkt->data.frame.sz > dest_max ) {
659 pthread_mutex_unlock(call->mutex); 659 pthread_mutex_unlock(&call->mutex);
660 return ErrorPacketTooLarge; 660 return ErrorPacketTooLarge;
661 } 661 }
662 662
@@ -665,7 +665,7 @@ inline__ int toxav_prepare_video_frame(ToxAv *av, int32_t call_index, uint8_t *d
665 } 665 }
666 } 666 }
667 667
668 pthread_mutex_unlock(call->mutex); 668 pthread_mutex_unlock(&call->mutex);
669 return copied; 669 return copied;
670} 670}
671 671
@@ -692,7 +692,7 @@ inline__ int toxav_recv_audio ( ToxAv *av, int32_t call_index, int frame_size, i
692 692
693 693
694 CallSpecific *call = &av->calls[call_index]; 694 CallSpecific *call = &av->calls[call_index];
695 pthread_mutex_lock(call->mutex); 695 pthread_mutex_lock(&call->mutex);
696 696
697 uint8_t packet [RTP_PAYLOAD_SIZE]; 697 uint8_t packet [RTP_PAYLOAD_SIZE];
698 698
@@ -701,7 +701,7 @@ inline__ int toxav_recv_audio ( ToxAv *av, int32_t call_index, int frame_size, i
701 if ( recved_size == ErrorAudioPacketLost ) { 701 if ( recved_size == ErrorAudioPacketLost ) {
702 int dec_size = opus_decode(call->cs->audio_decoder, NULL, 0, dest, frame_size, 1); 702 int dec_size = opus_decode(call->cs->audio_decoder, NULL, 0, dest, frame_size, 1);
703 703
704 pthread_mutex_unlock(call->mutex); 704 pthread_mutex_unlock(&call->mutex);
705 705
706 if ( dec_size < 0 ) { 706 if ( dec_size < 0 ) {
707 LOGGER_WARNING("Decoding error: %s", opus_strerror(dec_size)); 707 LOGGER_WARNING("Decoding error: %s", opus_strerror(dec_size));
@@ -711,14 +711,14 @@ inline__ int toxav_recv_audio ( ToxAv *av, int32_t call_index, int frame_size, i
711 } else if ( recved_size ) { 711 } else if ( recved_size ) {
712 int dec_size = opus_decode(call->cs->audio_decoder, packet, recved_size, dest, frame_size, 0); 712 int dec_size = opus_decode(call->cs->audio_decoder, packet, recved_size, dest, frame_size, 0);
713 713
714 pthread_mutex_unlock(call->mutex); 714 pthread_mutex_unlock(&call->mutex);
715 715
716 if ( dec_size < 0 ) { 716 if ( dec_size < 0 ) {
717 LOGGER_WARNING("Decoding error: %s", opus_strerror(dec_size)); 717 LOGGER_WARNING("Decoding error: %s", opus_strerror(dec_size));
718 return ErrorInternal; 718 return ErrorInternal;
719 } else return dec_size; 719 } else return dec_size;
720 } else { 720 } else {
721 pthread_mutex_unlock(call->mutex); 721 pthread_mutex_unlock(&call->mutex);
722 return 0; /* Nothing received */ 722 return 0; /* Nothing received */
723 } 723 }
724} 724}
@@ -742,9 +742,9 @@ inline__ int toxav_send_audio ( ToxAv *av, int32_t call_index, const uint8_t *fr
742 } 742 }
743 743
744 744
745 pthread_mutex_lock(av->calls[call_index].mutex); 745 pthread_mutex_lock(&av->calls[call_index].mutex);
746 int rc = toxav_send_rtp_payload(av, call_index, TypeAudio, frame, frame_size); 746 int rc = toxav_send_rtp_payload(av, call_index, TypeAudio, frame, frame_size);
747 pthread_mutex_unlock(av->calls[call_index].mutex); 747 pthread_mutex_unlock(&av->calls[call_index].mutex);
748 748
749 return rc; 749 return rc;
750} 750}
@@ -770,11 +770,11 @@ inline__ int toxav_prepare_audio_frame ( ToxAv *av, int32_t call_index, uint8_t
770 } 770 }
771 771
772 772
773 pthread_mutex_lock(av->calls[call_index].mutex); 773 pthread_mutex_lock(&av->calls[call_index].mutex);
774 774
775 int32_t rc = opus_encode(av->calls[call_index].cs->audio_encoder, frame, frame_size, dest, dest_max); 775 int32_t rc = opus_encode(av->calls[call_index].cs->audio_encoder, frame, frame_size, dest, dest_max);
776 776
777 pthread_mutex_unlock(av->calls[call_index].mutex); 777 pthread_mutex_unlock(&av->calls[call_index].mutex);
778 778
779 if (rc < 0) { 779 if (rc < 0) {
780 LOGGER_ERROR("Failed to encode payload: %s\n", opus_strerror(rc)); 780 LOGGER_ERROR("Failed to encode payload: %s\n", opus_strerror(rc));