summaryrefslogtreecommitdiff
path: root/auto_tests/toxav_basic_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'auto_tests/toxav_basic_test.c')
-rw-r--r--auto_tests/toxav_basic_test.c269
1 files changed, 130 insertions, 139 deletions
diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c
index bf130ecb..1361edd3 100644
--- a/auto_tests/toxav_basic_test.c
+++ b/auto_tests/toxav_basic_test.c
@@ -31,7 +31,8 @@ typedef enum _CallStatus {
31 Ringing, 31 Ringing,
32 Ended, 32 Ended,
33 Rejected, 33 Rejected,
34 Cancel 34 Cancel,
35 TimedOut
35 36
36} CallStatus; 37} CallStatus;
37 38
@@ -59,7 +60,7 @@ void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *dat
59 60
60 61
61/******************************************************************************/ 62/******************************************************************************/
62void callback_recv_invite ( int32_t call_index, void *_arg ) 63void callback_recv_invite ( void *av, int32_t call_index, void *_arg )
63{ 64{
64 Status *cast = _arg; 65 Status *cast = _arg;
65 66
@@ -67,23 +68,23 @@ void callback_recv_invite ( int32_t call_index, void *_arg )
67 cast->Bob.status = Ringing; 68 cast->Bob.status = Ringing;
68 cast->Bob.call_index = call_index; 69 cast->Bob.call_index = call_index;
69} 70}
70void callback_recv_ringing ( int32_t call_index, void *_arg ) 71void callback_recv_ringing ( void *av, int32_t call_index, void *_arg )
71{ 72{
72 Status *cast = _arg; 73 Status *cast = _arg;
73 74
74 /* Alice always sends invite */ 75 /* Alice always sends invite */
75 cast->Alice.status = Ringing; 76 cast->Alice.status = Ringing;
76} 77}
77void callback_recv_starting ( int32_t call_index, void *_arg ) 78void callback_recv_starting ( void *av, int32_t call_index, void *_arg )
78{ 79{
79 Status *cast = _arg; 80 Status *cast = _arg;
80 81
81 /* Alice always sends invite */ 82 /* Alice always sends invite */
82 printf("Call started on Alice side...\n"); 83 printf("Call started on Alice side...\n");
83 cast->Alice.status = InCall; 84 cast->Alice.status = InCall;
84 toxav_prepare_transmission(cast->Alice.av, call_index, &muhcaps, 1); 85 toxav_prepare_transmission(av, call_index, &muhcaps, 1);
85} 86}
86void callback_recv_ending ( int32_t call_index, void *_arg ) 87void callback_recv_ending ( void *av, int32_t call_index, void *_arg )
87{ 88{
88 Status *cast = _arg; 89 Status *cast = _arg;
89 90
@@ -96,28 +97,24 @@ void callback_recv_ending ( int32_t call_index, void *_arg )
96 } 97 }
97} 98}
98 99
99void callback_recv_error ( int32_t call_index, void *_arg )
100{
101 ck_assert_msg(0, "AV internal error");
102}
103 100
104void callback_call_started ( int32_t call_index, void *_arg ) 101void callback_call_started ( void *av, int32_t call_index, void *_arg )
105{ 102{
106 Status *cast = _arg; 103 Status *cast = _arg;
107 104
108 /* Alice always sends invite */ 105 /* Alice always sends invite */
109 printf("Call started on Bob side...\n"); 106 printf("Call started on Bob side...\n");
110 cast->Bob.status = InCall; 107 cast->Bob.status = InCall;
111 toxav_prepare_transmission(cast->Bob.av, call_index, &muhcaps, 1); 108 toxav_prepare_transmission(av, call_index, &muhcaps, 1);
112} 109}
113void callback_call_canceled ( int32_t call_index, void *_arg ) 110void callback_call_canceled ( void *av, int32_t call_index, void *_arg )
114{ 111{
115 Status *cast = _arg; 112 Status *cast = _arg;
116 113
117 printf ( "Call Canceled for Bob!\n" ); 114 printf ( "Call Canceled for Bob!\n" );
118 cast->Bob.status = Cancel; 115 cast->Bob.status = Cancel;
119} 116}
120void callback_call_rejected ( int32_t call_index, void *_arg ) 117void callback_call_rejected ( void *av, int32_t call_index, void *_arg )
121{ 118{
122 Status *cast = _arg; 119 Status *cast = _arg;
123 120
@@ -126,17 +123,25 @@ void callback_call_rejected ( int32_t call_index, void *_arg )
126 /* If Bob rejects, call is ended for alice and she sends ending */ 123 /* If Bob rejects, call is ended for alice and she sends ending */
127 cast->Alice.status = Rejected; 124 cast->Alice.status = Rejected;
128} 125}
129void callback_call_ended ( int32_t call_index, void *_arg ) 126void callback_call_ended ( void *av, int32_t call_index, void *_arg )
130{ 127{
131 Status *cast = _arg; 128 Status *cast = _arg;
132 129
133 printf ( "Call ended for Bob!\n" ); 130 printf ( "Call ended for Bob!\n" );
134 cast->Bob.status = Ended; 131 cast->Bob.status = Ended;
135} 132}
136 133
137void callback_requ_timeout ( int32_t call_index, void *_arg ) 134void callback_call_type_change ( void *av, int32_t call_index, void *_arg )
135{
136 printf("Call type changed; new type: %s!\n", toxav_get_peer_transmission_type
137 (av, call_index, 0) == TypeAudio ? "audio" : "video");
138}
139
140void callback_requ_timeout ( void *av, int32_t call_index, void *_arg )
138{ 141{
139 ck_assert_msg(0, "No answer!"); 142 Status *cast = _arg;
143 printf("Call timed-out!");
144 cast->Alice.status = TimedOut;
140} 145}
141 146
142static void callback_audio(ToxAv *av, int32_t call_index, int16_t *data, int length) 147static void callback_audio(ToxAv *av, int32_t call_index, int16_t *data, int length)
@@ -147,10 +152,31 @@ static void callback_video(ToxAv *av, int32_t call_index, vpx_image_t *img)
147{ 152{
148} 153}
149 154
155void register_callbacks(ToxAv* av, void* data)
156{
157 toxav_register_callstate_callback(av, callback_call_started, av_OnStart, data);
158 toxav_register_callstate_callback(av, callback_call_canceled, av_OnCancel, data);
159 toxav_register_callstate_callback(av, callback_call_rejected, av_OnReject, data);
160 toxav_register_callstate_callback(av, callback_call_ended, av_OnEnd, data);
161 toxav_register_callstate_callback(av, callback_recv_invite, av_OnInvite, data);
162
163 toxav_register_callstate_callback(av, callback_recv_ringing, av_OnRinging, data);
164 toxav_register_callstate_callback(av, callback_recv_starting, av_OnStarting, data);
165 toxav_register_callstate_callback(av, callback_recv_ending, av_OnEnding, data);
166
167 toxav_register_callstate_callback(av, callback_requ_timeout, av_OnRequestTimeout, data);
168 toxav_register_callstate_callback(av, callback_call_type_change, av_OnMediaChange, data);
169
170
171 toxav_register_audio_recv_callback(av, callback_audio);
172 toxav_register_video_recv_callback(av, callback_video);
173}
174
175
150/*************************************************************************************************/ 176/*************************************************************************************************/
151 177
152/* Alice calls bob and the call starts. 178/* Alice calls bob and the call starts.
153 * What happens in the call is defined after. To quit the loop use: step++; 179 * What happens during the call is defined after. To quit the loop use: step++;
154 */ 180 */
155#define CALL_AND_START_LOOP(AliceCallType, BobCallType) \ 181#define CALL_AND_START_LOOP(AliceCallType, BobCallType) \
156{ int step = 0, running = 1; while (running) {\ 182{ int step = 0, running = 1; while (running) {\
@@ -218,23 +244,8 @@ START_TEST(test_AV_flows)
218 ck_assert_msg(status_control.Alice.av || status_control.Bob.av, "Failed to create 2 toxav instances"); 244 ck_assert_msg(status_control.Alice.av || status_control.Bob.av, "Failed to create 2 toxav instances");
219 245
220 246
221 toxav_register_callstate_callback(callback_call_started, av_OnStart, &status_control); 247 register_callbacks(status_control.Alice.av, &status_control);
222 toxav_register_callstate_callback(callback_call_canceled, av_OnCancel, &status_control); 248 register_callbacks(status_control.Bob.av, &status_control);
223 toxav_register_callstate_callback(callback_call_rejected, av_OnReject, &status_control);
224 toxav_register_callstate_callback(callback_call_ended, av_OnEnd, &status_control);
225 toxav_register_callstate_callback(callback_recv_invite, av_OnInvite, &status_control);
226
227 toxav_register_callstate_callback(callback_recv_ringing, av_OnRinging, &status_control);
228 toxav_register_callstate_callback(callback_recv_starting, av_OnStarting, &status_control);
229 toxav_register_callstate_callback(callback_recv_ending, av_OnEnding, &status_control);
230
231 toxav_register_callstate_callback(callback_recv_error, av_OnError, &status_control);
232 toxav_register_callstate_callback(callback_requ_timeout, av_OnRequestTimeout, &status_control);
233
234 toxav_register_audio_recv_callback(status_control.Alice.av, callback_audio);
235 toxav_register_video_recv_callback(status_control.Alice.av, callback_video);
236 toxav_register_audio_recv_callback(status_control.Bob.av, callback_audio);
237 toxav_register_video_recv_callback(status_control.Bob.av, callback_video);
238 249
239 const int frame_size = (av_DefaultSettings.audio_sample_rate * av_DefaultSettings.audio_frame_duration / 1000); 250 const int frame_size = (av_DefaultSettings.audio_sample_rate * av_DefaultSettings.audio_frame_duration / 1000);
240 int16_t sample_payload[frame_size]; 251 int16_t sample_payload[frame_size];
@@ -279,24 +290,6 @@ START_TEST(test_AV_flows)
279 290
280 toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size); 291 toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size);
281 292
282 /* Both receive */
283 /*int16_t storage[frame_size];
284 int recved;
285
286 /* Payload from Bob */
287
288 /*recved = toxav_recv_audio(status_control.Alice.av, status_control.Alice.call_index, frame_size, storage);
289
290 if ( recved ) {
291 //ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid");
292 }
293
294 recved = toxav_recv_audio(status_control.Bob.av, status_control.Bob.call_index, frame_size, storage);
295
296 if ( recved ) {
297 //ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid");
298 }*/
299
300 if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */ 293 if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */
301 step++; /* This terminates the loop */ 294 step++; /* This terminates the loop */
302 toxav_kill_transmission(status_control.Alice.av, status_control.Alice.call_index); 295 toxav_kill_transmission(status_control.Alice.av, status_control.Alice.call_index);
@@ -334,38 +327,6 @@ START_TEST(test_AV_flows)
334 327
335// toxav_send_video(status_control.Bob.av, status_control.Bob.call_index, sample_image); 328// toxav_send_video(status_control.Bob.av, status_control.Bob.call_index, sample_image);
336 329
337 /* Both receive */
338 int16_t storage[frame_size];
339 vpx_image_t *video_storage;
340 int recved;
341
342 /* Payload from Bob */
343 /*recved = toxav_recv_audio(status_control.Alice.av, status_control.Alice.call_index, frame_size, storage);
344
345 if ( recved ) {
346 //ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid");
347 }*/
348
349 /* Video payload */
350// toxav_recv_video(status_control.Alice.av, status_control.Alice.call_index, &video_storage);
351//
352// if ( video_storage ) {
353// /*ck_assert_msg( memcmp(video_storage->planes[VPX_PLANE_Y], sample_payload, 10) == 0 ||
354// memcmp(video_storage->planes[VPX_PLANE_U], sample_payload, 10) == 0 ||
355// memcmp(video_storage->planes[VPX_PLANE_V], sample_payload, 10) == 0 , "Payload from Bob is invalid");*/
356// vpx_img_free(video_storage);
357// }
358
359
360
361
362 /* Payload from Alice */
363 /*recved = toxav_recv_audio(status_control.Bob.av, status_control.Bob.call_index, frame_size, storage);
364
365 if ( recved ) {
366 //ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid");
367 }*/
368
369 if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */ 330 if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */
370 step++; /* This terminates the loop */ 331 step++; /* This terminates the loop */
371 toxav_kill_transmission(status_control.Alice.av, status_control.Alice.call_index); 332 toxav_kill_transmission(status_control.Alice.av, status_control.Alice.call_index);
@@ -405,48 +366,6 @@ START_TEST(test_AV_flows)
405// toxav_send_video(status_control.Alice.av, status_control.Alice.call_index, sample_image); 366// toxav_send_video(status_control.Alice.av, status_control.Alice.call_index, sample_image);
406// toxav_send_video(status_control.Bob.av, status_control.Bob.call_index, sample_image); 367// toxav_send_video(status_control.Bob.av, status_control.Bob.call_index, sample_image);
407 368
408 /* Both receive */
409 int16_t storage[frame_size];
410 vpx_image_t *video_storage;
411 int recved;
412
413 /* Payload from Bob */
414 /*recved = toxav_recv_audio(status_control.Alice.av, status_control.Alice.call_index, frame_size, storage);
415
416 if ( recved ) {
417 //ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid");
418 }*/
419
420 /* Video payload */
421// toxav_recv_video(status_control.Alice.av, status_control.Alice.call_index, &video_storage);
422//
423// if ( video_storage ) {
424// /*ck_assert_msg( memcmp(video_storage->planes[VPX_PLANE_Y], sample_payload, 10) == 0 ||
425// memcmp(video_storage->planes[VPX_PLANE_U], sample_payload, 10) == 0 ||
426// memcmp(video_storage->planes[VPX_PLANE_V], sample_payload, 10) == 0 , "Payload from Bob is invalid");*/
427// vpx_img_free(video_storage);
428// }
429
430
431
432
433 /* Payload from Alice */
434 /*recved = toxav_recv_audio(status_control.Bob.av, status_control.Bob.call_index, frame_size, storage);
435
436 if ( recved ) {
437 ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid");
438 }*/
439
440 /* Video payload */
441// toxav_recv_video(status_control.Bob.av, status_control.Bob.call_index, &video_storage);
442//
443// if ( video_storage ) {
444// /*ck_assert_msg( memcmp(video_storage->planes[VPX_PLANE_Y], sample_payload, 10) == 0 ||
445// memcmp(video_storage->planes[VPX_PLANE_U], sample_payload, 10) == 0 ||
446// memcmp(video_storage->planes[VPX_PLANE_V], sample_payload, 10) == 0 , "Payload from Alice is invalid");*/
447// vpx_img_free(video_storage);
448// }
449
450 369
451 if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */ 370 if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */
452 step++; /* This terminates the loop */ 371 step++; /* This terminates the loop */
@@ -459,8 +378,49 @@ START_TEST(test_AV_flows)
459 } 378 }
460 TERMINATE_SCOPE() 379 TERMINATE_SCOPE()
461 380
381
382 uint64_t times_they_are_a_changin = time(NULL);
383 /* Media change */
384 CALL_AND_START_LOOP(TypeAudio, TypeAudio) {
385 /* Both send */
386 payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload,
387 1000, sample_payload, frame_size);
388
389 if ( payload_size < 0 ) {
390 ck_assert_msg ( 0, "Failed to encode payload" );
391 }
392
393 toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size);
394
395 payload_size = toxav_prepare_audio_frame(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, 1000,
396 sample_payload, frame_size);
397
398 if ( payload_size < 0 ) {
399 ck_assert_msg ( 0, "Failed to encode payload" );
400 }
401
402 toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size);
403
404 /* Wait 2 seconds and change transmission type */
405 if (time(NULL) - times_they_are_a_changin > 2) {
406 times_they_are_a_changin = time(NULL);
407 toxav_change_type(status_control.Alice.av, status_control.Alice.call_index,
408 toxav_get_peer_transmission_type(status_control.Bob.av, status_control.Bob.call_index, 0)
409 == TypeAudio ? TypeVideo : TypeAudio);
410 }
411
412 if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */
413 step++; /* This terminates the loop */
414 toxav_kill_transmission(status_control.Alice.av, status_control.Alice.call_index);
415 toxav_kill_transmission(status_control.Bob.av, status_control.Bob.call_index);
416
417 /* Call over Alice hangs up */
418 toxav_hangup(status_control.Alice.av, status_control.Alice.call_index);
419 }
420 }
421 TERMINATE_SCOPE()
462 422
463 423
464 /************************************************************************************************* 424 /*************************************************************************************************
465 * Other flows 425 * Other flows
466 */ 426 */
@@ -505,47 +465,78 @@ START_TEST(test_AV_flows)
505 printf("\n"); 465 printf("\n");
506 } 466 }
507 467
508 468
509 /* 469 /*
510 * Call and cancel 470 * Call and cancel
511 */ 471 */
512 { 472 {
513 int step = 0; 473 int step = 0;
514 int running = 1; 474 int running = 1;
515 475
516 while (running) { 476 while (running) {
517 tox_do(bootstrap_node); 477 tox_do(bootstrap_node);
518 tox_do(Alice); 478 tox_do(Alice);
519 tox_do(Bob); 479 tox_do(Bob);
520 480
521 switch ( step ) { 481 switch ( step ) {
522 case 0: /* Alice */ 482 case 0: /* Alice */
523 printf("Alice is calling...\n"); 483 printf("Alice is calling...\n");
524 toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, TypeAudio, 10); 484 toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, TypeAudio, 10);
525 step++; 485 step++;
526 break; 486 break;
527 \ 487
528 488
529 case 1: /* Alice again */ 489 case 1: /* Alice again */
530 if (status_control.Bob.status == Ringing) { 490 if (status_control.Bob.status == Ringing) {
531 printf("Alice cancels...\n"); 491 printf("Alice cancels...\n");
532 toxav_cancel(status_control.Alice.av, status_control.Alice.call_index, 0, "Who likes D's anyway?"); 492 toxav_cancel(status_control.Alice.av, status_control.Alice.call_index, 0, "Who likes D's anyway?");
533 step++; 493 step++;
534 } 494 }
535 495
536 break; 496 break;
537 497
538 case 2: /* Wait for Both to have status ended */ 498 case 2: /* Wait for Both to have status ended */
539 if (status_control.Bob.status == Cancel) running = 0; 499 if (status_control.Bob.status == Cancel) running = 0;
540 500
541 break; 501 break;
542 } 502 }
543 503
544 c_sleep(20); 504 c_sleep(20);
545 } 505 }
546 506
507 printf("\n");
508 }
509
510 /*
511 * Timeout
512 */
513 {
514 int step = 0;
515 int running = 1;
516 while (running) {
517 tox_do(bootstrap_node);
518 tox_do(Alice);
519 tox_do(Bob);
520
521 switch ( step ) {
522 case 0:
523 printf("Alice is calling...\n");
524 toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, TypeAudio, 10);
525 step++;
526 break;
527
528 case 1:
529 if (status_control.Alice.status == TimedOut) running = 0;
530 break;
531 }
532
533 c_sleep(20);
534 }
535
547 printf("\n"); 536 printf("\n");
548 } 537 }
538
539
549 540
550 541
551 printf("Calls ended!\n"); 542 printf("Calls ended!\n");