diff options
Diffstat (limited to 'toxav/toxav.c')
-rw-r--r-- | toxav/toxav.c | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/toxav/toxav.c b/toxav/toxav.c index 9febd3a9..54554918 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c | |||
@@ -47,7 +47,7 @@ typedef struct ToxAVCall_s { | |||
47 | 47 | ||
48 | pthread_mutex_t mutex_audio_sending[1]; | 48 | pthread_mutex_t mutex_audio_sending[1]; |
49 | pthread_mutex_t mutex_video_sending[1]; | 49 | pthread_mutex_t mutex_video_sending[1]; |
50 | /* Only audio or video can be decoded at one time */ | 50 | /* Only audio or video can be decoded at the time */ |
51 | pthread_mutex_t mutex_decoding[1]; | 51 | pthread_mutex_t mutex_decoding[1]; |
52 | 52 | ||
53 | bool active; | 53 | bool active; |
@@ -129,7 +129,8 @@ ToxAV* toxav_new(Tox* tox, TOXAV_ERR_NEW* error) | |||
129 | goto FAILURE; | 129 | goto FAILURE; |
130 | } | 130 | } |
131 | 131 | ||
132 | if (create_recursive_mutex(av->mutex) == -1) { | 132 | // if (create_recursive_mutex(av->mutex) == -1) { |
133 | if (pthread_mutex_init(av->mutex, NULL) == -1) { | ||
133 | LOGGER_WARNING("Mutex creation failed!"); | 134 | LOGGER_WARNING("Mutex creation failed!"); |
134 | rc = TOXAV_ERR_NEW_MALLOC; | 135 | rc = TOXAV_ERR_NEW_MALLOC; |
135 | goto FAILURE; | 136 | goto FAILURE; |
@@ -204,26 +205,30 @@ uint32_t toxav_iteration_interval(const ToxAV* av) | |||
204 | 205 | ||
205 | void toxav_iterate(ToxAV* av) | 206 | void toxav_iterate(ToxAV* av) |
206 | { | 207 | { |
207 | if (av->calls == NULL) | 208 | pthread_mutex_lock(av->mutex); |
209 | if (av->calls == NULL) { | ||
210 | pthread_mutex_unlock(av->mutex); | ||
208 | return; | 211 | return; |
212 | } | ||
209 | 213 | ||
210 | uint64_t start = current_time_monotonic(); | 214 | uint64_t start = current_time_monotonic(); |
211 | uint32_t rc = 500; | 215 | uint32_t rc = 500; |
212 | 216 | ||
213 | pthread_mutex_lock(av->mutex); | ||
214 | ToxAVCall* i = av->calls[av->calls_head]; | 217 | ToxAVCall* i = av->calls[av->calls_head]; |
215 | for (; i; i = i->next) { | 218 | while (i) { |
216 | if (i->active) { | 219 | if (i->active) { |
217 | pthread_mutex_lock(i->mutex_decoding); | 220 | pthread_mutex_lock(i->mutex_decoding); |
218 | pthread_mutex_unlock(av->mutex); | 221 | pthread_mutex_unlock(av->mutex); |
222 | |||
219 | cs_do(i->cs); | 223 | cs_do(i->cs); |
220 | rc = MIN(i->cs->last_packet_frame_duration, rc); | 224 | rc = MIN(i->cs->last_packet_frame_duration, rc); |
225 | |||
226 | pthread_mutex_lock(av->mutex); | ||
221 | pthread_mutex_unlock(i->mutex_decoding); | 227 | pthread_mutex_unlock(i->mutex_decoding); |
222 | } else | 228 | i = i->next; |
223 | continue; | 229 | } |
224 | |||
225 | pthread_mutex_lock(av->mutex); | ||
226 | } | 230 | } |
231 | pthread_mutex_unlock(av->mutex); | ||
227 | 232 | ||
228 | av->interval = rc < av->dmssa ? 0 : (rc - av->dmssa); | 233 | av->interval = rc < av->dmssa ? 0 : (rc - av->dmssa); |
229 | av->dmsst += current_time_monotonic() - start; | 234 | av->dmsst += current_time_monotonic() - start; |
@@ -1048,6 +1053,11 @@ void call_kill_transmission(ToxAVCall* call) | |||
1048 | 1053 | ||
1049 | call->active = 0; | 1054 | call->active = 0; |
1050 | 1055 | ||
1056 | rtp_kill(call->rtps[audio_index]); | ||
1057 | call->rtps[audio_index] = NULL; | ||
1058 | rtp_kill(call->rtps[video_index]); | ||
1059 | call->rtps[video_index] = NULL; | ||
1060 | |||
1051 | pthread_mutex_lock(call->mutex_audio_sending); | 1061 | pthread_mutex_lock(call->mutex_audio_sending); |
1052 | pthread_mutex_unlock(call->mutex_audio_sending); | 1062 | pthread_mutex_unlock(call->mutex_audio_sending); |
1053 | pthread_mutex_lock(call->mutex_video_sending); | 1063 | pthread_mutex_lock(call->mutex_video_sending); |
@@ -1055,11 +1065,6 @@ void call_kill_transmission(ToxAVCall* call) | |||
1055 | pthread_mutex_lock(call->mutex_decoding); | 1065 | pthread_mutex_lock(call->mutex_decoding); |
1056 | pthread_mutex_unlock(call->mutex_decoding); | 1066 | pthread_mutex_unlock(call->mutex_decoding); |
1057 | 1067 | ||
1058 | rtp_kill(call->rtps[audio_index]); | ||
1059 | call->rtps[audio_index] = NULL; | ||
1060 | rtp_kill(call->rtps[video_index]); | ||
1061 | call->rtps[video_index] = NULL; | ||
1062 | |||
1063 | cs_kill(call->cs); | 1068 | cs_kill(call->cs); |
1064 | call->cs = NULL; | 1069 | call->cs = NULL; |
1065 | 1070 | ||