summaryrefslogtreecommitdiff
path: root/toxav/toxav.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-12-03 14:41:01 -0500
committerirungentoo <irungentoo@gmail.com>2014-12-03 14:41:01 -0500
commitf6b3e6e8fe98d2457827ac6da944e715f008a08a (patch)
treecbdb0e1f0f9e2279350413a10093ba7a463cdf86 /toxav/toxav.c
parent475c157d68b53e9d6666c678bfb2dc0c2e126216 (diff)
Fixed possible threading issues.
Diffstat (limited to 'toxav/toxav.c')
-rw-r--r--toxav/toxav.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/toxav/toxav.c b/toxav/toxav.c
index 7633edf9..a4b2d5da 100644
--- a/toxav/toxav.c
+++ b/toxav/toxav.c
@@ -258,8 +258,7 @@ int toxav_stop_call ( ToxAv *av, int32_t call_index )
258int toxav_prepare_transmission ( ToxAv *av, int32_t call_index, int support_video ) 258int toxav_prepare_transmission ( ToxAv *av, int32_t call_index, int support_video )
259{ 259{
260 if ( !av->msi_session || CALL_INVALID_INDEX(call_index, av->msi_session->max_calls) || 260 if ( !av->msi_session || CALL_INVALID_INDEX(call_index, av->msi_session->max_calls) ||
261 !av->msi_session->calls[call_index] || !av->msi_session->calls[call_index]->csettings_peer || 261 !av->msi_session->calls[call_index] || !av->msi_session->calls[call_index]->csettings_peer) {
262 av->calls[call_index].active) {
263 LOGGER_ERROR("Error while starting RTP session: invalid call!\n"); 262 LOGGER_ERROR("Error while starting RTP session: invalid call!\n");
264 return av_ErrorNoCall; 263 return av_ErrorNoCall;
265 } 264 }
@@ -267,6 +266,13 @@ int toxav_prepare_transmission ( ToxAv *av, int32_t call_index, int support_vide
267 ToxAvCall *call = &av->calls[call_index]; 266 ToxAvCall *call = &av->calls[call_index];
268 267
269 pthread_mutex_lock(call->mutex); 268 pthread_mutex_lock(call->mutex);
269
270 if (call->active) {
271 pthread_mutex_unlock(call->mutex);
272 LOGGER_ERROR("Error while starting RTP session: call already active!\n");
273 return av_ErrorNoCall;
274 }
275
270 const ToxAvCSettings *c_peer = toxavcsettings_cast 276 const ToxAvCSettings *c_peer = toxavcsettings_cast
271 (&av->msi_session->calls[call_index]->csettings_peer[0]); 277 (&av->msi_session->calls[call_index]->csettings_peer[0]);
272 const ToxAvCSettings *c_self = toxavcsettings_cast 278 const ToxAvCSettings *c_self = toxavcsettings_cast
@@ -489,15 +495,14 @@ int toxav_prepare_audio_frame ( ToxAv *av,
489 const int16_t *frame, 495 const int16_t *frame,
490 int frame_size) 496 int frame_size)
491{ 497{
492 if (CALL_INVALID_INDEX(call_index, av->msi_session->max_calls) || !av->calls[call_index].active) { 498 if (CALL_INVALID_INDEX(call_index, av->msi_session->max_calls)) {
493 LOGGER_WARNING("Action on inactive call: %d", call_index); 499 LOGGER_WARNING("Action on nonexisting call: %d", call_index);
494 return av_ErrorNoCall; 500 return av_ErrorNoCall;
495 } 501 }
496 502
497 ToxAvCall *call = &av->calls[call_index]; 503 ToxAvCall *call = &av->calls[call_index];
498 pthread_mutex_lock(call->mutex); 504 pthread_mutex_lock(call->mutex);
499 505
500
501 if (!call->active) { 506 if (!call->active) {
502 pthread_mutex_unlock(call->mutex); 507 pthread_mutex_unlock(call->mutex);
503 LOGGER_WARNING("Action on inactive call: %d", call_index); 508 LOGGER_WARNING("Action on inactive call: %d", call_index);
@@ -517,8 +522,8 @@ int toxav_prepare_audio_frame ( ToxAv *av,
517 522
518int toxav_send_audio ( ToxAv *av, int32_t call_index, const uint8_t *data, unsigned int size) 523int toxav_send_audio ( ToxAv *av, int32_t call_index, const uint8_t *data, unsigned int size)
519{ 524{
520 if (CALL_INVALID_INDEX(call_index, av->msi_session->max_calls) || !av->calls[call_index].active) { 525 if (CALL_INVALID_INDEX(call_index, av->msi_session->max_calls)) {
521 LOGGER_WARNING("Action on inactive call: %d", call_index); 526 LOGGER_WARNING("Action on nonexisting call: %d", call_index);
522 return av_ErrorNoCall; 527 return av_ErrorNoCall;
523 } 528 }
524 529
@@ -583,7 +588,13 @@ int toxav_get_active_count(ToxAv *av)
583 588
584 int rc = 0, i = 0; 589 int rc = 0, i = 0;
585 590
586 for (; i < av->max_calls; i ++) if (av->calls[i].active) rc++; 591 for (; i < av->max_calls; i++) {
592 pthread_mutex_lock(av->calls[i].mutex);
593
594 if (av->calls[i].active) rc++;
595
596 pthread_mutex_unlock(av->calls[i].mutex);
597 }
587 598
588 return rc; 599 return rc;
589} 600}