summaryrefslogtreecommitdiff
path: root/auto_tests
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-07-22 11:20:55 -0400
committerirungentoo <irungentoo@gmail.com>2014-07-22 11:20:55 -0400
commit6ede3e8ad43ace57e4c4ae4fc95e6dcc2b296712 (patch)
treef8624676b5e432fa920c2932576bec9477a4042d /auto_tests
parentfdb5d890a3b211ecc95450887c99d2891d405728 (diff)
parent0cf9f27b70a612174ef16fad86f167017c7fc061 (diff)
Merge branch 'master' of https://github.com/mannol1/toxcore
Diffstat (limited to 'auto_tests')
-rw-r--r--auto_tests/toxav_basic_test.c231
-rw-r--r--auto_tests/toxav_many_test.c121
2 files changed, 160 insertions, 192 deletions
diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c
index bf130ecb..5fe17b40 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,7 +123,7 @@ 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
@@ -134,9 +131,17 @@ void callback_call_ended ( int32_t call_index, void *_arg )
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!\n");
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,48 @@ 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 369
413 /* Payload from Bob */ 370 if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */
414 /*recved = toxav_recv_audio(status_control.Alice.av, status_control.Alice.call_index, frame_size, storage); 371 step++; /* This terminates the loop */
372 toxav_kill_transmission(status_control.Alice.av, status_control.Alice.call_index);
373 toxav_kill_transmission(status_control.Bob.av, status_control.Bob.call_index);
415 374
416 if ( recved ) { 375 /* Call over Alice hangs up */
417 //ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid"); 376 toxav_hangup(status_control.Alice.av, status_control.Alice.call_index);
418 }*/ 377 }
378 }
379 TERMINATE_SCOPE()
419 380
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 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);
430 388
389 if ( payload_size < 0 ) {
390 ck_assert_msg ( 0, "Failed to encode payload" );
391 }
431 392
393 toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size);
432 394
433 /* Payload from Alice */ 395 payload_size = toxav_prepare_audio_frame(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, 1000,
434 /*recved = toxav_recv_audio(status_control.Bob.av, status_control.Bob.call_index, frame_size, storage); 396 sample_payload, frame_size);
435 397
436 if ( recved ) { 398 if ( payload_size < 0 ) {
437 ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid"); 399 ck_assert_msg ( 0, "Failed to encode payload" );
438 }*/ 400 }
439 401
440 /* Video payload */ 402 toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size);
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 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 }
450 411
451 if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */ 412 if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */
452 step++; /* This terminates the loop */ 413 step++; /* This terminates the loop */
@@ -460,7 +421,6 @@ START_TEST(test_AV_flows)
460 TERMINATE_SCOPE() 421 TERMINATE_SCOPE()
461 422
462 423
463
464 /************************************************************************************************* 424 /*************************************************************************************************
465 * Other flows 425 * Other flows
466 */ 426 */
@@ -524,7 +484,7 @@ START_TEST(test_AV_flows)
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) {
@@ -547,6 +507,39 @@ START_TEST(test_AV_flows)
547 printf("\n"); 507 printf("\n");
548 } 508 }
549 509
510 /*
511 * Timeout
512 */
513 {
514 int step = 0;
515 int running = 1;
516
517 while (running) {
518 tox_do(bootstrap_node);
519 tox_do(Alice);
520 tox_do(Bob);
521
522 switch ( step ) {
523 case 0:
524 printf("Alice is calling...\n");
525 toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, TypeAudio, 10);
526 step++;
527 break;
528
529 case 1:
530 if (status_control.Alice.status == TimedOut) running = 0;
531
532 break;
533 }
534
535 c_sleep(20);
536 }
537
538 printf("\n");
539 }
540
541
542
550 543
551 printf("Calls ended!\n"); 544 printf("Calls ended!\n");
552} 545}
diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c
index 3195d1ed..5276c2f9 100644
--- a/auto_tests/toxav_many_test.c
+++ b/auto_tests/toxav_many_test.c
@@ -44,6 +44,7 @@ typedef struct _Party {
44 44
45typedef struct _ACall { 45typedef struct _ACall {
46 pthread_t tid; 46 pthread_t tid;
47 int idx;
47 48
48 Party Caller; 49 Party Caller;
49 Party Callee; 50 Party Callee;
@@ -53,6 +54,8 @@ typedef struct _Status {
53 ACall calls[3]; /* Make 3 calls for this test */ 54 ACall calls[3]; /* Make 3 calls for this test */
54} Status; 55} Status;
55 56
57Status status_control;
58
56void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata) 59void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata)
57{ 60{
58 if (length == 7 && memcmp("gentoo", data, 7) == 0) { 61 if (length == 7 && memcmp("gentoo", data, 7) == 0) {
@@ -62,58 +65,49 @@ void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *dat
62 65
63 66
64/******************************************************************************/ 67/******************************************************************************/
65void callback_recv_invite ( int32_t call_index, void *_arg ) 68void callback_recv_invite ( void *av, int32_t call_index, void *_arg )
66{ 69{
67 /* 70 /*
68 Status *cast = _arg; 71 Status *cast = _arg;
69 72
70 cast->calls[call_index].Callee.status = Ringing;*/ 73 cast->calls[call_index].Callee.status = Ringing;*/
71} 74}
72void callback_recv_ringing ( int32_t call_index, void *_arg ) 75void callback_recv_ringing ( void *av, int32_t call_index, void *_arg )
73{ 76{
74 Status *cast = _arg; 77 Status *cast = _arg;
75
76 cast->calls[call_index].Caller.status = Ringing; 78 cast->calls[call_index].Caller.status = Ringing;
77} 79}
78void callback_recv_starting ( int32_t call_index, void *_arg ) 80void callback_recv_starting ( void *av, int32_t call_index, void *_arg )
79{ 81{
80 Status *cast = _arg; 82 Status *cast = _arg;
81
82 cast->calls[call_index].Caller.status = InCall; 83 cast->calls[call_index].Caller.status = InCall;
83} 84}
84void callback_recv_ending ( int32_t call_index, void *_arg ) 85void callback_recv_ending ( void *av, int32_t call_index, void *_arg )
85{ 86{
86 Status *cast = _arg; 87 Status *cast = _arg;
87
88 cast->calls[call_index].Caller.status = Ended; 88 cast->calls[call_index].Caller.status = Ended;
89} 89}
90 90
91void callback_recv_error ( int32_t call_index, void *_arg ) 91void callback_call_started ( void *av, int32_t call_index, void *_arg )
92{
93 ck_assert_msg(0, "AV internal error");
94}
95
96void callback_call_started ( int32_t call_index, void *_arg )
97{ 92{
98 /* 93 /*
99 Status *cast = _arg; 94 Status *cast = _arg;
100 95
101 cast->calls[call_index].Callee.status = InCall;*/ 96 cast->calls[call_index].Callee.status = InCall;*/
102} 97}
103void callback_call_canceled ( int32_t call_index, void *_arg ) 98void callback_call_canceled ( void *av, int32_t call_index, void *_arg )
104{ 99{
105 /* 100 /*
106 Status *cast = _arg; 101 Status *cast = _arg;
107 102
108 cast->calls[call_index].Callee.status = Cancel;*/ 103 cast->calls[call_index].Callee.status = Cancel;*/
109} 104}
110void callback_call_rejected ( int32_t call_index, void *_arg ) 105void callback_call_rejected ( void *av, int32_t call_index, void *_arg )
111{ 106{
112 Status *cast = _arg; 107 Status *cast = _arg;
113
114 cast->calls[call_index].Caller.status = Rejected; 108 cast->calls[call_index].Caller.status = Rejected;
115} 109}
116void callback_call_ended ( int32_t call_index, void *_arg ) 110void callback_call_ended ( void *av, int32_t call_index, void *_arg )
117{ 111{
118 /* 112 /*
119 Status *cast = _arg; 113 Status *cast = _arg;
@@ -121,7 +115,7 @@ void callback_call_ended ( int32_t call_index, void *_arg )
121 cast->calls[call_index].Callee.status = Ended;*/ 115 cast->calls[call_index].Callee.status = Ended;*/
122} 116}
123 117
124void callback_requ_timeout ( int32_t call_index, void *_arg ) 118void callback_requ_timeout ( void *av, int32_t call_index, void *_arg )
125{ 119{
126 ck_assert_msg(0, "No answer!"); 120 ck_assert_msg(0, "No answer!");
127} 121}
@@ -133,8 +127,27 @@ static void callback_audio(ToxAv *av, int32_t call_index, int16_t *data, int len
133static void callback_video(ToxAv *av, int32_t call_index, vpx_image_t *img) 127static void callback_video(ToxAv *av, int32_t call_index, vpx_image_t *img)
134{ 128{
135} 129}
130void register_callbacks(ToxAv *av, void *data)
131{
132 toxav_register_callstate_callback(av, callback_call_started, av_OnStart, data);
133 toxav_register_callstate_callback(av, callback_call_canceled, av_OnCancel, data);
134 toxav_register_callstate_callback(av, callback_call_rejected, av_OnReject, data);
135 toxav_register_callstate_callback(av, callback_call_ended, av_OnEnd, data);
136 toxav_register_callstate_callback(av, callback_recv_invite, av_OnInvite, data);
137
138 toxav_register_callstate_callback(av, callback_recv_ringing, av_OnRinging, data);
139 toxav_register_callstate_callback(av, callback_recv_starting, av_OnStarting, data);
140 toxav_register_callstate_callback(av, callback_recv_ending, av_OnEnding, data);
141
142 toxav_register_callstate_callback(av, callback_requ_timeout, av_OnRequestTimeout, data);
143
144
145 toxav_register_audio_recv_callback(av, callback_audio);
146 toxav_register_video_recv_callback(av, callback_video);
147}
136/*************************************************************************************************/ 148/*************************************************************************************************/
137 149
150int call_running[3];
138 151
139void *in_thread_call (void *arg) 152void *in_thread_call (void *arg)
140{ 153{
@@ -142,23 +155,22 @@ void *in_thread_call (void *arg)
142 155
143 ACall *this_call = arg; 156 ACall *this_call = arg;
144 uint64_t start = 0; 157 uint64_t start = 0;
145 int step = 0, running = 1; 158 int step = 0;
146 int call_idx; 159 int call_idx;
147 160
161 call_running[this_call->idx] = 1;
162
148 const int frame_size = (av_DefaultSettings.audio_sample_rate * av_DefaultSettings.audio_frame_duration / 1000); 163 const int frame_size = (av_DefaultSettings.audio_sample_rate * av_DefaultSettings.audio_frame_duration / 1000);
149 int16_t sample_payload[frame_size]; 164 int16_t sample_payload[frame_size];
150 randombytes((uint8_t *)sample_payload, sizeof(int16_t) * frame_size); 165 randombytes((uint8_t *)sample_payload, sizeof(int16_t) * frame_size);
151 166
152 uint8_t prepared_payload[RTP_PAYLOAD_SIZE]; 167 uint8_t prepared_payload[RTP_PAYLOAD_SIZE];
153 168
154 toxav_register_audio_recv_callback(this_call->Caller.av, callback_audio); 169 register_callbacks(this_call->Caller.av, &status_control);
155 toxav_register_video_recv_callback(this_call->Caller.av, callback_video); 170 register_callbacks(this_call->Callee.av, arg);
156 toxav_register_audio_recv_callback(this_call->Callee.av, callback_audio);
157 toxav_register_video_recv_callback(this_call->Callee.av, callback_video);
158
159 171
160 /* NOTE: CALLEE WILL ALWAHYS NEED CALL_IDX == 0 */ 172 /* NOTE: CALLEE WILL ALWAHYS NEED CALL_IDX == 0 */
161 while (running) { 173 while (call_running[this_call->idx]) {
162 174
163 switch ( step ) { 175 switch ( step ) {
164 case 0: /* CALLER */ 176 case 0: /* CALLER */
@@ -205,20 +217,6 @@ void *in_thread_call (void *arg)
205 int16_t storage[RTP_PAYLOAD_SIZE]; 217 int16_t storage[RTP_PAYLOAD_SIZE];
206 int recved; 218 int recved;
207 219
208 /* Payload from CALLER */
209 /*recved = toxav_recv_audio(this_call->Callee.av, 0, frame_size, storage);
210
211 if ( recved ) {
212 //ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from CALLER is invalid");
213 }*/
214
215 /* Payload from CALLEE */
216 /*recved = toxav_recv_audio(this_call->Caller.av, call_idx, frame_size, storage);
217
218 if ( recved ) {
219 //ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from CALLEE is invalid");
220 }*/
221
222 c_sleep(20); 220 c_sleep(20);
223 } 221 }
224 222
@@ -240,7 +238,7 @@ void *in_thread_call (void *arg)
240 if (this_call->Caller.status == Ended) { 238 if (this_call->Caller.status == Ended) {
241 c_sleep(1000); /* race condition */ 239 c_sleep(1000); /* race condition */
242 this_call->Callee.status = Ended; 240 this_call->Callee.status = Ended;
243 running = 0; 241 call_running[this_call->idx] = 0;
244 } 242 }
245 243
246 break; 244 break;
@@ -322,52 +320,29 @@ START_TEST(test_AV_three_calls)
322 320
323 ToxAv *uniqcallerav = toxav_new(caller, 3); 321 ToxAv *uniqcallerav = toxav_new(caller, 3);
324 322
325 Status status_control = { 323 for (i = 0; i < 3; i ++) {
326 0, 324 status_control.calls[i].idx = i;
327 {none, uniqcallerav, 0},
328 {none, toxav_new(callees[0], 1), 0},
329
330 0,
331 {none, uniqcallerav},
332 {none, toxav_new(callees[1], 1), 1},
333
334 0,
335 {none, uniqcallerav},
336 {none, toxav_new(callees[2], 1), 2}
337 };
338
339
340 toxav_register_callstate_callback(callback_call_started, av_OnStart, &status_control);
341 toxav_register_callstate_callback(callback_call_canceled, av_OnCancel, &status_control);
342 toxav_register_callstate_callback(callback_call_rejected, av_OnReject, &status_control);
343 toxav_register_callstate_callback(callback_call_ended, av_OnEnd, &status_control);
344 toxav_register_callstate_callback(callback_recv_invite, av_OnInvite, &status_control);
345
346 toxav_register_callstate_callback(callback_recv_ringing, av_OnRinging, &status_control);
347 toxav_register_callstate_callback(callback_recv_starting, av_OnStarting, &status_control);
348 toxav_register_callstate_callback(callback_recv_ending, av_OnEnding, &status_control);
349 325
350 toxav_register_callstate_callback(callback_recv_error, av_OnError, &status_control); 326 status_control.calls[i].Caller.av = uniqcallerav;
351 toxav_register_callstate_callback(callback_requ_timeout, av_OnRequestTimeout, &status_control); 327 status_control.calls[i].Caller.id = 0;
328 status_control.calls[i].Caller.status = none;
352 329
330 status_control.calls[i].Callee.av = toxav_new(callees[i], 1);
331 status_control.calls[i].Callee.id = i;
332 status_control.calls[i].Callee.status = none;
333 }
353 334
354 pthread_mutex_init(&muhmutex, NULL); 335 pthread_mutex_init(&muhmutex, NULL);
355 336
356
357 for ( i = 0; i < 3; i++ ) 337 for ( i = 0; i < 3; i++ )
358 pthread_create(&status_control.calls[i].tid, NULL, in_thread_call, &status_control.calls[i]); 338 pthread_create(&status_control.calls[i].tid, NULL, in_thread_call, &status_control.calls[i]);
359 339
360
361 /* Now start 3 calls and they'll run for 10 s */ 340 /* Now start 3 calls and they'll run for 10 s */
362 341
363 for ( i = 0; i < 3; i++ ) 342 for ( i = 0; i < 3; i++ )
364 pthread_detach(status_control.calls[i].tid); 343 pthread_detach(status_control.calls[i].tid);
365 344
366 while ( 345 while (call_running[0] || call_running[1] || call_running[2]) {
367 status_control.calls[0].Callee.status != Ended && status_control.calls[0].Caller.status != Ended &&
368 status_control.calls[1].Callee.status != Ended && status_control.calls[1].Caller.status != Ended &&
369 status_control.calls[2].Callee.status != Ended && status_control.calls[2].Caller.status != Ended
370 ) {
371 pthread_mutex_lock(&muhmutex); 346 pthread_mutex_lock(&muhmutex);
372 347
373 tox_do(bootstrap_node); 348 tox_do(bootstrap_node);