diff options
author | Gregory Mullen (grayhatter) <greg@grayhatter.com> | 2016-09-11 16:27:03 -0700 |
---|---|---|
committer | Gregory Mullen (grayhatter) <greg@grayhatter.com> | 2016-09-17 14:05:51 -0700 |
commit | 21f8db12c45bd56293262cd4abfb73cd9abec821 (patch) | |
tree | 580729367d00e1eb7e0c4d533777d22af7d7ffc5 /testing/av_test.c | |
parent | 5da85c582d97d746887da407153afc0acf0a4215 (diff) |
Make ToxAV stateless
Diffstat (limited to 'testing/av_test.c')
-rw-r--r-- | testing/av_test.c | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/testing/av_test.c b/testing/av_test.c index 28796abb..46212255 100644 --- a/testing/av_test.c +++ b/testing/av_test.c | |||
@@ -80,7 +80,9 @@ typedef struct { | |||
80 | 80 | ||
81 | struct toxav_thread_data { | 81 | struct toxav_thread_data { |
82 | ToxAV *AliceAV; | 82 | ToxAV *AliceAV; |
83 | void *AliceCC; | ||
83 | ToxAV *BobAV; | 84 | ToxAV *BobAV; |
85 | void *BobCC; | ||
84 | int32_t sig; | 86 | int32_t sig; |
85 | }; | 87 | }; |
86 | 88 | ||
@@ -270,31 +272,32 @@ static void initialize_tox(Tox **bootstrap, ToxAV **AliceAV, CallControl *AliceC | |||
270 | 272 | ||
271 | 273 | ||
272 | /* Alice */ | 274 | /* Alice */ |
273 | toxav_callback_call(*AliceAV, t_toxav_call_cb, AliceCC); | 275 | toxav_callback_call(*AliceAV, t_toxav_call_cb); |
274 | toxav_callback_call_state(*AliceAV, t_toxav_call_state_cb, AliceCC); | 276 | toxav_callback_call_state(*AliceAV, t_toxav_call_state_cb); |
275 | toxav_callback_bit_rate_status(*AliceAV, t_toxav_bit_rate_status_cb, AliceCC); | 277 | toxav_callback_bit_rate_status(*AliceAV, t_toxav_bit_rate_status_cb); |
276 | toxav_callback_video_receive_frame(*AliceAV, t_toxav_receive_video_frame_cb, AliceCC); | 278 | toxav_callback_video_receive_frame(*AliceAV, t_toxav_receive_video_frame_cb); |
277 | toxav_callback_audio_receive_frame(*AliceAV, t_toxav_receive_audio_frame_cb, AliceCC); | 279 | toxav_callback_audio_receive_frame(*AliceAV, t_toxav_receive_audio_frame_cb); |
278 | 280 | ||
279 | /* Bob */ | 281 | /* Bob */ |
280 | toxav_callback_call(*BobAV, t_toxav_call_cb, BobCC); | 282 | toxav_callback_call(*BobAV, t_toxav_call_cb); |
281 | toxav_callback_call_state(*BobAV, t_toxav_call_state_cb, BobCC); | 283 | toxav_callback_call_state(*BobAV, t_toxav_call_state_cb); |
282 | toxav_callback_bit_rate_status(*BobAV, t_toxav_bit_rate_status_cb, BobCC); | 284 | toxav_callback_bit_rate_status(*BobAV, t_toxav_bit_rate_status_cb); |
283 | toxav_callback_video_receive_frame(*BobAV, t_toxav_receive_video_frame_cb, BobCC); | 285 | toxav_callback_video_receive_frame(*BobAV, t_toxav_receive_video_frame_cb); |
284 | toxav_callback_audio_receive_frame(*BobAV, t_toxav_receive_audio_frame_cb, BobCC); | 286 | toxav_callback_audio_receive_frame(*BobAV, t_toxav_receive_audio_frame_cb); |
285 | 287 | ||
286 | 288 | ||
287 | printf("Created 2 instances of ToxAV\n"); | 289 | printf("Created 2 instances of ToxAV\n"); |
288 | printf("All set after %llu seconds!\n", time(NULL) - cur_time); | 290 | printf("All set after %llu seconds!\n", time(NULL) - cur_time); |
289 | } | 291 | } |
290 | static int iterate_tox(Tox *bootstrap, ToxAV *AliceAV, ToxAV *BobAV, void *userdata) | 292 | static int iterate_tox(Tox *bootstrap, ToxAV *AliceAV, void *aCC, ToxAV *BobAV, void *bCC) |
291 | { | 293 | { |
292 | tox_iterate(bootstrap, userdata); | 294 | tox_iterate(bootstrap, NULL); |
293 | tox_iterate(toxav_get_tox(AliceAV), userdata); | 295 | tox_iterate(toxav_get_tox(AliceAV), aCC); |
294 | tox_iterate(toxav_get_tox(BobAV), userdata); | 296 | tox_iterate(toxav_get_tox(BobAV), bCC); |
295 | 297 | ||
296 | return MIN(tox_iteration_interval(toxav_get_tox(AliceAV)), tox_iteration_interval(toxav_get_tox(BobAV))); | 298 | return MIN(tox_iteration_interval(toxav_get_tox(AliceAV)), tox_iteration_interval(toxav_get_tox(BobAV))); |
297 | } | 299 | } |
300 | |||
298 | static void *iterate_toxav(void *data) | 301 | static void *iterate_toxav(void *data) |
299 | { | 302 | { |
300 | struct toxav_thread_data *data_cast = data; | 303 | struct toxav_thread_data *data_cast = data; |
@@ -303,8 +306,8 @@ static void *iterate_toxav(void *data) | |||
303 | #endif | 306 | #endif |
304 | 307 | ||
305 | while (data_cast->sig == 0) { | 308 | while (data_cast->sig == 0) { |
306 | toxav_iterate(data_cast->AliceAV); | 309 | toxav_iterate(data_cast->AliceAV, data_cast->AliceCC); |
307 | toxav_iterate(data_cast->BobAV); | 310 | toxav_iterate(data_cast->BobAV, data_cast->BobCC); |
308 | int rc = MIN(toxav_iteration_interval(data_cast->AliceAV), toxav_iteration_interval(data_cast->BobAV)); | 311 | int rc = MIN(toxav_iteration_interval(data_cast->AliceAV), toxav_iteration_interval(data_cast->BobAV)); |
309 | 312 | ||
310 | printf("\rIteration interval: %d ", rc); | 313 | printf("\rIteration interval: %d ", rc); |
@@ -549,7 +552,7 @@ CHECK_ARG: | |||
549 | } | 552 | } |
550 | 553 | ||
551 | while (!BobCC.incoming) { | 554 | while (!BobCC.incoming) { |
552 | iterate_tox(bootstrap, AliceAV, BobAV, NULL); | 555 | iterate_tox(bootstrap, AliceAV, &AliceCC, BobAV, &BobCC); |
553 | } | 556 | } |
554 | 557 | ||
555 | { /* Answer */ | 558 | { /* Answer */ |
@@ -563,7 +566,7 @@ CHECK_ARG: | |||
563 | } | 566 | } |
564 | 567 | ||
565 | while (AliceCC.state == 0) { | 568 | while (AliceCC.state == 0) { |
566 | iterate_tox(bootstrap, AliceAV, BobAV, NULL); | 569 | iterate_tox(bootstrap, AliceAV, &AliceCC, BobAV, &BobCC); |
567 | } | 570 | } |
568 | 571 | ||
569 | /* Open audio file */ | 572 | /* Open audio file */ |
@@ -628,7 +631,7 @@ CHECK_ARG: | |||
628 | } | 631 | } |
629 | } | 632 | } |
630 | 633 | ||
631 | iterate_tox(bootstrap, AliceAV, BobAV, NULL); | 634 | iterate_tox(bootstrap, AliceAV, &AliceCC, BobAV, &BobCC); |
632 | c_sleep((audio_frame_duration - (current_time_monotonic() - enc_start_time) - 1)); | 635 | c_sleep((audio_frame_duration - (current_time_monotonic() - enc_start_time) - 1)); |
633 | } | 636 | } |
634 | 637 | ||
@@ -647,7 +650,7 @@ CHECK_ARG: | |||
647 | } | 650 | } |
648 | } | 651 | } |
649 | 652 | ||
650 | iterate_tox(bootstrap, AliceAV, BobAV, NULL); | 653 | iterate_tox(bootstrap, AliceAV, &AliceCC, BobAV, &BobCC); |
651 | assert(BobCC.state == TOXAV_FRIEND_CALL_STATE_FINISHED); | 654 | assert(BobCC.state == TOXAV_FRIEND_CALL_STATE_FINISHED); |
652 | 655 | ||
653 | /* Stop decode thread */ | 656 | /* Stop decode thread */ |
@@ -690,7 +693,7 @@ CHECK_ARG: | |||
690 | } | 693 | } |
691 | 694 | ||
692 | while (!BobCC.incoming) { | 695 | while (!BobCC.incoming) { |
693 | iterate_tox(bootstrap, AliceAV, BobAV, NULL); | 696 | iterate_tox(bootstrap, AliceAV, &AliceCC, BobAV, &BobCC); |
694 | } | 697 | } |
695 | 698 | ||
696 | { /* Answer */ | 699 | { /* Answer */ |
@@ -703,12 +706,14 @@ CHECK_ARG: | |||
703 | } | 706 | } |
704 | } | 707 | } |
705 | 708 | ||
706 | iterate_tox(bootstrap, AliceAV, BobAV, NULL); | 709 | iterate_tox(bootstrap, AliceAV, &AliceCC, BobAV, &BobCC); |
707 | 710 | ||
708 | /* Start decode thread */ | 711 | /* Start decode thread */ |
709 | struct toxav_thread_data data = { | 712 | struct toxav_thread_data data = { |
710 | .AliceAV = AliceAV, | 713 | .AliceAV = AliceAV, |
714 | .AliceCC = &AliceCC, | ||
711 | .BobAV = BobAV, | 715 | .BobAV = BobAV, |
716 | .BobCC = &BobCC, | ||
712 | .sig = 0 | 717 | .sig = 0 |
713 | }; | 718 | }; |
714 | 719 | ||
@@ -735,7 +740,7 @@ CHECK_ARG: | |||
735 | } | 740 | } |
736 | 741 | ||
737 | send_opencv_img(AliceAV, 0, frame); | 742 | send_opencv_img(AliceAV, 0, frame); |
738 | iterate_tox(bootstrap, AliceAV, BobAV, NULL); | 743 | iterate_tox(bootstrap, AliceAV, &AliceCC, BobAV, &BobCC); |
739 | c_sleep(10); | 744 | c_sleep(10); |
740 | } | 745 | } |
741 | 746 | ||
@@ -751,7 +756,7 @@ CHECK_ARG: | |||
751 | } | 756 | } |
752 | } | 757 | } |
753 | 758 | ||
754 | iterate_tox(bootstrap, AliceAV, BobAV, NULL); | 759 | iterate_tox(bootstrap, AliceAV, &AliceCC, BobAV, &BobCC); |
755 | assert(BobCC.state == TOXAV_FRIEND_CALL_STATE_FINISHED); | 760 | assert(BobCC.state == TOXAV_FRIEND_CALL_STATE_FINISHED); |
756 | 761 | ||
757 | /* Stop decode thread */ | 762 | /* Stop decode thread */ |