diff options
author | irungentoo <irungentoo@gmail.com> | 2014-11-28 13:10:27 -0500 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-11-28 13:10:27 -0500 |
commit | db68c6eff6adb63acba9e5d3733ec4e395ee87c1 (patch) | |
tree | 4032b993a6814e1302366266fd3322ebe4880b79 /toxav | |
parent | 767c0653bd6531c463ee4d005938470462faeb71 (diff) |
Fixed toxav issues.
Diffstat (limited to 'toxav')
-rw-r--r-- | toxav/codec.c | 5 | ||||
-rw-r--r-- | toxav/toxav.c | 35 |
2 files changed, 28 insertions, 12 deletions
diff --git a/toxav/codec.c b/toxav/codec.c index e0b004a4..2849ed69 100644 --- a/toxav/codec.c +++ b/toxav/codec.c | |||
@@ -378,12 +378,13 @@ void cs_do(CSSession *cs) | |||
378 | if (!cs) return; | 378 | if (!cs) return; |
379 | 379 | ||
380 | pthread_mutex_lock(cs->queue_mutex); | 380 | pthread_mutex_lock(cs->queue_mutex); |
381 | /* | 381 | |
382 | if (!cs->active) { | 382 | if (!cs->active) { |
383 | pthread_mutex_unlock(cs->queue_mutex); | 383 | pthread_mutex_unlock(cs->queue_mutex); |
384 | return; | 384 | return; |
385 | } | 385 | } |
386 | 386 | ||
387 | /* | ||
387 | /* Iterate over whole buffers and call playback callback * / | 388 | /* Iterate over whole buffers and call playback callback * / |
388 | if (cs->abuf_ready) while (!DecodedAudioBuffer_empty(cs->abuf_ready)) { | 389 | if (cs->abuf_ready) while (!DecodedAudioBuffer_empty(cs->abuf_ready)) { |
389 | DecodedAudio* p; | 390 | DecodedAudio* p; |
@@ -613,8 +614,6 @@ void cs_kill(CSSession *cs) | |||
613 | 614 | ||
614 | /* Wait threads to close */ | 615 | /* Wait threads to close */ |
615 | pthread_mutex_unlock(cs->queue_mutex); | 616 | pthread_mutex_unlock(cs->queue_mutex); |
616 | pthread_mutex_lock(cs->queue_mutex); | ||
617 | pthread_mutex_unlock(cs->queue_mutex); | ||
618 | 617 | ||
619 | pthread_mutex_destroy(cs->queue_mutex); | 618 | pthread_mutex_destroy(cs->queue_mutex); |
620 | 619 | ||
diff --git a/toxav/toxav.c b/toxav/toxav.c index 1aa4d6b4..11f709b9 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c | |||
@@ -117,6 +117,19 @@ ToxAv *toxav_new( Tox *messenger, int32_t max_calls) | |||
117 | av->calls = calloc(sizeof(CallSpecific), max_calls); | 117 | av->calls = calloc(sizeof(CallSpecific), max_calls); |
118 | av->max_calls = max_calls; | 118 | av->max_calls = max_calls; |
119 | 119 | ||
120 | unsigned int i; | ||
121 | |||
122 | for (i = 0; i < max_calls; ++i) { | ||
123 | if (pthread_mutex_init(&av->calls[i].mutex, NULL) != 0 ) { | ||
124 | LOGGER_WARNING("Failed to init call mutex!"); | ||
125 | msi_kill(av->msi_session); | ||
126 | |||
127 | free(av->calls); | ||
128 | free(av); | ||
129 | return NULL; | ||
130 | } | ||
131 | } | ||
132 | |||
120 | return av; | 133 | return av; |
121 | } | 134 | } |
122 | 135 | ||
@@ -133,6 +146,8 @@ void toxav_kill ( ToxAv *av ) | |||
133 | rtp_kill(av->calls[i].crtps[video_index], av->msi_session->messenger_handle); | 146 | rtp_kill(av->calls[i].crtps[video_index], av->msi_session->messenger_handle); |
134 | 147 | ||
135 | if ( av->calls[i].cs ) cs_kill(av->calls[i].cs); | 148 | if ( av->calls[i].cs ) cs_kill(av->calls[i].cs); |
149 | |||
150 | pthread_mutex_destroy(&av->calls[i].mutex); | ||
136 | } | 151 | } |
137 | 152 | ||
138 | msi_kill(av->msi_session); | 153 | msi_kill(av->msi_session); |
@@ -166,9 +181,14 @@ void toxav_do(ToxAv *av) | |||
166 | 181 | ||
167 | uint32_t i = 0; | 182 | uint32_t i = 0; |
168 | 183 | ||
169 | for (; i < av->max_calls; i ++) | 184 | for (; i < av->max_calls; i ++) { |
185 | pthread_mutex_lock(&av->calls[i].mutex); | ||
186 | |||
170 | if (av->calls[i].call_active) cs_do(av->calls[i].cs); | 187 | if (av->calls[i].call_active) cs_do(av->calls[i].cs); |
171 | 188 | ||
189 | pthread_mutex_unlock(&av->calls[i].mutex); | ||
190 | } | ||
191 | |||
172 | uint64_t end = current_time_monotonic(); | 192 | uint64_t end = current_time_monotonic(); |
173 | 193 | ||
174 | /* TODO maybe use variable for sizes */ | 194 | /* TODO maybe use variable for sizes */ |
@@ -286,11 +306,7 @@ int toxav_prepare_transmission ( ToxAv *av, int32_t call_index, int support_vide | |||
286 | 306 | ||
287 | CallSpecific *call = &av->calls[call_index]; | 307 | CallSpecific *call = &av->calls[call_index]; |
288 | 308 | ||
289 | if ( pthread_mutex_init(&call->mutex, NULL) != 0 ) { | 309 | pthread_mutex_lock(&call->mutex); |
290 | LOGGER_WARNING("Failed to init call mutex!"); | ||
291 | return av_ErrorInternal; | ||
292 | } | ||
293 | |||
294 | const ToxAvCSettings *c_peer = toxavcsettings_cast | 310 | const ToxAvCSettings *c_peer = toxavcsettings_cast |
295 | (&av->msi_session->calls[call_index]->csettings_peer[0]); | 311 | (&av->msi_session->calls[call_index]->csettings_peer[0]); |
296 | const ToxAvCSettings *c_self = toxavcsettings_cast | 312 | const ToxAvCSettings *c_self = toxavcsettings_cast |
@@ -315,8 +331,8 @@ int toxav_prepare_transmission ( ToxAv *av, int32_t call_index, int support_vide | |||
315 | c_self->audio_channels, c_peer->audio_channels ); | 331 | c_self->audio_channels, c_peer->audio_channels ); |
316 | 332 | ||
317 | if ( !(call->cs = cs_new(c_self, c_peer, jbuf_capacity, support_video)) ) { | 333 | if ( !(call->cs = cs_new(c_self, c_peer, jbuf_capacity, support_video)) ) { |
318 | pthread_mutex_destroy(&call->mutex); | ||
319 | LOGGER_ERROR("Error while starting Codec State!\n"); | 334 | LOGGER_ERROR("Error while starting Codec State!\n"); |
335 | pthread_mutex_unlock(&call->mutex); | ||
320 | return av_ErrorInternal; | 336 | return av_ErrorInternal; |
321 | } | 337 | } |
322 | 338 | ||
@@ -328,6 +344,7 @@ int toxav_prepare_transmission ( ToxAv *av, int32_t call_index, int support_vide | |||
328 | 344 | ||
329 | if ( !call->crtps[audio_index] ) { | 345 | if ( !call->crtps[audio_index] ) { |
330 | LOGGER_ERROR("Error while starting audio RTP session!\n"); | 346 | LOGGER_ERROR("Error while starting audio RTP session!\n"); |
347 | pthread_mutex_unlock(&call->mutex); | ||
331 | return av_ErrorInternal; | 348 | return av_ErrorInternal; |
332 | } | 349 | } |
333 | 350 | ||
@@ -346,14 +363,15 @@ int toxav_prepare_transmission ( ToxAv *av, int32_t call_index, int support_vide | |||
346 | } | 363 | } |
347 | 364 | ||
348 | call->call_active = 1; | 365 | call->call_active = 1; |
366 | pthread_mutex_unlock(&call->mutex); | ||
349 | return av_ErrorNone; | 367 | return av_ErrorNone; |
350 | error: | 368 | error: |
351 | rtp_kill(call->crtps[audio_index], av->messenger); | 369 | rtp_kill(call->crtps[audio_index], av->messenger); |
352 | rtp_kill(call->crtps[video_index], av->messenger); | 370 | rtp_kill(call->crtps[video_index], av->messenger); |
353 | cs_kill(call->cs); | 371 | cs_kill(call->cs); |
354 | pthread_mutex_destroy(&call->mutex); | ||
355 | memset(call, 0, sizeof(CallSpecific)); | 372 | memset(call, 0, sizeof(CallSpecific)); |
356 | 373 | ||
374 | pthread_mutex_unlock(&call->mutex); | ||
357 | return av_ErrorInternal; | 375 | return av_ErrorInternal; |
358 | } | 376 | } |
359 | 377 | ||
@@ -384,7 +402,6 @@ int toxav_kill_transmission ( ToxAv *av, int32_t call_index ) | |||
384 | call->call_active = 0; | 402 | call->call_active = 0; |
385 | 403 | ||
386 | pthread_mutex_unlock(&call->mutex); | 404 | pthread_mutex_unlock(&call->mutex); |
387 | pthread_mutex_destroy(&call->mutex); | ||
388 | 405 | ||
389 | return av_ErrorNone; | 406 | return av_ErrorNone; |
390 | } | 407 | } |