diff options
author | irungentoo <irungentoo@gmail.com> | 2014-11-24 20:24:59 -0500 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-11-24 20:24:59 -0500 |
commit | 279c33c01a9ca721b986aabf72fa982936b20c9e (patch) | |
tree | 4c0d289c6d74788989024485d44a4f5c7fec6efc /auto_tests/toxav_basic_test.c | |
parent | c67bc3399faae541d64309412326ae92262b1282 (diff) | |
parent | 386c9748d48d3bb4513e8e5c32e2b30a4d6a00d4 (diff) |
Merge branch 'master' of https://github.com/mannol/toxcore
Diffstat (limited to 'auto_tests/toxav_basic_test.c')
-rw-r--r-- | auto_tests/toxav_basic_test.c | 147 |
1 files changed, 93 insertions, 54 deletions
diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c index c6481366..c5a9a3db 100644 --- a/auto_tests/toxav_basic_test.c +++ b/auto_tests/toxav_basic_test.c | |||
@@ -11,6 +11,8 @@ | |||
11 | #include <time.h> | 11 | #include <time.h> |
12 | #include <assert.h> | 12 | #include <assert.h> |
13 | 13 | ||
14 | #include <vpx/vpx_image.h> | ||
15 | |||
14 | #include "../toxcore/tox.h" | 16 | #include "../toxcore/tox.h" |
15 | #include "../toxcore/logger.h" | 17 | #include "../toxcore/logger.h" |
16 | #include "../toxcore/crypto_core.h" | 18 | #include "../toxcore/crypto_core.h" |
@@ -33,7 +35,7 @@ typedef enum _CallStatus { | |||
33 | Ringing, | 35 | Ringing, |
34 | Ended, | 36 | Ended, |
35 | Rejected, | 37 | Rejected, |
36 | Cancel, | 38 | Canceled, |
37 | TimedOut | 39 | TimedOut |
38 | 40 | ||
39 | } CallStatus; | 41 | } CallStatus; |
@@ -66,36 +68,23 @@ void callback_recv_invite ( void *av, int32_t call_index, void *_arg ) | |||
66 | { | 68 | { |
67 | Status *cast = _arg; | 69 | Status *cast = _arg; |
68 | 70 | ||
69 | /* Bob always receives invite */ | 71 | if (cast->Alice.av == av) { |
70 | cast->Bob.status = Ringing; | 72 | // ... |
71 | cast->Bob.call_index = call_index; | 73 | } else if (cast->Bob.av == av) { |
74 | /* Bob always receives invite */ | ||
75 | cast->Bob.status = Ringing; | ||
76 | cast->Bob.call_index = call_index; | ||
77 | } | ||
72 | } | 78 | } |
73 | void callback_recv_ringing ( void *av, int32_t call_index, void *_arg ) | 79 | void callback_recv_ringing ( void *av, int32_t call_index, void *_arg ) |
74 | { | 80 | { |
75 | Status *cast = _arg; | 81 | Status *cast = _arg; |
76 | 82 | ||
77 | /* Alice always sends invite */ | 83 | if (cast->Alice.av == av) { |
78 | cast->Alice.status = Ringing; | 84 | /* Alice always sends invite */ |
79 | } | 85 | cast->Alice.status = Ringing; |
80 | void callback_recv_starting ( void *av, int32_t call_index, void *_arg ) | 86 | } else if (cast->Bob.av == av) { |
81 | { | 87 | // ... |
82 | Status *cast = _arg; | ||
83 | |||
84 | /* Alice always sends invite */ | ||
85 | printf("Call started on Alice side...\n"); | ||
86 | cast->Alice.status = InCall; | ||
87 | toxav_prepare_transmission(av, call_index, av_jbufdc, av_VADd, 1); | ||
88 | } | ||
89 | void callback_recv_ending ( void *av, int32_t call_index, void *_arg ) | ||
90 | { | ||
91 | Status *cast = _arg; | ||
92 | |||
93 | if ( cast->Alice.status == Rejected) { | ||
94 | printf ( "Call ended for Bob!\n" ); | ||
95 | cast->Bob.status = Ended; | ||
96 | } else { | ||
97 | printf ( "Call ended for Alice!\n" ); | ||
98 | cast->Alice.status = Ended; | ||
99 | } | 88 | } |
100 | } | 89 | } |
101 | 90 | ||
@@ -104,17 +93,26 @@ void callback_call_started ( void *av, int32_t call_index, void *_arg ) | |||
104 | { | 93 | { |
105 | Status *cast = _arg; | 94 | Status *cast = _arg; |
106 | 95 | ||
107 | /* Alice always sends invite */ | 96 | if (cast->Alice.av == av) { |
108 | printf("Call started on Bob side...\n"); | 97 | printf("Call started on Alices side...\n"); |
109 | cast->Bob.status = InCall; | 98 | cast->Alice.status = InCall; |
110 | toxav_prepare_transmission(av, call_index, av_jbufdc, av_VADd, 1); | 99 | toxav_prepare_transmission(av, call_index, 1); |
100 | } else if (cast->Bob.av == av) { | ||
101 | printf("Call started on Bob side...\n"); | ||
102 | cast->Bob.status = InCall; | ||
103 | toxav_prepare_transmission(av, call_index, 1); | ||
104 | } | ||
111 | } | 105 | } |
112 | void callback_call_canceled ( void *av, int32_t call_index, void *_arg ) | 106 | void callback_call_canceled ( void *av, int32_t call_index, void *_arg ) |
113 | { | 107 | { |
114 | Status *cast = _arg; | 108 | Status *cast = _arg; |
115 | 109 | ||
116 | printf ( "Call Canceled for Bob!\n" ); | 110 | if (cast->Alice.av == av) { |
117 | cast->Bob.status = Cancel; | 111 | // ... |
112 | } else if (cast->Bob.av == av) { | ||
113 | printf ( "Call Canceled for Bob!\n" ); | ||
114 | cast->Bob.status = Canceled; | ||
115 | } | ||
118 | } | 116 | } |
119 | void callback_call_rejected ( void *av, int32_t call_index, void *_arg ) | 117 | void callback_call_rejected ( void *av, int32_t call_index, void *_arg ) |
120 | { | 118 | { |
@@ -122,23 +120,58 @@ void callback_call_rejected ( void *av, int32_t call_index, void *_arg ) | |||
122 | 120 | ||
123 | printf ( "Call rejected by Bob!\n" | 121 | printf ( "Call rejected by Bob!\n" |
124 | "Call ended for Alice!\n" ); | 122 | "Call ended for Alice!\n" ); |
123 | |||
125 | /* If Bob rejects, call is ended for alice and she sends ending */ | 124 | /* If Bob rejects, call is ended for alice and she sends ending */ |
126 | cast->Alice.status = Rejected; | 125 | if (cast->Alice.av == av) { |
126 | cast->Alice.status = Rejected; | ||
127 | } else if (cast->Bob.av == av) { | ||
128 | //... ignor | ||
129 | } | ||
127 | } | 130 | } |
128 | void callback_call_ended ( void *av, int32_t call_index, void *_arg ) | 131 | void callback_call_ended ( void *av, int32_t call_index, void *_arg ) |
129 | { | 132 | { |
130 | Status *cast = _arg; | 133 | Status *cast = _arg; |
131 | 134 | ||
132 | printf ( "Call ended for Bob!\n" ); | 135 | if (cast->Alice.av == av) { |
133 | cast->Bob.status = Ended; | 136 | printf ( "Call ended for Alice!\n" ); |
137 | cast->Alice.status = Ended; | ||
138 | } else if (cast->Bob.av == av) { | ||
139 | printf ( "Call ended for Bob!\n" ); | ||
140 | cast->Bob.status = Ended; | ||
141 | } | ||
134 | } | 142 | } |
135 | 143 | ||
136 | void callback_call_type_change ( void *av, int32_t call_index, void *_arg ) | 144 | void callback_peer_cs_change ( void *av, int32_t call_index, void *_arg ) |
137 | { | 145 | { |
138 | ToxAvCSettings csettings; | 146 | ToxAvCSettings csettings; |
139 | toxav_get_peer_csettings(av, call_index, 0, &csettings); | 147 | toxav_get_peer_csettings(av, call_index, 0, &csettings); |
140 | 148 | ||
141 | printf("New settings: \n" | 149 | printf("Peer changing settings to: \n" |
150 | "Type: %u \n" | ||
151 | "Video bitrate: %u \n" | ||
152 | "Video height: %u \n" | ||
153 | "Video width: %u \n" | ||
154 | "Audio bitrate: %u \n" | ||
155 | "Audio framedur: %u \n" | ||
156 | "Audio sample rate: %u \n" | ||
157 | "Audio channels: %u \n", | ||
158 | csettings.call_type, | ||
159 | csettings.video_bitrate, | ||
160 | csettings.max_video_height, | ||
161 | csettings.max_video_width, | ||
162 | csettings.audio_bitrate, | ||
163 | csettings.audio_frame_duration, | ||
164 | csettings.audio_sample_rate, | ||
165 | csettings.audio_channels | ||
166 | ); | ||
167 | } | ||
168 | |||
169 | void callback_self_cs_change ( void *av, int32_t call_index, void *_arg ) | ||
170 | { | ||
171 | ToxAvCSettings csettings; | ||
172 | toxav_get_peer_csettings(av, call_index, 0, &csettings); | ||
173 | |||
174 | printf("Changed settings to: \n" | ||
142 | "Type: %u \n" | 175 | "Type: %u \n" |
143 | "Video bitrate: %u \n" | 176 | "Video bitrate: %u \n" |
144 | "Video height: %u \n" | 177 | "Video height: %u \n" |
@@ -162,16 +195,19 @@ void callback_requ_timeout ( void *av, int32_t call_index, void *_arg ) | |||
162 | { | 195 | { |
163 | Status *cast = _arg; | 196 | Status *cast = _arg; |
164 | printf("Call timed-out!\n"); | 197 | printf("Call timed-out!\n"); |
165 | cast->Alice.status = TimedOut; | ||
166 | } | ||
167 | 198 | ||
168 | static void callback_audio(ToxAv *av, int32_t call_index, int16_t *data, int length, void *userdata) | 199 | if (cast->Alice.av == av) { |
169 | { | 200 | cast->Alice.status = TimedOut; |
201 | } else if (cast->Bob.av == av) { | ||
202 | cast->Bob.status = TimedOut; | ||
203 | } | ||
170 | } | 204 | } |
171 | 205 | ||
172 | static void callback_video(ToxAv *av, int32_t call_index, vpx_image_t *img, void *userdata) | 206 | void callback_audio (void *agent, int32_t call_idx, const int16_t *PCM, uint16_t size, void *data) |
173 | { | 207 | {} |
174 | } | 208 | |
209 | void callback_video (void *agent, int32_t call_idx, const vpx_image_t *img, void *data) | ||
210 | {} | ||
175 | 211 | ||
176 | void register_callbacks(ToxAv *av, void *data) | 212 | void register_callbacks(ToxAv *av, void *data) |
177 | { | 213 | { |
@@ -180,17 +216,12 @@ void register_callbacks(ToxAv *av, void *data) | |||
180 | toxav_register_callstate_callback(av, callback_call_rejected, av_OnReject, data); | 216 | toxav_register_callstate_callback(av, callback_call_rejected, av_OnReject, data); |
181 | toxav_register_callstate_callback(av, callback_call_ended, av_OnEnd, data); | 217 | toxav_register_callstate_callback(av, callback_call_ended, av_OnEnd, data); |
182 | toxav_register_callstate_callback(av, callback_recv_invite, av_OnInvite, data); | 218 | toxav_register_callstate_callback(av, callback_recv_invite, av_OnInvite, data); |
183 | |||
184 | toxav_register_callstate_callback(av, callback_recv_ringing, av_OnRinging, data); | 219 | toxav_register_callstate_callback(av, callback_recv_ringing, av_OnRinging, data); |
185 | toxav_register_callstate_callback(av, callback_recv_starting, av_OnStarting, data); | ||
186 | toxav_register_callstate_callback(av, callback_recv_ending, av_OnEnding, data); | ||
187 | |||
188 | toxav_register_callstate_callback(av, callback_requ_timeout, av_OnRequestTimeout, data); | 220 | toxav_register_callstate_callback(av, callback_requ_timeout, av_OnRequestTimeout, data); |
189 | toxav_register_callstate_callback(av, callback_call_type_change, av_OnMediaChange, data); | 221 | toxav_register_callstate_callback(av, callback_peer_cs_change, av_OnPeerCSChange, data); |
190 | 222 | toxav_register_callstate_callback(av, callback_self_cs_change, av_OnSelfCSChange, data); | |
191 | 223 | toxav_register_audio_callback(callback_audio, NULL); | |
192 | toxav_register_audio_recv_callback(av, callback_audio, NULL); | 224 | toxav_register_video_callback(callback_video, NULL); |
193 | toxav_register_video_recv_callback(av, callback_video, NULL); | ||
194 | } | 225 | } |
195 | 226 | ||
196 | 227 | ||
@@ -202,6 +233,7 @@ void register_callbacks(ToxAv *av, void *data) | |||
202 | #define CALL_AND_START_LOOP(AliceCallType, BobCallType) \ | 233 | #define CALL_AND_START_LOOP(AliceCallType, BobCallType) \ |
203 | { int step = 0, running = 1; while (running) {\ | 234 | { int step = 0, running = 1; while (running) {\ |
204 | tox_do(bootstrap_node); tox_do(Alice); tox_do(Bob); \ | 235 | tox_do(bootstrap_node); tox_do(Alice); tox_do(Bob); \ |
236 | toxav_do(status_control.Bob.av); toxav_do(status_control.Alice.av); \ | ||
205 | switch ( step ) {\ | 237 | switch ( step ) {\ |
206 | case 0: /* Alice */ printf("Alice is calling...\n");\ | 238 | case 0: /* Alice */ printf("Alice is calling...\n");\ |
207 | toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, &muhcaps, 10); step++; break;\ | 239 | toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, &muhcaps, 10); step++; break;\ |
@@ -496,6 +528,10 @@ START_TEST(test_AV_flows) | |||
496 | tox_do(Alice); | 528 | tox_do(Alice); |
497 | tox_do(Bob); | 529 | tox_do(Bob); |
498 | 530 | ||
531 | toxav_do(status_control.Alice.av); | ||
532 | toxav_do(status_control.Bob.av); | ||
533 | |||
534 | |||
499 | switch ( step ) { | 535 | switch ( step ) { |
500 | case 0: /* Alice */ | 536 | case 0: /* Alice */ |
501 | printf("Alice is calling...\n"); | 537 | printf("Alice is calling...\n"); |
@@ -514,7 +550,7 @@ START_TEST(test_AV_flows) | |||
514 | break; | 550 | break; |
515 | 551 | ||
516 | case 2: /* Wait for Both to have status ended */ | 552 | case 2: /* Wait for Both to have status ended */ |
517 | if (status_control.Bob.status == Cancel) running = 0; | 553 | if (status_control.Bob.status == Canceled) running = 0; |
518 | 554 | ||
519 | break; | 555 | break; |
520 | } | 556 | } |
@@ -537,6 +573,9 @@ START_TEST(test_AV_flows) | |||
537 | tox_do(Alice); | 573 | tox_do(Alice); |
538 | tox_do(Bob); | 574 | tox_do(Bob); |
539 | 575 | ||
576 | toxav_do(status_control.Alice.av); | ||
577 | toxav_do(status_control.Bob.av); | ||
578 | |||
540 | switch ( step ) { | 579 | switch ( step ) { |
541 | case 0: | 580 | case 0: |
542 | printf("Alice is calling...\n"); | 581 | printf("Alice is calling...\n"); |