Add synchronization protection for send_frame API functions

This commit is contained in:
Eniz Vukovic 2015-10-24 01:56:49 +02:00
parent 7972db5c41
commit 87828a1b42
3 changed files with 18 additions and 2 deletions

View File

@ -492,6 +492,10 @@ error for send_frame {
* This client is currently not in a call with the friend.
*/
FRIEND_NOT_IN_CALL,
/**
* Synchronization error occurred.
*/
SYNC,
/**
* One of the frame parameters was invalid. E.g. the resolution may be too
* small or too large, or the audio sampling rate may be unsupported.

View File

@ -649,7 +649,11 @@ bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pc
goto END;
}
pthread_mutex_lock(av->mutex);
if (pthread_mutex_trylock(av->mutex) != 0) {
rc = TOXAV_ERR_SEND_FRAME_SYNC;
goto END;
}
call = call_get(av, friend_number);
if (call == NULL || !call->active || call->msi_call->state != msi_CallActive) {
@ -728,7 +732,11 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u
goto END;
}
pthread_mutex_lock(av->mutex);
if (pthread_mutex_trylock(av->mutex) != 0) {
rc = TOXAV_ERR_SEND_FRAME_SYNC;
goto END;
}
call = call_get(av, friend_number);
if (call == NULL || !call->active || call->msi_call->state != msi_CallActive) {

View File

@ -565,6 +565,10 @@ typedef enum TOXAV_ERR_SEND_FRAME {
* This client is currently not in a call with the friend.
*/
TOXAV_ERR_SEND_FRAME_FRIEND_NOT_IN_CALL,
/**
* Synchronization error occurred.
*/
TOXAV_ERR_SEND_FRAME_SYNC,
/**
* One of the frame parameters was invalid. E.g. the resolution may be too
* small or too large, or the audio sampling rate may be unsupported.