diff options
author | irungentoo <irungentoo@gmail.com> | 2015-11-03 13:42:05 -0500 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2015-11-03 13:42:05 -0500 |
commit | 6a494e2cbdd146bb13185d8220061322661a5f5a (patch) | |
tree | 6cb23bca09894cde6173bc7a362a112d72872215 /toxav/toxav.c | |
parent | f435e94397feb3121ef334de6873b93adaaf01dd (diff) |
Astyle.
Diffstat (limited to 'toxav/toxav.c')
-rw-r--r-- | toxav/toxav.c | 57 |
1 files changed, 36 insertions, 21 deletions
diff --git a/toxav/toxav.c b/toxav/toxav.c index 6a17f55d..9eda3412 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c | |||
@@ -190,7 +190,7 @@ void toxav_kill(ToxAV *av) | |||
190 | return; | 190 | return; |
191 | 191 | ||
192 | pthread_mutex_lock(av->mutex); | 192 | pthread_mutex_lock(av->mutex); |
193 | 193 | ||
194 | /* To avoid possible deadlocks */ | 194 | /* To avoid possible deadlocks */ |
195 | while (av->msi && msi_kill(av->msi) != 0) { | 195 | while (av->msi && msi_kill(av->msi) != 0) { |
196 | pthread_mutex_unlock(av->mutex); | 196 | pthread_mutex_unlock(av->mutex); |
@@ -206,10 +206,10 @@ void toxav_kill(ToxAV *av) | |||
206 | it = call_remove(it); /* This will eventually free av->calls */ | 206 | it = call_remove(it); /* This will eventually free av->calls */ |
207 | } | 207 | } |
208 | } | 208 | } |
209 | 209 | ||
210 | pthread_mutex_unlock(av->mutex); | 210 | pthread_mutex_unlock(av->mutex); |
211 | pthread_mutex_destroy(av->mutex); | 211 | pthread_mutex_destroy(av->mutex); |
212 | 212 | ||
213 | free(av); | 213 | free(av); |
214 | } | 214 | } |
215 | Tox *toxav_get_tox(const ToxAV *av) | 215 | Tox *toxav_get_tox(const ToxAV *av) |
@@ -277,11 +277,11 @@ bool toxav_call(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, uint | |||
277 | TOXAV_ERR_CALL *error) | 277 | TOXAV_ERR_CALL *error) |
278 | { | 278 | { |
279 | TOXAV_ERR_CALL rc = TOXAV_ERR_CALL_OK; | 279 | TOXAV_ERR_CALL rc = TOXAV_ERR_CALL_OK; |
280 | 280 | ||
281 | pthread_mutex_lock(av->mutex); | 281 | pthread_mutex_lock(av->mutex); |
282 | 282 | ||
283 | if ((audio_bit_rate && audio_bit_rate_invalid(audio_bit_rate)) | 283 | if ((audio_bit_rate && audio_bit_rate_invalid(audio_bit_rate)) |
284 | || (video_bit_rate && video_bit_rate_invalid(video_bit_rate))) { | 284 | || (video_bit_rate && video_bit_rate_invalid(video_bit_rate))) { |
285 | rc = TOXAV_ERR_CALL_INVALID_BIT_RATE; | 285 | rc = TOXAV_ERR_CALL_INVALID_BIT_RATE; |
286 | goto END; | 286 | goto END; |
287 | } | 287 | } |
@@ -311,7 +311,7 @@ bool toxav_call(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, uint | |||
311 | 311 | ||
312 | END: | 312 | END: |
313 | pthread_mutex_unlock(av->mutex); | 313 | pthread_mutex_unlock(av->mutex); |
314 | 314 | ||
315 | if (error) | 315 | if (error) |
316 | *error = rc; | 316 | *error = rc; |
317 | 317 | ||
@@ -337,7 +337,7 @@ bool toxav_answer(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, ui | |||
337 | } | 337 | } |
338 | 338 | ||
339 | if ((audio_bit_rate && audio_bit_rate_invalid(audio_bit_rate)) | 339 | if ((audio_bit_rate && audio_bit_rate_invalid(audio_bit_rate)) |
340 | || (video_bit_rate && video_bit_rate_invalid(video_bit_rate)) | 340 | || (video_bit_rate && video_bit_rate_invalid(video_bit_rate)) |
341 | ) { | 341 | ) { |
342 | rc = TOXAV_ERR_ANSWER_INVALID_BIT_RATE; | 342 | rc = TOXAV_ERR_ANSWER_INVALID_BIT_RATE; |
343 | goto END; | 343 | goto END; |
@@ -441,9 +441,10 @@ bool toxav_call_control(ToxAV *av, uint32_t friend_number, TOXAV_CALL_CONTROL co | |||
441 | case TOXAV_CALL_CONTROL_CANCEL: { | 441 | case TOXAV_CALL_CONTROL_CANCEL: { |
442 | /* Hang up */ | 442 | /* Hang up */ |
443 | pthread_mutex_lock(call->mutex); | 443 | pthread_mutex_lock(call->mutex); |
444 | |||
444 | if (msi_hangup(call->msi_call) != 0) { | 445 | if (msi_hangup(call->msi_call) != 0) { |
445 | rc = TOXAV_ERR_CALL_CONTROL_SYNC; | 446 | rc = TOXAV_ERR_CALL_CONTROL_SYNC; |
446 | pthread_mutex_unlock(call->mutex); | 447 | pthread_mutex_unlock(call->mutex); |
447 | goto END; | 448 | goto END; |
448 | } | 449 | } |
449 | 450 | ||
@@ -566,18 +567,22 @@ bool toxav_bit_rate_set(ToxAV *av, uint32_t friend_number, int32_t audio_bit_rat | |||
566 | LOGGER_DEBUG("Audio bitrate already set to: %d", audio_bit_rate); | 567 | LOGGER_DEBUG("Audio bitrate already set to: %d", audio_bit_rate); |
567 | } else if (audio_bit_rate == 0) { | 568 | } else if (audio_bit_rate == 0) { |
568 | LOGGER_DEBUG("Turned off audio sending"); | 569 | LOGGER_DEBUG("Turned off audio sending"); |
570 | |||
569 | if (msi_change_capabilities(call->msi_call, call->msi_call-> | 571 | if (msi_change_capabilities(call->msi_call, call->msi_call-> |
570 | self_capabilities ^ msi_CapSAudio) != 0) { | 572 | self_capabilities ^ msi_CapSAudio) != 0) { |
571 | pthread_mutex_unlock(av->mutex); | 573 | pthread_mutex_unlock(av->mutex); |
572 | rc = TOXAV_ERR_BIT_RATE_SET_SYNC; | 574 | rc = TOXAV_ERR_BIT_RATE_SET_SYNC; |
573 | goto END; | 575 | goto END; |
574 | } | 576 | } |
577 | |||
575 | /* Audio sending is turned off; notify peer */ | 578 | /* Audio sending is turned off; notify peer */ |
576 | call->audio_bit_rate = 0; | 579 | call->audio_bit_rate = 0; |
577 | } else { | 580 | } else { |
578 | pthread_mutex_lock(call->mutex); | 581 | pthread_mutex_lock(call->mutex); |
582 | |||
579 | if (call->audio_bit_rate == 0) { | 583 | if (call->audio_bit_rate == 0) { |
580 | LOGGER_DEBUG("Turned on audio sending"); | 584 | LOGGER_DEBUG("Turned on audio sending"); |
585 | |||
581 | /* The audio has been turned off before this */ | 586 | /* The audio has been turned off before this */ |
582 | if (msi_change_capabilities(call->msi_call, call-> | 587 | if (msi_change_capabilities(call->msi_call, call-> |
583 | msi_call->self_capabilities | msi_CapSAudio) != 0) { | 588 | msi_call->self_capabilities | msi_CapSAudio) != 0) { |
@@ -588,6 +593,7 @@ bool toxav_bit_rate_set(ToxAV *av, uint32_t friend_number, int32_t audio_bit_rat | |||
588 | } | 593 | } |
589 | } else | 594 | } else |
590 | LOGGER_DEBUG("Set new audio bit rate %d", audio_bit_rate); | 595 | LOGGER_DEBUG("Set new audio bit rate %d", audio_bit_rate); |
596 | |||
591 | call->audio_bit_rate = audio_bit_rate; | 597 | call->audio_bit_rate = audio_bit_rate; |
592 | pthread_mutex_unlock(call->mutex); | 598 | pthread_mutex_unlock(call->mutex); |
593 | } | 599 | } |
@@ -600,6 +606,7 @@ bool toxav_bit_rate_set(ToxAV *av, uint32_t friend_number, int32_t audio_bit_rat | |||
600 | LOGGER_DEBUG("Video bitrate already set to: %d", video_bit_rate); | 606 | LOGGER_DEBUG("Video bitrate already set to: %d", video_bit_rate); |
601 | } else if (video_bit_rate == 0) { | 607 | } else if (video_bit_rate == 0) { |
602 | LOGGER_DEBUG("Turned off video sending"); | 608 | LOGGER_DEBUG("Turned off video sending"); |
609 | |||
603 | /* Video sending is turned off; notify peer */ | 610 | /* Video sending is turned off; notify peer */ |
604 | if (msi_change_capabilities(call->msi_call, call->msi_call-> | 611 | if (msi_change_capabilities(call->msi_call, call->msi_call-> |
605 | self_capabilities ^ msi_CapSVideo) != 0) { | 612 | self_capabilities ^ msi_CapSVideo) != 0) { |
@@ -607,11 +614,14 @@ bool toxav_bit_rate_set(ToxAV *av, uint32_t friend_number, int32_t audio_bit_rat | |||
607 | rc = TOXAV_ERR_BIT_RATE_SET_SYNC; | 614 | rc = TOXAV_ERR_BIT_RATE_SET_SYNC; |
608 | goto END; | 615 | goto END; |
609 | } | 616 | } |
617 | |||
610 | call->video_bit_rate = 0; | 618 | call->video_bit_rate = 0; |
611 | } else { | 619 | } else { |
612 | pthread_mutex_lock(call->mutex); | 620 | pthread_mutex_lock(call->mutex); |
621 | |||
613 | if (call->video_bit_rate == 0) { | 622 | if (call->video_bit_rate == 0) { |
614 | LOGGER_DEBUG("Turned on video sending"); | 623 | LOGGER_DEBUG("Turned on video sending"); |
624 | |||
615 | /* The video has been turned off before this */ | 625 | /* The video has been turned off before this */ |
616 | if (msi_change_capabilities(call->msi_call, call-> | 626 | if (msi_change_capabilities(call->msi_call, call-> |
617 | msi_call->self_capabilities | msi_CapSVideo) != 0) { | 627 | msi_call->self_capabilities | msi_CapSVideo) != 0) { |
@@ -622,13 +632,15 @@ bool toxav_bit_rate_set(ToxAV *av, uint32_t friend_number, int32_t audio_bit_rat | |||
622 | } | 632 | } |
623 | } else | 633 | } else |
624 | LOGGER_DEBUG("Set new video bit rate %d", video_bit_rate); | 634 | LOGGER_DEBUG("Set new video bit rate %d", video_bit_rate); |
635 | |||
625 | call->video_bit_rate = video_bit_rate; | 636 | call->video_bit_rate = video_bit_rate; |
626 | pthread_mutex_unlock(call->mutex); | 637 | pthread_mutex_unlock(call->mutex); |
627 | } | 638 | } |
628 | } | 639 | } |
629 | 640 | ||
630 | pthread_mutex_unlock(av->mutex); | 641 | pthread_mutex_unlock(av->mutex); |
631 | END: | 642 | END: |
643 | |||
632 | if (error) | 644 | if (error) |
633 | *error = rc; | 645 | *error = rc; |
634 | 646 | ||
@@ -656,7 +668,7 @@ bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pc | |||
656 | rc = TOXAV_ERR_SEND_FRAME_SYNC; | 668 | rc = TOXAV_ERR_SEND_FRAME_SYNC; |
657 | goto END; | 669 | goto END; |
658 | } | 670 | } |
659 | 671 | ||
660 | call = call_get(av, friend_number); | 672 | call = call_get(av, friend_number); |
661 | 673 | ||
662 | if (call == NULL || !call->active || call->msi_call->state != msi_CallActive) { | 674 | if (call == NULL || !call->active || call->msi_call->state != msi_CallActive) { |
@@ -719,6 +731,7 @@ bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pc | |||
719 | pthread_mutex_unlock(call->mutex_audio); | 731 | pthread_mutex_unlock(call->mutex_audio); |
720 | 732 | ||
721 | END: | 733 | END: |
734 | |||
722 | if (error) | 735 | if (error) |
723 | *error = rc; | 736 | *error = rc; |
724 | 737 | ||
@@ -739,7 +752,7 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u | |||
739 | rc = TOXAV_ERR_SEND_FRAME_SYNC; | 752 | rc = TOXAV_ERR_SEND_FRAME_SYNC; |
740 | goto END; | 753 | goto END; |
741 | } | 754 | } |
742 | 755 | ||
743 | call = call_get(av, friend_number); | 756 | call = call_get(av, friend_number); |
744 | 757 | ||
745 | if (call == NULL || !call->active || call->msi_call->state != msi_CallActive) { | 758 | if (call == NULL || !call->active || call->msi_call->state != msi_CallActive) { |
@@ -817,6 +830,7 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u | |||
817 | pthread_mutex_unlock(call->mutex_video); | 830 | pthread_mutex_unlock(call->mutex_video); |
818 | 831 | ||
819 | END: | 832 | END: |
833 | |||
820 | if (error) | 834 | if (error) |
821 | *error = rc; | 835 | *error = rc; |
822 | 836 | ||
@@ -843,7 +857,7 @@ void toxav_callback_video_receive_frame(ToxAV *av, toxav_video_receive_frame_cb | |||
843 | * :: Internal | 857 | * :: Internal |
844 | * | 858 | * |
845 | ******************************************************************************/ | 859 | ******************************************************************************/ |
846 | void callback_bwc(BWControler* bwc, uint32_t friend_number, float loss, void* user_data) | 860 | void callback_bwc(BWControler *bwc, uint32_t friend_number, float loss, void *user_data) |
847 | { | 861 | { |
848 | /* Callback which is called when the internal measure mechanism reported packet loss. | 862 | /* Callback which is called when the internal measure mechanism reported packet loss. |
849 | * We report suggested lowered bitrate to an app. If app is sending both audio and video, | 863 | * We report suggested lowered bitrate to an app. If app is sending both audio and video, |
@@ -851,22 +865,23 @@ void callback_bwc(BWControler* bwc, uint32_t friend_number, float loss, void* us | |||
851 | * takes more than 90% bandwidth. Otherwise, we report lowered bitrate on audio. | 865 | * takes more than 90% bandwidth. Otherwise, we report lowered bitrate on audio. |
852 | * The application may choose to disable video totally if the stream is too bad. | 866 | * The application may choose to disable video totally if the stream is too bad. |
853 | */ | 867 | */ |
854 | 868 | ||
855 | ToxAVCall* call = user_data; | 869 | ToxAVCall *call = user_data; |
856 | assert(call); | 870 | assert(call); |
857 | 871 | ||
858 | LOGGER_DEBUG("Reported loss of %f%%", loss*100); | 872 | LOGGER_DEBUG("Reported loss of %f%%", loss * 100); |
859 | 873 | ||
860 | if (loss < .01f) | 874 | if (loss < .01f) |
861 | return; | 875 | return; |
862 | 876 | ||
863 | pthread_mutex_lock(call->av->mutex); | 877 | pthread_mutex_lock(call->av->mutex); |
878 | |||
864 | if (!call->av->bcb.first) { | 879 | if (!call->av->bcb.first) { |
865 | pthread_mutex_unlock(call->av->mutex); | 880 | pthread_mutex_unlock(call->av->mutex); |
866 | LOGGER_WARNING("No callback to report loss on"); | 881 | LOGGER_WARNING("No callback to report loss on"); |
867 | return; | 882 | return; |
868 | } | 883 | } |
869 | 884 | ||
870 | if (call->video_bit_rate) | 885 | if (call->video_bit_rate) |
871 | (*call->av->bcb.first) (call->av, friend_number, call->audio_bit_rate, | 886 | (*call->av->bcb.first) (call->av, friend_number, call->audio_bit_rate, |
872 | call->video_bit_rate - (call->video_bit_rate * loss), | 887 | call->video_bit_rate - (call->video_bit_rate * loss), |
@@ -875,7 +890,7 @@ void callback_bwc(BWControler* bwc, uint32_t friend_number, float loss, void* us | |||
875 | (*call->av->bcb.first) (call->av, friend_number, | 890 | (*call->av->bcb.first) (call->av, friend_number, |
876 | call->audio_bit_rate - (call->audio_bit_rate * loss), | 891 | call->audio_bit_rate - (call->audio_bit_rate * loss), |
877 | 0, call->av->bcb.second); | 892 | 0, call->av->bcb.second); |
878 | 893 | ||
879 | pthread_mutex_unlock(call->av->mutex); | 894 | pthread_mutex_unlock(call->av->mutex); |
880 | } | 895 | } |
881 | int callback_invite(void *toxav_inst, MSICall *call) | 896 | int callback_invite(void *toxav_inst, MSICall *call) |
@@ -1167,7 +1182,7 @@ bool call_prepare_transmission(ToxAVCall *call) | |||
1167 | 1182 | ||
1168 | /* Prepare bwc */ | 1183 | /* Prepare bwc */ |
1169 | call->bwc = bwc_new(av->m, call->friend_number, callback_bwc, call); | 1184 | call->bwc = bwc_new(av->m, call->friend_number, callback_bwc, call); |
1170 | 1185 | ||
1171 | { /* Prepare audio */ | 1186 | { /* Prepare audio */ |
1172 | call->audio.second = ac_new(av, call->friend_number, av->acb.first, av->acb.second); | 1187 | call->audio.second = ac_new(av, call->friend_number, av->acb.first, av->acb.second); |
1173 | 1188 | ||
@@ -1236,7 +1251,7 @@ void call_kill_transmission(ToxAVCall *call) | |||
1236 | pthread_mutex_unlock(call->mutex); | 1251 | pthread_mutex_unlock(call->mutex); |
1237 | 1252 | ||
1238 | bwc_kill(call->bwc); | 1253 | bwc_kill(call->bwc); |
1239 | 1254 | ||
1240 | rtp_kill(call->audio.first); | 1255 | rtp_kill(call->audio.first); |
1241 | ac_kill(call->audio.second); | 1256 | ac_kill(call->audio.second); |
1242 | call->audio.first = NULL; | 1257 | call->audio.first = NULL; |