summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--auto_tests/Makefile.inc10
-rw-r--r--auto_tests/toxav_basic_test.c13
-rw-r--r--auto_tests/toxav_many_test.c168
-rw-r--r--toxav/msi.c2
-rw-r--r--toxav/rtp.c9
-rw-r--r--toxav/toxav.c11
6 files changed, 182 insertions, 31 deletions
diff --git a/auto_tests/Makefile.inc b/auto_tests/Makefile.inc
index 741ca7fa..d78a6a5a 100644
--- a/auto_tests/Makefile.inc
+++ b/auto_tests/Makefile.inc
@@ -21,8 +21,8 @@ AUTOTEST_LDADD = \
21 21
22 22
23if BUILD_AV 23if BUILD_AV
24TESTS += toxav_basic_test #toxav_many_test 24TESTS += toxav_basic_test toxav_many_test
25check_PROGRAMS += toxav_basic_test #toxav_many_test 25check_PROGRAMS += toxav_basic_test toxav_many_test
26AUTOTEST_LDADD += libtoxav.la 26AUTOTEST_LDADD += libtoxav.la
27endif 27endif
28 28
@@ -90,11 +90,11 @@ toxav_basic_test_CFLAGS = $(AUTOTEST_CFLAGS)
90toxav_basic_test_LDADD = $(AUTOTEST_LDADD) $(AV_LIBS) 90toxav_basic_test_LDADD = $(AUTOTEST_LDADD) $(AV_LIBS)
91 91
92 92
93#toxav_many_test_SOURCES = ../auto_tests/toxav_many_test.c 93toxav_many_test_SOURCES = ../auto_tests/toxav_many_test.c
94 94
95#toxav_many_test_CFLAGS = $(AUTOTEST_CFLAGS) 95toxav_many_test_CFLAGS = $(AUTOTEST_CFLAGS)
96 96
97#toxav_many_test_LDADD = $(AUTOTEST_LDADD) 97toxav_many_test_LDADD = $(AUTOTEST_LDADD)
98endif 98endif
99 99
100endif 100endif
diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c
index 7598c0db..423cd03d 100644
--- a/auto_tests/toxav_basic_test.c
+++ b/auto_tests/toxav_basic_test.c
@@ -49,11 +49,19 @@ typedef struct {
49 */ 49 */
50void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data) 50void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data)
51{ 51{
52 (void) av;
53 (void) friend_number;
54 (void) audio_enabled;
55 (void) video_enabled;
56
52 printf("Handling CALL callback\n"); 57 printf("Handling CALL callback\n");
53 ((CallControl*)user_data)->incoming = true; 58 ((CallControl*)user_data)->incoming = true;
54} 59}
55void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data) 60void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data)
56{ 61{
62 (void) av;
63 (void) friend_number;
64
57 printf("Handling CALL STATE callback: %d\n", state); 65 printf("Handling CALL STATE callback: %d\n", state);
58 ((CallControl*)user_data)->state = state; 66 ((CallControl*)user_data)->state = state;
59} 67}
@@ -92,6 +100,8 @@ void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number,
92} 100}
93void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) 101void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata)
94{ 102{
103 (void) userdata;
104
95 if (length == 7 && memcmp("gentoo", data, 7) == 0) { 105 if (length == 7 && memcmp("gentoo", data, 7) == 0) {
96 assert(tox_friend_add_norequest(m, public_key, NULL) != (uint32_t) ~0); 106 assert(tox_friend_add_norequest(m, public_key, NULL) != (uint32_t) ~0);
97 } 107 }
@@ -433,6 +443,9 @@ Suite *tox_suite(void)
433} 443}
434int main(int argc, char *argv[]) 444int main(int argc, char *argv[])
435{ 445{
446 (void) argc;
447 (void) argv;
448
436 Suite *tox = tox_suite(); 449 Suite *tox = tox_suite();
437 SRunner *test_runner = srunner_create(tox); 450 SRunner *test_runner = srunner_create(tox);
438 451
diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c
index ef59b2b2..84f94e96 100644
--- a/auto_tests/toxav_many_test.c
+++ b/auto_tests/toxav_many_test.c
@@ -31,22 +31,34 @@
31typedef struct { 31typedef struct {
32 bool incoming; 32 bool incoming;
33 uint32_t state; 33 uint32_t state;
34
35} CallControl; 34} CallControl;
36 35
36typedef struct {
37 ToxAV* AliceAV;
38 ToxAV* BobAV;
39 CallControl* AliceCC;
40 CallControl* BobCC;
41 uint32_t friend_number;
42} thread_data;
37 43
38/** 44/**
39 * Callbacks 45 * Callbacks
40 */ 46 */
41void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data) 47void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data)
42{ 48{
49 (void) av;
50 (void) audio_enabled;
51 (void) video_enabled;
52
43 printf("Handling CALL callback\n"); 53 printf("Handling CALL callback\n");
44 ((CallControl*)user_data)->incoming = true; 54 ((CallControl*)user_data)[friend_number].incoming = true;
45} 55}
46void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data) 56void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data)
47{ 57{
58 (void) av;
59
48 printf("Handling CALL STATE callback: %d\n", state); 60 printf("Handling CALL STATE callback: %d\n", state);
49 ((CallControl*)user_data)->state = state; 61 ((CallControl*)user_data)[friend_number].state = state;
50} 62}
51void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, 63void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number,
52 uint16_t width, uint16_t height, 64 uint16_t width, uint16_t height,
@@ -83,6 +95,7 @@ void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number,
83} 95}
84void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) 96void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata)
85{ 97{
98 (void) userdata;
86 if (length == 7 && memcmp("gentoo", data, 7) == 0) { 99 if (length == 7 && memcmp("gentoo", data, 7) == 0) {
87 assert(tox_friend_add_norequest(m, public_key, NULL) != (uint32_t) ~0); 100 assert(tox_friend_add_norequest(m, public_key, NULL) != (uint32_t) ~0);
88 } 101 }
@@ -106,11 +119,82 @@ ToxAV* setup_av_instance(Tox* tox, CallControl *CC)
106 119
107 return av; 120 return av;
108} 121}
109void* call_thread(ToxAV* Alice, ToxAV* Bob) 122void* call_thread(void* pd)
110{ 123{
124 ToxAV* AliceAV = ((thread_data*) pd)->AliceAV;
125 ToxAV* BobAV = ((thread_data*) pd)->BobAV;
126 CallControl* AliceCC = ((thread_data*) pd)->AliceCC;
127 CallControl* BobCC = ((thread_data*) pd)->BobCC;
128 uint32_t friend_number = ((thread_data*) pd)->friend_number;
129
130
131 memset(AliceCC, 0, sizeof(CallControl));
132 memset(BobCC, 0, sizeof(CallControl));
133
134 { /* Call */
135 TOXAV_ERR_CALL rc;
136 toxav_call(AliceAV, friend_number, 48, 3000, &rc);
137
138 if (rc != TOXAV_ERR_CALL_OK) {
139 printf("toxav_call failed: %d\n", rc);
140 exit(1);
141 }
142 }
143
144 while (!BobCC->incoming)
145 c_sleep(10);
146
147 { /* Answer */
148 TOXAV_ERR_ANSWER rc;
149 toxav_answer(BobAV, 0, 8, 500, &rc);
150
151 if (rc != TOXAV_ERR_ANSWER_OK) {
152 printf("toxav_answer failed: %d\n", rc);
153 exit(1);
154 }
155 }
156
157 c_sleep(30);
158
159 int16_t PCM[960];
160 uint8_t video_y[800*600];
161 uint8_t video_u[800*600 / 2];
162 uint8_t video_v[800*600 / 2];
163
164 memset(PCM, 0, sizeof(PCM));
165 memset(video_y, 0, sizeof(video_y));
166 memset(video_u, 0, sizeof(video_u));
167 memset(video_v, 0, sizeof(video_v));
168
169 time_t start_time = time(NULL);
170 while(time(NULL) - start_time < 9) {
171 toxav_iterate(AliceAV);
172 toxav_iterate(BobAV);
173
174 toxav_send_audio_frame(AliceAV, friend_number, PCM, 960, 1, 48000, NULL);
175 toxav_send_audio_frame(BobAV, 0, PCM, 960, 1, 48000, NULL);
176
177 toxav_send_video_frame(AliceAV, friend_number, 800, 600, video_y, video_u, video_v, NULL);
178 toxav_send_video_frame(BobAV, 0, 800, 600, video_y, video_u, video_v, NULL);
179
180 c_sleep(10);
181 }
182
183 { /* Hangup */
184 TOXAV_ERR_CALL_CONTROL rc;
185 toxav_call_control(AliceAV, friend_number, TOXAV_CALL_CONTROL_CANCEL, &rc);
186
187 if (rc != TOXAV_ERR_CALL_CONTROL_OK) {
188 printf("toxav_call_control failed: %d\n", rc);
189 exit(1);
190 }
191 }
192
193 c_sleep(30);
111 pthread_exit(NULL); 194 pthread_exit(NULL);
112} 195}
113 196
197
114START_TEST(test_AV_three_calls) 198START_TEST(test_AV_three_calls)
115{ 199{
116 Tox* Alice, *bootstrap, *Bobs[3]; 200 Tox* Alice, *bootstrap, *Bobs[3];
@@ -118,7 +202,6 @@ START_TEST(test_AV_three_calls)
118 202
119 CallControl AliceCC[3], BobsCC[3]; 203 CallControl AliceCC[3], BobsCC[3];
120 204
121 int i = 0;
122 { 205 {
123 TOX_ERR_NEW error; 206 TOX_ERR_NEW error;
124 207
@@ -128,10 +211,14 @@ START_TEST(test_AV_three_calls)
128 Alice = tox_new(NULL, NULL, 0, &error); 211 Alice = tox_new(NULL, NULL, 0, &error);
129 assert(error == TOX_ERR_NEW_OK); 212 assert(error == TOX_ERR_NEW_OK);
130 213
131 for (; i < 3; i ++) { 214 Bobs[0] = tox_new(NULL, NULL, 0, &error);
132 BobsAV[i] = tox_new(NULL, NULL, 0, &error); 215 assert(error == TOX_ERR_NEW_OK);
133 assert(error == TOX_ERR_NEW_OK); 216
134 } 217 Bobs[1] = tox_new(NULL, NULL, 0, &error);
218 assert(error == TOX_ERR_NEW_OK);
219
220 Bobs[2] = tox_new(NULL, NULL, 0, &error);
221 assert(error == TOX_ERR_NEW_OK);
135 } 222 }
136 223
137 printf("Created 5 instances of Tox\n"); 224 printf("Created 5 instances of Tox\n");
@@ -178,25 +265,65 @@ START_TEST(test_AV_three_calls)
178 c_sleep(20); 265 c_sleep(20);
179 } 266 }
180 267
181 AliceAV = setup_av_instance(Alice, &AliceCC); 268 AliceAV = setup_av_instance(Alice, AliceCC);
182 BobsAV[0] = setup_av_instance(Bobs[0], &BobsCC[0]); 269 BobsAV[0] = setup_av_instance(Bobs[0], BobsCC + 0);
183 BobsAV[1] = setup_av_instance(Bobs[1], &BobsCC[1]); 270 BobsAV[1] = setup_av_instance(Bobs[1], BobsCC + 1);
184 BobsAV[2] = setup_av_instance(Bobs[2], &BobsCC[2]); 271 BobsAV[2] = setup_av_instance(Bobs[2], BobsCC + 2);
185 272
186 printf("Created 4 instances of ToxAV\n"); 273 printf("Created 4 instances of ToxAV\n");
187 printf("All set after %llu seconds!\n", time(NULL) - cur_time); 274 printf("All set after %llu seconds!\n", time(NULL) - cur_time);
188 275
276 thread_data tds[3];
277 tds[0].AliceAV = AliceAV;
278 tds[0].BobAV = BobsAV[0];
279 tds[0].AliceCC = AliceCC + 0;
280 tds[0].BobCC = BobsCC + 0;
281 tds[0].friend_number = 0;
189 282
283 tds[1].AliceAV = AliceAV;
284 tds[1].BobAV = BobsAV[1];
285 tds[1].AliceCC = AliceCC + 1;
286 tds[1].BobCC = BobsCC + 1;
287 tds[1].friend_number = 1;
190 288
191 tox_kill(bootstrap); 289 tds[2].AliceAV = AliceAV;
192 tox_kill(Alice); 290 tds[2].BobAV = BobsAV[2];
193 toxav_kill(AliceAV); 291 tds[2].AliceCC = AliceCC + 2;
292 tds[2].BobCC = BobsCC + 2;
293 tds[2].friend_number = 2;
194 294
195 for (i = 0; i < 3; i ++) { 295 pthread_t tids[3];
196 tox_kill(Bobs[i]); 296 (void) pthread_create(tids + 0, NULL, call_thread, tds + 0);
197 toxav_kill(BobsAV[i]); 297 (void) pthread_create(tids + 1, NULL, call_thread, tds + 1);
298 (void) pthread_create(tids + 2, NULL, call_thread, tds + 2);
299
300 (void) pthread_detach(tids[0]);
301 (void) pthread_detach(tids[1]);
302 (void) pthread_detach(tids[2]);
303
304 time_t start_time = time(NULL);
305 while (time(NULL) - start_time < 10) {
306 tox_iterate(Alice);
307 tox_iterate(Bobs[0]);
308 tox_iterate(Bobs[1]);
309 tox_iterate(Bobs[2]);
310 c_sleep(20);
198 } 311 }
199 312
313 (void) pthread_join(tids[0], NULL);
314 (void) pthread_join(tids[1], NULL);
315 (void) pthread_join(tids[2], NULL);
316
317 toxav_kill(BobsAV[0]);
318 toxav_kill(BobsAV[1]);
319 toxav_kill(BobsAV[2]);
320 toxav_kill(AliceAV);
321 tox_kill(Bobs[0]);
322 tox_kill(Bobs[1]);
323 tox_kill(Bobs[2]);
324 tox_kill(Alice);
325 tox_kill(bootstrap);
326
200 printf("\nTest successful!\n"); 327 printf("\nTest successful!\n");
201} 328}
202END_TEST 329END_TEST
@@ -218,6 +345,9 @@ Suite *tox_suite(void)
218 345
219int main(int argc, char *argv[]) 346int main(int argc, char *argv[])
220{ 347{
348 (void) argc;
349 (void) argv;
350
221 Suite *tox = tox_suite(); 351 Suite *tox = tox_suite();
222 SRunner *test_runner = srunner_create(tox); 352 SRunner *test_runner = srunner_create(tox);
223 353
diff --git a/toxav/msi.c b/toxav/msi.c
index f8bc8451..d68e4a9c 100644
--- a/toxav/msi.c
+++ b/toxav/msi.c
@@ -526,7 +526,7 @@ MSICall *new_call ( MSISession *session, uint32_t friend_number )
526 session->calls = tmp; 526 session->calls = tmp;
527 527
528 /* Set fields in between to null */ 528 /* Set fields in between to null */
529 int32_t i = session->calls_tail + 1; 529 uint32_t i = session->calls_tail + 1;
530 for (; i < friend_number; i ++) 530 for (; i < friend_number; i ++)
531 session->calls[i] = NULL; 531 session->calls[i] = NULL;
532 532
diff --git a/toxav/rtp.c b/toxav/rtp.c
index 2219805b..4ca23d2a 100644
--- a/toxav/rtp.c
+++ b/toxav/rtp.c
@@ -243,7 +243,8 @@ int rtp_send_data ( RTPSession *session, const uint8_t *data, uint16_t length, b
243 uint8_t parsed[MAX_RTP_SIZE]; 243 uint8_t parsed[MAX_RTP_SIZE];
244 uint8_t *it; 244 uint8_t *it;
245 245
246 RTPHeader header[1] = {0}; 246 RTPHeader header[1];
247 memset(header, 0, sizeof(header));
247 248
248 ADD_FLAG_VERSION ( header, session->version ); 249 ADD_FLAG_VERSION ( header, session->version );
249 ADD_FLAG_PADDING ( header, session->padding ); 250 ADD_FLAG_PADDING ( header, session->padding );
@@ -463,6 +464,9 @@ uint8_t *parse_ext_header_out ( const RTPExtHeader *header, uint8_t *payload )
463} 464}
464int handle_rtp_packet ( Messenger* m, uint32_t friendnumber, const uint8_t* data, uint16_t length, void* object ) 465int handle_rtp_packet ( Messenger* m, uint32_t friendnumber, const uint8_t* data, uint16_t length, void* object )
465{ 466{
467 (void) m;
468 (void) friendnumber;
469
466 RTPSession *session = object; 470 RTPSession *session = object;
467 471
468 if ( !session || length < 13 || length > MAX_RTP_SIZE ) { 472 if ( !session || length < 13 || length > MAX_RTP_SIZE ) {
@@ -553,6 +557,9 @@ int handle_rtp_packet ( Messenger* m, uint32_t friendnumber, const uint8_t* data
553} 557}
554int handle_rtcp_packet ( Messenger* m, uint32_t friendnumber, const uint8_t* data, uint16_t length, void* object ) 558int handle_rtcp_packet ( Messenger* m, uint32_t friendnumber, const uint8_t* data, uint16_t length, void* object )
555{ 559{
560 (void) m;
561 (void) friendnumber;
562
556 if (length < 9) 563 if (length < 9)
557 return -1; 564 return -1;
558 565
diff --git a/toxav/toxav.c b/toxav/toxav.c
index 25a2857c..e7807592 100644
--- a/toxav/toxav.c
+++ b/toxav/toxav.c
@@ -224,7 +224,7 @@ void toxav_iterate(ToxAV* av)
224 } 224 }
225 225
226 uint64_t start = current_time_monotonic(); 226 uint64_t start = current_time_monotonic();
227 uint32_t rc = 500; 227 int32_t rc = 500;
228 228
229 ToxAVCall* i = av->calls[av->calls_head]; 229 ToxAVCall* i = av->calls[av->calls_head];
230 for (; i; i = i->next) { 230 for (; i; i = i->next) {
@@ -292,7 +292,7 @@ void toxav_iterate(ToxAV* av)
292 292
293 if (i->msi_call->self_capabilities & msi_CapRVideo && 293 if (i->msi_call->self_capabilities & msi_CapRVideo &&
294 i->msi_call->peer_capabilities & msi_CapSVideo) 294 i->msi_call->peer_capabilities & msi_CapSVideo)
295 rc = MIN(i->video.second->lcfd, rc); 295 rc = MIN(i->video.second->lcfd, (uint32_t) rc);
296 296
297 uint32_t fid = i->friend_number; 297 uint32_t fid = i->friend_number;
298 298
@@ -821,7 +821,7 @@ bool toxav_send_video_frame(ToxAV* av, uint32_t friend_number, uint16_t width, u
821 } 821 }
822 } 822 }
823 823
824 if (call->vba.end_time == ~0) 824 if (call->vba.end_time == (uint64_t) ~0)
825 call->vba.end_time = current_time_monotonic() + BITRATE_CHANGE_TESTING_TIME_MS; 825 call->vba.end_time = current_time_monotonic() + BITRATE_CHANGE_TESTING_TIME_MS;
826 } 826 }
827 827
@@ -921,7 +921,7 @@ bool toxav_send_audio_frame(ToxAV* av, uint32_t friend_number, const int16_t* pc
921 rc = TOXAV_ERR_SEND_FRAME_RTP_FAILED; 921 rc = TOXAV_ERR_SEND_FRAME_RTP_FAILED;
922 } 922 }
923 923
924 if (call->aba.end_time == ~0) 924 if (call->aba.end_time == (uint64_t) ~0)
925 call->aba.end_time = current_time_monotonic() + BITRATE_CHANGE_TESTING_TIME_MS; 925 call->aba.end_time = current_time_monotonic() + BITRATE_CHANGE_TESTING_TIME_MS;
926 } 926 }
927 } 927 }
@@ -1056,6 +1056,7 @@ bool audio_bit_rate_invalid(uint32_t bit_rate)
1056 1056
1057bool video_bit_rate_invalid(uint32_t bit_rate) 1057bool video_bit_rate_invalid(uint32_t bit_rate)
1058{ 1058{
1059 (void) bit_rate;
1059 /* TODO: If anyone knows the answer to this one please fill it up */ 1060 /* TODO: If anyone knows the answer to this one please fill it up */
1060 return false; 1061 return false;
1061} 1062}
@@ -1123,7 +1124,7 @@ ToxAVCall* call_new(ToxAV* av, uint32_t friend_number, TOXAV_ERR_CALL* error)
1123 av->calls = tmp; 1124 av->calls = tmp;
1124 1125
1125 /* Set fields in between to null */ 1126 /* Set fields in between to null */
1126 int32_t i = av->calls_tail + 1; 1127 uint32_t i = av->calls_tail + 1;
1127 for (; i < friend_number; i ++) 1128 for (; i < friend_number; i ++)
1128 av->calls[i] = NULL; 1129 av->calls[i] = NULL;
1129 1130