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.c110
1 files changed, 67 insertions, 43 deletions
diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c
index 048567bb..c8ebd497 100644
--- a/auto_tests/toxav_basic_test.c
+++ b/auto_tests/toxav_basic_test.c
@@ -46,6 +46,9 @@ typedef struct _Status {
46 Party Bob; 46 Party Bob;
47} Status; 47} Status;
48 48
49/* My default settings */
50static ToxAvCodecSettings muhcaps;
51
49void accept_friend_request(Tox *m, uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata) 52void accept_friend_request(Tox *m, uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata)
50{ 53{
51 if (length == 7 && memcmp("gentoo", data, 7) == 0) { 54 if (length == 7 && memcmp("gentoo", data, 7) == 0) {
@@ -77,7 +80,7 @@ void callback_recv_starting ( uint32_t call_index, void *_arg )
77 /* Alice always sends invite */ 80 /* Alice always sends invite */
78 printf("Call started on Alice side...\n"); 81 printf("Call started on Alice side...\n");
79 cast->Alice.status = InCall; 82 cast->Alice.status = InCall;
80 toxav_prepare_transmission(cast->Alice.av, call_index, 1); 83 toxav_prepare_transmission(cast->Alice.av, call_index, &muhcaps, 1);
81} 84}
82void callback_recv_ending ( uint32_t call_index, void *_arg ) 85void callback_recv_ending ( uint32_t call_index, void *_arg )
83{ 86{
@@ -104,7 +107,7 @@ void callback_call_started ( uint32_t call_index, void *_arg )
104 /* Alice always sends invite */ 107 /* Alice always sends invite */
105 printf("Call started on Bob side...\n"); 108 printf("Call started on Bob side...\n");
106 cast->Bob.status = InCall; 109 cast->Bob.status = InCall;
107 toxav_prepare_transmission(cast->Bob.av, call_index, 1); 110 toxav_prepare_transmission(cast->Bob.av, call_index, &muhcaps, 1);
108} 111}
109void callback_call_canceled ( uint32_t call_index, void *_arg ) 112void callback_call_canceled ( uint32_t call_index, void *_arg )
110{ 113{
@@ -193,12 +196,12 @@ START_TEST(test_AV_flows)
193 196
194 printf("All set after %llu seconds! Starting call...\n", time(NULL) - cur_time); 197 printf("All set after %llu seconds! Starting call...\n", time(NULL) - cur_time);
195 198
196 ToxAvCodecSettings muhcaps = av_DefaultSettings; 199 muhcaps = av_DefaultSettings;
197 muhcaps.video_height = muhcaps.video_width = 128; 200 muhcaps.video_height = muhcaps.video_width = 128;
198 201
199 Status status_control = { 202 Status status_control = {
200 {none, toxav_new(Alice, &muhcaps, 1), NULL}, 203 {none, toxav_new(Alice, 1), NULL},
201 {none, toxav_new(Bob, &muhcaps, 1), NULL}, 204 {none, toxav_new(Bob, 1), NULL},
202 }; 205 };
203 206
204 207
@@ -221,6 +224,9 @@ START_TEST(test_AV_flows)
221 224
222 225
223 int16_t sample_payload[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 226 int16_t sample_payload[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
227 uint8_t prepared_payload[1000];
228 int payload_size;
229
224 vpx_image_t *sample_image = vpx_img_alloc(NULL, VPX_IMG_FMT_I420, 128, 128, 1); 230 vpx_image_t *sample_image = vpx_img_alloc(NULL, VPX_IMG_FMT_I420, 128, 128, 1);
225 231
226 memcpy(sample_image->planes[VPX_PLANE_Y], sample_payload, 10); 232 memcpy(sample_image->planes[VPX_PLANE_Y], sample_payload, 10);
@@ -237,15 +243,20 @@ START_TEST(test_AV_flows)
237 */ 243 */
238 CALL_AND_START_LOOP(TypeAudio, TypeAudio) { 244 CALL_AND_START_LOOP(TypeAudio, TypeAudio) {
239 /* Both send */ 245 /* Both send */
240 toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, sample_payload, 10); 246 int payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, 1000, sample_payload, 120);
241 toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, sample_payload, 10); 247 if (!( payload_size > 0 )) { /* FIXME: this will always fail */
248 ck_assert_msg ( 0, "Failed to encode payload" );
249 }
250
251 toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size);
252 toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size);
242 253
243 /* Both receive */ 254 /* Both receive */
244 int16_t storage[10]; 255 int16_t storage[10];
245 int recved; 256 int recved;
246 257
247 /* Payload from Bob */ 258 /* Payload from Bob */
248 recved = toxav_recv_audio(status_control.Alice.av, status_control.Alice.call_index, 10, storage); 259 recved = toxav_recv_audio(status_control.Alice.av, status_control.Alice.call_index, 120, storage);
249 260
250 if ( recved ) { 261 if ( recved ) {
251 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid");*/ 262 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid");*/
@@ -253,7 +264,7 @@ START_TEST(test_AV_flows)
253 } 264 }
254 265
255 /* Payload from Alice */ 266 /* Payload from Alice */
256 recved = toxav_recv_audio(status_control.Bob.av, status_control.Bob.call_index, 10, storage); 267 recved = toxav_recv_audio(status_control.Bob.av, status_control.Bob.call_index, 120, storage);
257 268
258 if ( recved ) { 269 if ( recved ) {
259 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid");*/ 270 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid");*/
@@ -276,10 +287,15 @@ START_TEST(test_AV_flows)
276 */ 287 */
277 CALL_AND_START_LOOP(TypeAudio, TypeVideo) { 288 CALL_AND_START_LOOP(TypeAudio, TypeVideo) {
278 /* Both send */ 289 /* Both send */
279 toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, sample_payload, 10); 290 int payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, 1000, sample_payload, 120);
280 291 if (!( payload_size > 0 )) { /* FIXME: this will always fail */
281 toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, sample_payload, 10); 292 ck_assert_msg ( 0, "Failed to encode payload" );
282 toxav_send_video(status_control.Bob.av, status_control.Bob.call_index, sample_image); 293 }
294
295 toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size);
296
297 toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size);
298// toxav_send_video(status_control.Bob.av, status_control.Bob.call_index, sample_image);
283 299
284 /* Both receive */ 300 /* Both receive */
285 int16_t storage[10]; 301 int16_t storage[10];
@@ -287,7 +303,7 @@ START_TEST(test_AV_flows)
287 int recved; 303 int recved;
288 304
289 /* Payload from Bob */ 305 /* Payload from Bob */
290 recved = toxav_recv_audio(status_control.Alice.av, status_control.Alice.call_index, 10, storage); 306 recved = toxav_recv_audio(status_control.Alice.av, status_control.Alice.call_index, 120, storage);
291 307
292 if ( recved ) { 308 if ( recved ) {
293 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid");*/ 309 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid");*/
@@ -295,19 +311,20 @@ START_TEST(test_AV_flows)
295 } 311 }
296 312
297 /* Video payload */ 313 /* Video payload */
298 toxav_recv_video(status_control.Alice.av, status_control.Alice.call_index, &video_storage); 314// toxav_recv_video(status_control.Alice.av, status_control.Alice.call_index, &video_storage);
299 315//
300 if ( video_storage ) { 316// if ( video_storage ) {
301 /*ck_assert_msg( memcmp(video_storage->planes[VPX_PLANE_Y], sample_payload, 10) == 0 || 317// /*ck_assert_msg( memcmp(video_storage->planes[VPX_PLANE_Y], sample_payload, 10) == 0 ||
302 memcmp(video_storage->planes[VPX_PLANE_U], sample_payload, 10) == 0 || 318// memcmp(video_storage->planes[VPX_PLANE_U], sample_payload, 10) == 0 ||
303 memcmp(video_storage->planes[VPX_PLANE_V], sample_payload, 10) == 0 , "Payload from Bob is invalid");*/ 319// memcmp(video_storage->planes[VPX_PLANE_V], sample_payload, 10) == 0 , "Payload from Bob is invalid");*/
304 } 320// vpx_img_free(video_storage);
321// }
305 322
306 323
307 324
308 325
309 /* Payload from Alice */ 326 /* Payload from Alice */
310 recved = toxav_recv_audio(status_control.Bob.av, status_control.Bob.call_index, 10, storage); 327 recved = toxav_recv_audio(status_control.Bob.av, status_control.Bob.call_index, 120, storage);
311 328
312 if ( recved ) { 329 if ( recved ) {
313 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid");*/ 330 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid");*/
@@ -330,11 +347,16 @@ START_TEST(test_AV_flows)
330 */ 347 */
331 CALL_AND_START_LOOP(TypeVideo, TypeVideo) { 348 CALL_AND_START_LOOP(TypeVideo, TypeVideo) {
332 /* Both send */ 349 /* Both send */
333 toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, sample_payload, 10); 350 int payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, 1000, sample_payload, 120);
334 toxav_send_video(status_control.Alice.av, status_control.Alice.call_index, sample_image); 351 if (!( payload_size > 0 )) { /* FIXME: this will always fail */
335 352 ck_assert_msg ( 0, "Failed to encode payload" );
336 toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, sample_payload, 10); 353 }
337 toxav_send_video(status_control.Bob.av, status_control.Bob.call_index, sample_image); 354
355 toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size);
356// toxav_send_video(status_control.Alice.av, status_control.Alice.call_index, sample_image);
357
358 toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size);
359// toxav_send_video(status_control.Bob.av, status_control.Bob.call_index, sample_image);
338 360
339 /* Both receive */ 361 /* Both receive */
340 int16_t storage[10]; 362 int16_t storage[10];
@@ -342,7 +364,7 @@ START_TEST(test_AV_flows)
342 int recved; 364 int recved;
343 365
344 /* Payload from Bob */ 366 /* Payload from Bob */
345 recved = toxav_recv_audio(status_control.Alice.av, status_control.Alice.call_index, 10, storage); 367 recved = toxav_recv_audio(status_control.Alice.av, status_control.Alice.call_index, 120, storage);
346 368
347 if ( recved ) { 369 if ( recved ) {
348 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid");*/ 370 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid");*/
@@ -350,32 +372,34 @@ START_TEST(test_AV_flows)
350 } 372 }
351 373
352 /* Video payload */ 374 /* Video payload */
353 toxav_recv_video(status_control.Alice.av, status_control.Alice.call_index, &video_storage); 375// toxav_recv_video(status_control.Alice.av, status_control.Alice.call_index, &video_storage);
354 376//
355 if ( video_storage ) { 377// if ( video_storage ) {
356 /*ck_assert_msg( memcmp(video_storage->planes[VPX_PLANE_Y], sample_payload, 10) == 0 || 378// /*ck_assert_msg( memcmp(video_storage->planes[VPX_PLANE_Y], sample_payload, 10) == 0 ||
357 memcmp(video_storage->planes[VPX_PLANE_U], sample_payload, 10) == 0 || 379// memcmp(video_storage->planes[VPX_PLANE_U], sample_payload, 10) == 0 ||
358 memcmp(video_storage->planes[VPX_PLANE_V], sample_payload, 10) == 0 , "Payload from Bob is invalid");*/ 380// memcmp(video_storage->planes[VPX_PLANE_V], sample_payload, 10) == 0 , "Payload from Bob is invalid");*/
359 } 381// vpx_img_free(video_storage);
382// }
360 383
361 384
362 385
363 386
364 /* Payload from Alice */ 387 /* Payload from Alice */
365 recved = toxav_recv_audio(status_control.Bob.av, status_control.Bob.call_index, 10, storage); 388 recved = toxav_recv_audio(status_control.Bob.av, status_control.Bob.call_index, 120, storage);
366 389
367 if ( recved ) { 390 if ( recved ) {
368 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid");*/ 391 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid");*/
369 } 392 }
370 393
371 /* Video payload */ 394 /* Video payload */
372 toxav_recv_video(status_control.Bob.av, status_control.Bob.call_index, &video_storage); 395// toxav_recv_video(status_control.Bob.av, status_control.Bob.call_index, &video_storage);
373 396//
374 if ( video_storage ) { 397// if ( video_storage ) {
375 /*ck_assert_msg( memcmp(video_storage->planes[VPX_PLANE_Y], sample_payload, 10) == 0 || 398// /*ck_assert_msg( memcmp(video_storage->planes[VPX_PLANE_Y], sample_payload, 10) == 0 ||
376 memcmp(video_storage->planes[VPX_PLANE_U], sample_payload, 10) == 0 || 399// memcmp(video_storage->planes[VPX_PLANE_U], sample_payload, 10) == 0 ||
377 memcmp(video_storage->planes[VPX_PLANE_V], sample_payload, 10) == 0 , "Payload from Alice is invalid");*/ 400// memcmp(video_storage->planes[VPX_PLANE_V], sample_payload, 10) == 0 , "Payload from Alice is invalid");*/
378 } 401// vpx_img_free(video_storage);
402// }
379 403
380 404
381 if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */ 405 if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */