diff options
Diffstat (limited to 'auto_tests/toxav_basic_test.c')
-rw-r--r-- | auto_tests/toxav_basic_test.c | 236 |
1 files changed, 149 insertions, 87 deletions
diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c index ea74f90b..c35af270 100644 --- a/auto_tests/toxav_basic_test.c +++ b/auto_tests/toxav_basic_test.c | |||
@@ -12,6 +12,8 @@ | |||
12 | #include <assert.h> | 12 | #include <assert.h> |
13 | 13 | ||
14 | #include "../toxcore/tox.h" | 14 | #include "../toxcore/tox.h" |
15 | #include "../toxcore/logger.h" | ||
16 | #include "../toxcore/crypto_core.h" | ||
15 | #include "../toxav/toxav.h" | 17 | #include "../toxav/toxav.h" |
16 | 18 | ||
17 | #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) | 19 | #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) |
@@ -22,6 +24,7 @@ | |||
22 | #endif | 24 | #endif |
23 | 25 | ||
24 | 26 | ||
27 | |||
25 | typedef enum _CallStatus { | 28 | typedef enum _CallStatus { |
26 | none, | 29 | none, |
27 | InCall, | 30 | InCall, |
@@ -36,6 +39,7 @@ typedef struct _Party { | |||
36 | CallStatus status; | 39 | CallStatus status; |
37 | ToxAv *av; | 40 | ToxAv *av; |
38 | time_t *CallStarted; | 41 | time_t *CallStarted; |
42 | int call_index; | ||
39 | } Party; | 43 | } Party; |
40 | 44 | ||
41 | typedef struct _Status { | 45 | typedef struct _Status { |
@@ -43,44 +47,46 @@ typedef struct _Status { | |||
43 | Party Bob; | 47 | Party Bob; |
44 | } Status; | 48 | } Status; |
45 | 49 | ||
50 | /* My default settings */ | ||
51 | static ToxAvCodecSettings muhcaps; | ||
52 | |||
46 | void accept_friend_request(Tox *m, uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata) | 53 | void accept_friend_request(Tox *m, uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata) |
47 | { | 54 | { |
48 | if (length == 15 && memcmp("ILIKESMALLTITS", data, 15) == 0) { | 55 | if (length == 7 && memcmp("gentoo", data, 7) == 0) { |
49 | tox_add_friend_norequest(m, public_key); | 56 | tox_add_friend_norequest(m, public_key); |
50 | } | 57 | } |
51 | } | 58 | } |
52 | 59 | ||
53 | 60 | ||
54 | /******************************************************************************/ | 61 | /******************************************************************************/ |
55 | void callback_recv_invite ( void *_arg ) | 62 | void callback_recv_invite ( int32_t call_index, void *_arg ) |
56 | { | 63 | { |
57 | Status *cast = _arg; | 64 | Status *cast = _arg; |
58 | 65 | ||
59 | /* Bob always receives invite */ | 66 | /* Bob always receives invite */ |
60 | cast->Bob.status = Ringing; | 67 | cast->Bob.status = Ringing; |
68 | cast->Bob.call_index = call_index; | ||
61 | } | 69 | } |
62 | void callback_recv_ringing ( void *_arg ) | 70 | void callback_recv_ringing ( int32_t call_index, void *_arg ) |
63 | { | 71 | { |
64 | Status *cast = _arg; | 72 | Status *cast = _arg; |
65 | 73 | ||
66 | /* Alice always sends invite */ | 74 | /* Alice always sends invite */ |
67 | cast->Alice.status = Ringing; | 75 | cast->Alice.status = Ringing; |
68 | } | 76 | } |
69 | void callback_recv_starting ( void *_arg ) | 77 | void callback_recv_starting ( int32_t call_index, void *_arg ) |
70 | { | 78 | { |
71 | Status *cast = _arg; | 79 | Status *cast = _arg; |
72 | 80 | ||
73 | /* Alice always sends invite */ | 81 | /* Alice always sends invite */ |
74 | printf("Call started on Alice side...\n"); | 82 | printf("Call started on Alice side...\n"); |
75 | cast->Alice.status = InCall; | 83 | cast->Alice.status = InCall; |
76 | toxav_prepare_transmission(cast->Alice.av, 1); | 84 | toxav_prepare_transmission(cast->Alice.av, call_index, &muhcaps, 1); |
77 | } | 85 | } |
78 | void callback_recv_ending ( void *_arg ) | 86 | void callback_recv_ending ( int32_t call_index, void *_arg ) |
79 | { | 87 | { |
80 | Status *cast = _arg; | 88 | Status *cast = _arg; |
81 | 89 | ||
82 | |||
83 | |||
84 | if ( cast->Alice.status == Rejected) { | 90 | if ( cast->Alice.status == Rejected) { |
85 | printf ( "Call ended for Bob!\n" ); | 91 | printf ( "Call ended for Bob!\n" ); |
86 | cast->Bob.status = Ended; | 92 | cast->Bob.status = Ended; |
@@ -90,28 +96,28 @@ void callback_recv_ending ( void *_arg ) | |||
90 | } | 96 | } |
91 | } | 97 | } |
92 | 98 | ||
93 | void callback_recv_error ( void *_arg ) | 99 | void callback_recv_error ( int32_t call_index, void *_arg ) |
94 | { | 100 | { |
95 | ck_assert_msg(0, "AV internal error"); | 101 | ck_assert_msg(0, "AV internal error"); |
96 | } | 102 | } |
97 | 103 | ||
98 | void callback_call_started ( void *_arg ) | 104 | void callback_call_started ( int32_t call_index, void *_arg ) |
99 | { | 105 | { |
100 | Status *cast = _arg; | 106 | Status *cast = _arg; |
101 | 107 | ||
102 | /* Alice always sends invite */ | 108 | /* Alice always sends invite */ |
103 | printf("Call started on Bob side...\n"); | 109 | printf("Call started on Bob side...\n"); |
104 | cast->Bob.status = InCall; | 110 | cast->Bob.status = InCall; |
105 | toxav_prepare_transmission(cast->Bob.av, 1); | 111 | toxav_prepare_transmission(cast->Bob.av, call_index, &muhcaps, 1); |
106 | } | 112 | } |
107 | void callback_call_canceled ( void *_arg ) | 113 | void callback_call_canceled ( int32_t call_index, void *_arg ) |
108 | { | 114 | { |
109 | Status *cast = _arg; | 115 | Status *cast = _arg; |
110 | 116 | ||
111 | printf ( "Call Canceled for Bob!\n" ); | 117 | printf ( "Call Canceled for Bob!\n" ); |
112 | cast->Bob.status = Cancel; | 118 | cast->Bob.status = Cancel; |
113 | } | 119 | } |
114 | void callback_call_rejected ( void *_arg ) | 120 | void callback_call_rejected ( int32_t call_index, void *_arg ) |
115 | { | 121 | { |
116 | Status *cast = _arg; | 122 | Status *cast = _arg; |
117 | 123 | ||
@@ -120,7 +126,7 @@ void callback_call_rejected ( void *_arg ) | |||
120 | /* If Bob rejects, call is ended for alice and she sends ending */ | 126 | /* If Bob rejects, call is ended for alice and she sends ending */ |
121 | cast->Alice.status = Rejected; | 127 | cast->Alice.status = Rejected; |
122 | } | 128 | } |
123 | void callback_call_ended ( void *_arg ) | 129 | void callback_call_ended ( int32_t call_index, void *_arg ) |
124 | { | 130 | { |
125 | Status *cast = _arg; | 131 | Status *cast = _arg; |
126 | 132 | ||
@@ -128,7 +134,7 @@ void callback_call_ended ( void *_arg ) | |||
128 | cast->Bob.status = Ended; | 134 | cast->Bob.status = Ended; |
129 | } | 135 | } |
130 | 136 | ||
131 | void callback_requ_timeout ( void *_arg ) | 137 | void callback_requ_timeout ( int32_t call_index, void *_arg ) |
132 | { | 138 | { |
133 | ck_assert_msg(0, "No answer!"); | 139 | ck_assert_msg(0, "No answer!"); |
134 | } | 140 | } |
@@ -142,9 +148,9 @@ void callback_requ_timeout ( void *_arg ) | |||
142 | tox_do(bootstrap_node); tox_do(Alice); tox_do(Bob); \ | 148 | tox_do(bootstrap_node); tox_do(Alice); tox_do(Bob); \ |
143 | switch ( step ) {\ | 149 | switch ( step ) {\ |
144 | case 0: /* Alice */ printf("Alice is calling...\n");\ | 150 | case 0: /* Alice */ printf("Alice is calling...\n");\ |
145 | toxav_call(status_control.Alice.av, 0, AliceCallType, 10); step++; break;\ | 151 | toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, AliceCallType, 10); step++; break;\ |
146 | case 1: /* Bob */ if (status_control.Bob.status == Ringing) { printf("Bob answers...\n");\ | 152 | case 1: /* Bob */ if (status_control.Bob.status == Ringing) { printf("Bob answers...\n");\ |
147 | cur_time = time(NULL); toxav_answer(status_control.Bob.av, BobCallType); step++; } break; \ | 153 | cur_time = time(NULL); toxav_answer(status_control.Bob.av, status_control.Bob.call_index, BobCallType); step++; } break; \ |
148 | case 2: /* Rtp transmission */ \ | 154 | case 2: /* Rtp transmission */ \ |
149 | if (status_control.Bob.status == InCall && status_control.Alice.status == InCall) | 155 | if (status_control.Bob.status == InCall && status_control.Alice.status == InCall) |
150 | 156 | ||
@@ -153,7 +159,8 @@ void callback_requ_timeout ( void *_arg ) | |||
153 | case 3: /* Wait for Both to have status ended */\ | 159 | case 3: /* Wait for Both to have status ended */\ |
154 | if (status_control.Alice.status == Ended && status_control.Bob.status == Ended) running = 0; break; } c_sleep(20); } } printf("\n"); | 160 | if (status_control.Alice.status == Ended && status_control.Bob.status == Ended) running = 0; break; } c_sleep(20); } } printf("\n"); |
155 | 161 | ||
156 | START_TEST(test_AV) | 162 | START_TEST(test_AV_flows) |
163 | // int test_AV_flows() | ||
157 | { | 164 | { |
158 | long long unsigned int cur_time = time(NULL); | 165 | long long unsigned int cur_time = time(NULL); |
159 | Tox *bootstrap_node = tox_new(0); | 166 | Tox *bootstrap_node = tox_new(0); |
@@ -166,7 +173,7 @@ START_TEST(test_AV) | |||
166 | tox_callback_friend_request(Alice, accept_friend_request, &to_compare); | 173 | tox_callback_friend_request(Alice, accept_friend_request, &to_compare); |
167 | uint8_t address[TOX_FRIEND_ADDRESS_SIZE]; | 174 | uint8_t address[TOX_FRIEND_ADDRESS_SIZE]; |
168 | tox_get_address(Alice, address); | 175 | tox_get_address(Alice, address); |
169 | int test = tox_add_friend(Bob, address, (uint8_t *)"ILIKESMALLTITS", 15); | 176 | int test = tox_add_friend(Bob, address, (uint8_t *)"gentoo", 7); |
170 | 177 | ||
171 | ck_assert_msg(test == 0, "Failed to add friend error code: %i", test); | 178 | ck_assert_msg(test == 0, "Failed to add friend error code: %i", test); |
172 | 179 | ||
@@ -191,15 +198,14 @@ START_TEST(test_AV) | |||
191 | 198 | ||
192 | printf("All set after %llu seconds! Starting call...\n", time(NULL) - cur_time); | 199 | printf("All set after %llu seconds! Starting call...\n", time(NULL) - cur_time); |
193 | 200 | ||
194 | ToxAvCodecSettings muhcaps = av_DefaultSettings; | 201 | muhcaps = av_DefaultSettings; |
195 | muhcaps.video_height = muhcaps.video_width = 128; | 202 | muhcaps.video_height = muhcaps.video_width = 128; |
196 | 203 | ||
197 | Status status_control = { | 204 | Status status_control = { |
198 | {none, toxav_new(Alice, &muhcaps), NULL}, | 205 | {none, toxav_new(Alice, 1), NULL, -1}, |
199 | {none, toxav_new(Bob, &muhcaps), NULL}, | 206 | {none, toxav_new(Bob, 1), NULL, -1}, |
200 | }; | 207 | }; |
201 | 208 | ||
202 | |||
203 | ck_assert_msg(status_control.Alice.av || status_control.Bob.av, "Failed to create 2 toxav instances"); | 209 | ck_assert_msg(status_control.Alice.av || status_control.Bob.av, "Failed to create 2 toxav instances"); |
204 | 210 | ||
205 | 211 | ||
@@ -217,8 +223,13 @@ START_TEST(test_AV) | |||
217 | toxav_register_callstate_callback(callback_requ_timeout, av_OnRequestTimeout, &status_control); | 223 | toxav_register_callstate_callback(callback_requ_timeout, av_OnRequestTimeout, &status_control); |
218 | 224 | ||
219 | 225 | ||
226 | const int frame_size = (av_DefaultSettings.audio_sample_rate * av_DefaultSettings.audio_frame_duration / 1000); | ||
227 | int16_t sample_payload[frame_size]; | ||
228 | randombytes((uint8_t *)sample_payload, sizeof(int16_t) * frame_size); | ||
229 | |||
230 | uint8_t prepared_payload[RTP_PAYLOAD_SIZE]; | ||
231 | int payload_size; | ||
220 | 232 | ||
221 | int16_t sample_payload[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; | ||
222 | vpx_image_t *sample_image = vpx_img_alloc(NULL, VPX_IMG_FMT_I420, 128, 128, 1); | 233 | vpx_image_t *sample_image = vpx_img_alloc(NULL, VPX_IMG_FMT_I420, 128, 128, 1); |
223 | 234 | ||
224 | memcpy(sample_image->planes[VPX_PLANE_Y], sample_payload, 10); | 235 | memcpy(sample_image->planes[VPX_PLANE_Y], sample_payload, 10); |
@@ -233,25 +244,40 @@ START_TEST(test_AV) | |||
233 | /* | 244 | /* |
234 | * Call with audio only on both sides. Alice calls Bob. | 245 | * Call with audio only on both sides. Alice calls Bob. |
235 | */ | 246 | */ |
247 | |||
248 | |||
236 | CALL_AND_START_LOOP(TypeAudio, TypeAudio) { | 249 | CALL_AND_START_LOOP(TypeAudio, TypeAudio) { |
237 | /* Both send */ | 250 | /* Both send */ |
238 | toxav_send_audio(status_control.Alice.av, sample_payload, 10); | 251 | payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, |
239 | toxav_send_audio(status_control.Bob.av, sample_payload, 10); | 252 | 1000, sample_payload, frame_size); |
253 | |||
254 | if ( payload_size < 0 ) { | ||
255 | ck_assert_msg ( 0, "Failed to encode payload" ); | ||
256 | } | ||
257 | |||
258 | toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size); | ||
259 | |||
260 | payload_size = toxav_prepare_audio_frame(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, 1000, | ||
261 | sample_payload, frame_size); | ||
262 | |||
263 | if ( payload_size < 0 ) { | ||
264 | ck_assert_msg ( 0, "Failed to encode payload" ); | ||
265 | } | ||
266 | |||
267 | toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size); | ||
240 | 268 | ||
241 | /* Both receive */ | 269 | /* Both receive */ |
242 | int16_t storage[10]; | 270 | int16_t storage[frame_size]; |
243 | int recved; | 271 | int recved; |
244 | 272 | ||
245 | /* Payload from Alice */ | 273 | /* Payload from Bob */ |
246 | recved = toxav_recv_audio(status_control.Alice.av, 10, storage); | 274 | recved = toxav_recv_audio(status_control.Alice.av, status_control.Alice.call_index, frame_size, storage); |
247 | 275 | ||
248 | if ( recved ) { | 276 | if ( recved ) { |
249 | /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid");*/ | 277 | /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid");*/ |
250 | memset(storage, 0, 10); | ||
251 | } | 278 | } |
252 | 279 | ||
253 | /* Payload from Bob */ | 280 | recved = toxav_recv_audio(status_control.Bob.av, status_control.Bob.call_index, frame_size, storage); |
254 | recved = toxav_recv_audio(status_control.Bob.av, 10, storage); | ||
255 | 281 | ||
256 | if ( recved ) { | 282 | if ( recved ) { |
257 | /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid");*/ | 283 | /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid");*/ |
@@ -259,11 +285,11 @@ START_TEST(test_AV) | |||
259 | 285 | ||
260 | if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */ | 286 | if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */ |
261 | step++; /* This terminates the loop */ | 287 | step++; /* This terminates the loop */ |
262 | toxav_kill_transmission(status_control.Alice.av); | 288 | toxav_kill_transmission(status_control.Alice.av, status_control.Alice.call_index); |
263 | toxav_kill_transmission(status_control.Bob.av); | 289 | toxav_kill_transmission(status_control.Bob.av, status_control.Bob.call_index); |
264 | 290 | ||
265 | /* Call over Alice hangs up */ | 291 | /* Call over Alice hangs up */ |
266 | toxav_hangup(status_control.Alice.av); | 292 | toxav_hangup(status_control.Alice.av, status_control.Alice.call_index); |
267 | } | 293 | } |
268 | } | 294 | } |
269 | TERMINATE_SCOPE() | 295 | TERMINATE_SCOPE() |
@@ -274,38 +300,52 @@ START_TEST(test_AV) | |||
274 | */ | 300 | */ |
275 | CALL_AND_START_LOOP(TypeAudio, TypeVideo) { | 301 | CALL_AND_START_LOOP(TypeAudio, TypeVideo) { |
276 | /* Both send */ | 302 | /* Both send */ |
277 | toxav_send_audio(status_control.Alice.av, sample_payload, 10); | 303 | payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, |
304 | 1000, sample_payload, frame_size); | ||
305 | |||
306 | if ( payload_size < 0 ) { | ||
307 | ck_assert_msg ( 0, "Failed to encode payload" ); | ||
308 | } | ||
309 | |||
310 | toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size); | ||
311 | |||
312 | payload_size = toxav_prepare_audio_frame(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, 1000, | ||
313 | sample_payload, frame_size); | ||
278 | 314 | ||
279 | toxav_send_audio(status_control.Bob.av, sample_payload, 10); | 315 | if ( payload_size < 0 ) { |
280 | toxav_send_video(status_control.Bob.av, sample_image); | 316 | ck_assert_msg ( 0, "Failed to encode payload" ); |
317 | } | ||
318 | |||
319 | toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size); | ||
320 | // toxav_send_video(status_control.Bob.av, status_control.Bob.call_index, sample_image); | ||
281 | 321 | ||
282 | /* Both receive */ | 322 | /* Both receive */ |
283 | int16_t storage[10]; | 323 | int16_t storage[frame_size]; |
284 | vpx_image_t *video_storage; | 324 | vpx_image_t *video_storage; |
285 | int recved; | 325 | int recved; |
286 | 326 | ||
287 | /* Payload from Bob */ | 327 | /* Payload from Bob */ |
288 | recved = toxav_recv_audio(status_control.Alice.av, 10, storage); | 328 | recved = toxav_recv_audio(status_control.Alice.av, status_control.Alice.call_index, frame_size, storage); |
289 | 329 | ||
290 | if ( recved ) { | 330 | if ( recved ) { |
291 | /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid");*/ | 331 | /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid");*/ |
292 | memset(storage, 0, 10); | ||
293 | } | 332 | } |
294 | 333 | ||
295 | /* Video payload */ | 334 | /* Video payload */ |
296 | toxav_recv_video(status_control.Alice.av, &video_storage); | 335 | // toxav_recv_video(status_control.Alice.av, status_control.Alice.call_index, &video_storage); |
297 | 336 | // | |
298 | if ( video_storage ) { | 337 | // if ( video_storage ) { |
299 | /*ck_assert_msg( memcmp(video_storage->planes[VPX_PLANE_Y], sample_payload, 10) == 0 || | 338 | // /*ck_assert_msg( memcmp(video_storage->planes[VPX_PLANE_Y], sample_payload, 10) == 0 || |
300 | memcmp(video_storage->planes[VPX_PLANE_U], sample_payload, 10) == 0 || | 339 | // memcmp(video_storage->planes[VPX_PLANE_U], sample_payload, 10) == 0 || |
301 | memcmp(video_storage->planes[VPX_PLANE_V], sample_payload, 10) == 0 , "Payload from Bob is invalid");*/ | 340 | // memcmp(video_storage->planes[VPX_PLANE_V], sample_payload, 10) == 0 , "Payload from Bob is invalid");*/ |
302 | } | 341 | // vpx_img_free(video_storage); |
342 | // } | ||
303 | 343 | ||
304 | 344 | ||
305 | 345 | ||
306 | 346 | ||
307 | /* Payload from Alice */ | 347 | /* Payload from Alice */ |
308 | recved = toxav_recv_audio(status_control.Bob.av, 10, storage); | 348 | recved = toxav_recv_audio(status_control.Bob.av, status_control.Bob.call_index, frame_size, storage); |
309 | 349 | ||
310 | if ( recved ) { | 350 | if ( recved ) { |
311 | /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid");*/ | 351 | /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid");*/ |
@@ -313,11 +353,11 @@ START_TEST(test_AV) | |||
313 | 353 | ||
314 | if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */ | 354 | if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */ |
315 | step++; /* This terminates the loop */ | 355 | step++; /* This terminates the loop */ |
316 | toxav_kill_transmission(status_control.Alice.av); | 356 | toxav_kill_transmission(status_control.Alice.av, status_control.Alice.call_index); |
317 | toxav_kill_transmission(status_control.Bob.av); | 357 | toxav_kill_transmission(status_control.Bob.av, status_control.Bob.call_index); |
318 | 358 | ||
319 | /* Call over Alice hangs up */ | 359 | /* Call over Alice hangs up */ |
320 | toxav_hangup(status_control.Alice.av); | 360 | toxav_hangup(status_control.Alice.av, status_control.Alice.call_index); |
321 | } | 361 | } |
322 | } | 362 | } |
323 | TERMINATE_SCOPE() | 363 | TERMINATE_SCOPE() |
@@ -328,61 +368,78 @@ START_TEST(test_AV) | |||
328 | */ | 368 | */ |
329 | CALL_AND_START_LOOP(TypeVideo, TypeVideo) { | 369 | CALL_AND_START_LOOP(TypeVideo, TypeVideo) { |
330 | /* Both send */ | 370 | /* Both send */ |
331 | toxav_send_audio(status_control.Alice.av, sample_payload, 10); | ||
332 | toxav_send_video(status_control.Alice.av, sample_image); | ||
333 | 371 | ||
334 | toxav_send_audio(status_control.Bob.av, sample_payload, 10); | 372 | payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, |
335 | toxav_send_video(status_control.Bob.av, sample_image); | 373 | 1000, sample_payload, frame_size); |
374 | |||
375 | if ( payload_size < 0 ) { | ||
376 | ck_assert_msg ( 0, "Failed to encode payload" ); | ||
377 | } | ||
378 | |||
379 | toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size); | ||
380 | |||
381 | payload_size = toxav_prepare_audio_frame(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, 1000, | ||
382 | sample_payload, frame_size); | ||
383 | |||
384 | if ( payload_size < 0 ) { | ||
385 | ck_assert_msg ( 0, "Failed to encode payload" ); | ||
386 | } | ||
387 | |||
388 | toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size); | ||
389 | |||
390 | // toxav_send_video(status_control.Alice.av, status_control.Alice.call_index, sample_image); | ||
391 | // toxav_send_video(status_control.Bob.av, status_control.Bob.call_index, sample_image); | ||
336 | 392 | ||
337 | /* Both receive */ | 393 | /* Both receive */ |
338 | int16_t storage[10]; | 394 | int16_t storage[frame_size]; |
339 | vpx_image_t *video_storage; | 395 | vpx_image_t *video_storage; |
340 | int recved; | 396 | int recved; |
341 | 397 | ||
342 | /* Payload from Bob */ | 398 | /* Payload from Bob */ |
343 | recved = toxav_recv_audio(status_control.Alice.av, 10, storage); | 399 | recved = toxav_recv_audio(status_control.Alice.av, status_control.Alice.call_index, frame_size, storage); |
344 | 400 | ||
345 | if ( recved ) { | 401 | if ( recved ) { |
346 | /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid");*/ | 402 | /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid");*/ |
347 | memset(storage, 0, 10); | ||
348 | } | 403 | } |
349 | 404 | ||
350 | /* Video payload */ | 405 | /* Video payload */ |
351 | toxav_recv_video(status_control.Alice.av, &video_storage); | 406 | // toxav_recv_video(status_control.Alice.av, status_control.Alice.call_index, &video_storage); |
352 | 407 | // | |
353 | if ( video_storage ) { | 408 | // if ( video_storage ) { |
354 | /*ck_assert_msg( memcmp(video_storage->planes[VPX_PLANE_Y], sample_payload, 10) == 0 || | 409 | // /*ck_assert_msg( memcmp(video_storage->planes[VPX_PLANE_Y], sample_payload, 10) == 0 || |
355 | memcmp(video_storage->planes[VPX_PLANE_U], sample_payload, 10) == 0 || | 410 | // memcmp(video_storage->planes[VPX_PLANE_U], sample_payload, 10) == 0 || |
356 | memcmp(video_storage->planes[VPX_PLANE_V], sample_payload, 10) == 0 , "Payload from Bob is invalid");*/ | 411 | // memcmp(video_storage->planes[VPX_PLANE_V], sample_payload, 10) == 0 , "Payload from Bob is invalid");*/ |
357 | } | 412 | // vpx_img_free(video_storage); |
413 | // } | ||
358 | 414 | ||
359 | 415 | ||
360 | 416 | ||
361 | 417 | ||
362 | /* Payload from Alice */ | 418 | /* Payload from Alice */ |
363 | recved = toxav_recv_audio(status_control.Bob.av, 10, storage); | 419 | recved = toxav_recv_audio(status_control.Bob.av, status_control.Bob.call_index, frame_size, storage); |
364 | 420 | ||
365 | if ( recved ) { | 421 | if ( recved ) { |
366 | /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid");*/ | 422 | /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid");*/ |
367 | } | 423 | } |
368 | 424 | ||
369 | /* Video payload */ | 425 | /* Video payload */ |
370 | toxav_recv_video(status_control.Bob.av, &video_storage); | 426 | // toxav_recv_video(status_control.Bob.av, status_control.Bob.call_index, &video_storage); |
371 | 427 | // | |
372 | if ( video_storage ) { | 428 | // if ( video_storage ) { |
373 | /*ck_assert_msg( memcmp(video_storage->planes[VPX_PLANE_Y], sample_payload, 10) == 0 || | 429 | // /*ck_assert_msg( memcmp(video_storage->planes[VPX_PLANE_Y], sample_payload, 10) == 0 || |
374 | memcmp(video_storage->planes[VPX_PLANE_U], sample_payload, 10) == 0 || | 430 | // memcmp(video_storage->planes[VPX_PLANE_U], sample_payload, 10) == 0 || |
375 | memcmp(video_storage->planes[VPX_PLANE_V], sample_payload, 10) == 0 , "Payload from Alice is invalid");*/ | 431 | // memcmp(video_storage->planes[VPX_PLANE_V], sample_payload, 10) == 0 , "Payload from Alice is invalid");*/ |
376 | } | 432 | // vpx_img_free(video_storage); |
433 | // } | ||
377 | 434 | ||
378 | 435 | ||
379 | if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */ | 436 | if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */ |
380 | step++; /* This terminates the loop */ | 437 | step++; /* This terminates the loop */ |
381 | toxav_kill_transmission(status_control.Alice.av); | 438 | toxav_kill_transmission(status_control.Alice.av, status_control.Alice.call_index); |
382 | toxav_kill_transmission(status_control.Bob.av); | 439 | toxav_kill_transmission(status_control.Bob.av, status_control.Bob.call_index); |
383 | 440 | ||
384 | /* Call over Alice hangs up */ | 441 | /* Call over Alice hangs up */ |
385 | toxav_hangup(status_control.Alice.av); | 442 | toxav_hangup(status_control.Alice.av, status_control.Alice.call_index); |
386 | } | 443 | } |
387 | } | 444 | } |
388 | TERMINATE_SCOPE() | 445 | TERMINATE_SCOPE() |
@@ -408,15 +465,14 @@ START_TEST(test_AV) | |||
408 | switch ( step ) { | 465 | switch ( step ) { |
409 | case 0: /* Alice */ | 466 | case 0: /* Alice */ |
410 | printf("Alice is calling...\n"); | 467 | printf("Alice is calling...\n"); |
411 | toxav_call(status_control.Alice.av, 0, TypeAudio, 10); | 468 | toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, TypeAudio, 10); |
412 | step++; | 469 | step++; |
413 | break; | 470 | break; |
414 | \ | ||
415 | 471 | ||
416 | case 1: /* Bob */ | 472 | case 1: /* Bob */ |
417 | if (status_control.Bob.status == Ringing) { | 473 | if (status_control.Bob.status == Ringing) { |
418 | printf("Bob rejects...\n"); | 474 | printf("Bob rejects...\n"); |
419 | toxav_reject(status_control.Bob.av, "Who likes D's anyway?"); | 475 | toxav_reject(status_control.Bob.av, status_control.Bob.call_index, "Who likes D's anyway?"); |
420 | step++; | 476 | step++; |
421 | } | 477 | } |
422 | 478 | ||
@@ -450,7 +506,7 @@ START_TEST(test_AV) | |||
450 | switch ( step ) { | 506 | switch ( step ) { |
451 | case 0: /* Alice */ | 507 | case 0: /* Alice */ |
452 | printf("Alice is calling...\n"); | 508 | printf("Alice is calling...\n"); |
453 | toxav_call(status_control.Alice.av, 0, TypeAudio, 10); | 509 | toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, TypeAudio, 10); |
454 | step++; | 510 | step++; |
455 | break; | 511 | break; |
456 | \ | 512 | \ |
@@ -458,14 +514,14 @@ START_TEST(test_AV) | |||
458 | case 1: /* Alice again */ | 514 | case 1: /* Alice again */ |
459 | if (status_control.Bob.status == Ringing) { | 515 | if (status_control.Bob.status == Ringing) { |
460 | printf("Alice cancels...\n"); | 516 | printf("Alice cancels...\n"); |
461 | toxav_cancel(status_control.Alice.av, 0, "Who likes D's anyway?"); | 517 | toxav_cancel(status_control.Alice.av, status_control.Alice.call_index, 0, "Who likes D's anyway?"); |
462 | step++; | 518 | step++; |
463 | } | 519 | } |
464 | 520 | ||
465 | break; | 521 | break; |
466 | 522 | ||
467 | case 2: /* Wait for Both to have status ended */ | 523 | case 2: /* Wait for Both to have status ended */ |
468 | if (status_control.Alice.status == Ended && status_control.Bob.status == Cancel) running = 0; | 524 | if (status_control.Bob.status == Cancel) running = 0; |
469 | 525 | ||
470 | break; | 526 | break; |
471 | } | 527 | } |
@@ -484,15 +540,19 @@ END_TEST | |||
484 | /*************************************************************************************************/ | 540 | /*************************************************************************************************/ |
485 | 541 | ||
486 | 542 | ||
543 | /*************************************************************************************************/ | ||
544 | |||
545 | /*************************************************************************************************/ | ||
546 | |||
487 | 547 | ||
488 | Suite *tox_suite(void) | 548 | Suite *tox_suite(void) |
489 | { | 549 | { |
490 | Suite *s = suite_create("ToxAV"); | 550 | Suite *s = suite_create("ToxAV"); |
491 | 551 | ||
492 | TCase *tc_av = tcase_create("A/V"); | 552 | TCase *tc_av_flows = tcase_create("AV_flows"); |
493 | tcase_add_test(tc_av, test_AV); | 553 | tcase_add_test(tc_av_flows, test_AV_flows); |
494 | tcase_set_timeout(tc_av, 100); /* Timeout on 100 too much? */ | 554 | tcase_set_timeout(tc_av_flows, 200); |
495 | suite_add_tcase(s, tc_av); | 555 | suite_add_tcase(s, tc_av_flows); |
496 | 556 | ||
497 | return s; | 557 | return s; |
498 | } | 558 | } |
@@ -509,4 +569,6 @@ int main(int argc, char *argv[]) | |||
509 | srunner_free(test_runner); | 569 | srunner_free(test_runner); |
510 | 570 | ||
511 | return number_failed; | 571 | return number_failed; |
572 | |||
573 | // return test_AV_flows(); | ||
512 | } | 574 | } |