diff options
author | mannol <eniz_vukovic@hotmail.com> | 2015-04-13 01:45:53 +0200 |
---|---|---|
committer | mannol <eniz_vukovic@hotmail.com> | 2015-04-13 01:45:53 +0200 |
commit | 2465f486acd90ed8395c8a83a13af09ecd024c98 (patch) | |
tree | 4abe53d39eb07a45e5ed4d8894b7ae038e2bb705 /toxav/av_test.c | |
parent | b2d88a4544a81a217db18b60d91a44d85821db3d (diff) |
Started custom RTCP
Diffstat (limited to 'toxav/av_test.c')
-rw-r--r-- | toxav/av_test.c | 107 |
1 files changed, 53 insertions, 54 deletions
diff --git a/toxav/av_test.c b/toxav/av_test.c index dab1f6ef..c20d459b 100644 --- a/toxav/av_test.c +++ b/toxav/av_test.c | |||
@@ -1,5 +1,31 @@ | |||
1 | /** av_test.c | ||
2 | * | ||
3 | * Copyright (C) 2013-2015 Tox project All Rights Reserved. | ||
4 | * | ||
5 | * This file is part of Tox. | ||
6 | * | ||
7 | * Tox is free software: you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation, either version 3 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * Tox is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with Tox. If not, see <http://www.gnu.org/licenses/>. | ||
19 | * | ||
20 | * Compile with (Linux only; in newly created directory toxcore/dir_name): | ||
21 | * gcc -o av_test ../toxav/av_test.c ../build/.libs/libtox*.a -lopencv_core \ | ||
22 | * -lopencv_highgui -lopencv_imgproc -lsndfile -pthread -lvpx -lopus -lsodium -lportaudio | ||
23 | */ | ||
24 | |||
25 | |||
1 | #include "../toxav/toxav.h" | 26 | #include "../toxav/toxav.h" |
2 | #include "../toxcore/tox.h" | 27 | #include "../toxcore/tox.h" |
28 | #include "../toxcore/util.h" | ||
3 | 29 | ||
4 | /* Playing audio data */ | 30 | /* Playing audio data */ |
5 | #include <portaudio.h> | 31 | #include <portaudio.h> |
@@ -11,7 +37,6 @@ | |||
11 | #include <opencv/highgui.h> | 37 | #include <opencv/highgui.h> |
12 | #include <opencv/cvwimage.h> | 38 | #include <opencv/cvwimage.h> |
13 | 39 | ||
14 | |||
15 | #include <sys/stat.h> | 40 | #include <sys/stat.h> |
16 | #include <assert.h> | 41 | #include <assert.h> |
17 | #include <stdio.h> | 42 | #include <stdio.h> |
@@ -63,8 +88,8 @@ struct toxav_thread_data { | |||
63 | int32_t sig; | 88 | int32_t sig; |
64 | }; | 89 | }; |
65 | 90 | ||
66 | const char* vdout = "AV Test"; | 91 | const char* vdout = "AV Test"; /* Video output */ |
67 | PaStream* adout = NULL; | 92 | PaStream* adout = NULL; /* Audio output */ |
68 | 93 | ||
69 | const char* stringify_state(TOXAV_CALL_STATE s) | 94 | const char* stringify_state(TOXAV_CALL_STATE s) |
70 | { | 95 | { |
@@ -230,7 +255,7 @@ void* iterate_toxav (void * data) | |||
230 | toxav_iterate(data_cast->BobAV); | 255 | toxav_iterate(data_cast->BobAV); |
231 | int rc = MIN(toxav_iteration_interval(data_cast->AliceAV), toxav_iteration_interval(data_cast->BobAV)); | 256 | int rc = MIN(toxav_iteration_interval(data_cast->AliceAV), toxav_iteration_interval(data_cast->BobAV)); |
232 | 257 | ||
233 | // cvWaitKey(rc); | 258 | // cvWaitKey(10); |
234 | c_sleep(10); | 259 | c_sleep(10); |
235 | } | 260 | } |
236 | 261 | ||
@@ -306,7 +331,26 @@ int print_help (const char* name) | |||
306 | 331 | ||
307 | int main (int argc, char** argv) | 332 | int main (int argc, char** argv) |
308 | { | 333 | { |
334 | RingBuffer* rb = rb_new(4); | ||
335 | int a[5] = {0, 1, 2, 3, 4}; | ||
336 | int* x; | ||
337 | rb_write(rb, a + 0); | ||
338 | rb_write(rb, a + 1); | ||
339 | rb_write(rb, a + 2); | ||
340 | rb_write(rb, a + 3); | ||
341 | // rb_write(rb, a + 4); | ||
342 | |||
343 | x = rb_write(rb, a + 4); | ||
344 | while (rb_read(rb, (void**) &x)) | ||
345 | // rb_read(rb, (void**)&x); | ||
346 | printf("%d ", *x); | ||
347 | |||
348 | printf("\n"); | ||
349 | // int r = 43; | ||
350 | // printf("%d\n", r >= 40 ? 3 : r / 10); | ||
351 | return 0; | ||
309 | Pa_Initialize(); | 352 | Pa_Initialize(); |
353 | |||
310 | struct stat st; | 354 | struct stat st; |
311 | 355 | ||
312 | /* AV files for testing */ | 356 | /* AV files for testing */ |
@@ -395,53 +439,6 @@ int main (int argc, char** argv) | |||
395 | return 1; | 439 | return 1; |
396 | } | 440 | } |
397 | 441 | ||
398 | if (0) { | ||
399 | SNDFILE* af_handle; | ||
400 | SF_INFO af_info; | ||
401 | |||
402 | /* Open audio file */ | ||
403 | af_handle = sf_open(af_name, SFM_READ, &af_info); | ||
404 | if (af_handle == NULL) { | ||
405 | printf("Failed to open the file.\n"); | ||
406 | exit(1); | ||
407 | } | ||
408 | |||
409 | int frame_size = (af_info.samplerate * audio_frame_duration / 1000) * af_info.channels; | ||
410 | |||
411 | struct PaStreamParameters output; | ||
412 | output.device = audio_out_dev_idx; /* default output device */ | ||
413 | output.channelCount = af_info.channels; | ||
414 | output.sampleFormat = paInt16; | ||
415 | output.suggestedLatency = audio_dev->defaultHighOutputLatency; | ||
416 | output.hostApiSpecificStreamInfo = NULL; | ||
417 | |||
418 | |||
419 | PaError err = Pa_OpenStream(&adout, NULL, &output, af_info.samplerate, frame_size, paNoFlag, NULL, NULL); | ||
420 | assert(err == paNoError); | ||
421 | |||
422 | err = Pa_StartStream(adout); | ||
423 | assert(err == paNoError); | ||
424 | |||
425 | int16_t PCM[frame_size]; | ||
426 | |||
427 | time_t start_time = time(NULL); | ||
428 | time_t expected_time = af_info.frames / af_info.samplerate + 2; | ||
429 | |||
430 | printf("Sample rate %d\n", af_info.samplerate); | ||
431 | while ( start_time + expected_time > time(NULL) ) { | ||
432 | |||
433 | int64_t count = sf_read_short(af_handle, PCM, frame_size); | ||
434 | if (count > 0) { | ||
435 | t_toxav_receive_audio_frame_cb(NULL, 0, PCM, count, af_info.channels, af_info.samplerate, NULL); | ||
436 | } | ||
437 | |||
438 | c_sleep(audio_frame_duration / 2); | ||
439 | } | ||
440 | |||
441 | Pa_Terminate(); | ||
442 | return 0; | ||
443 | } | ||
444 | |||
445 | printf("Using audio device: %s\n", audio_dev->name); | 442 | printf("Using audio device: %s\n", audio_dev->name); |
446 | printf("Using audio file: %s\n", af_name); | 443 | printf("Using audio file: %s\n", af_name); |
447 | printf("Using video file: %s\n", vf_name); | 444 | printf("Using video file: %s\n", vf_name); |
@@ -758,17 +755,15 @@ int main (int argc, char** argv) | |||
758 | 755 | ||
759 | printf("Sample rate %d\n", af_info.samplerate); | 756 | printf("Sample rate %d\n", af_info.samplerate); |
760 | while ( start_time + expected_time > time(NULL) ) { | 757 | while ( start_time + expected_time > time(NULL) ) { |
761 | |||
762 | int64_t count = sf_read_short(af_handle, PCM, frame_size); | 758 | int64_t count = sf_read_short(af_handle, PCM, frame_size); |
763 | if (count > 0) { | 759 | if (count > 0) { |
764 | TOXAV_ERR_SEND_FRAME rc; | 760 | TOXAV_ERR_SEND_FRAME rc; |
765 | if (toxav_send_audio_frame(AliceAV, 0, PCM, count/af_info.channels, af_info.channels, af_info.samplerate, &rc) == false) { | 761 | if (toxav_send_audio_frame(AliceAV, 0, PCM, count/af_info.channels, af_info.channels, af_info.samplerate, &rc) == false) { |
766 | printf("Error sending frame of size %ld: %d\n", count, rc); | 762 | printf("Error sending frame of size %ld: %d\n", count, rc); |
767 | // exit(1); | ||
768 | } | 763 | } |
769 | } | 764 | } |
770 | iterate_tox(bootstrap, AliceAV, BobAV); | 765 | iterate_tox(bootstrap, AliceAV, BobAV); |
771 | c_sleep(30); | 766 | c_sleep(53); |
772 | } | 767 | } |
773 | 768 | ||
774 | 769 | ||
@@ -794,6 +789,8 @@ int main (int argc, char** argv) | |||
794 | while(data.sig != 1) | 789 | while(data.sig != 1) |
795 | pthread_yield(); | 790 | pthread_yield(); |
796 | 791 | ||
792 | Pa_StopStream(adout); | ||
793 | |||
797 | printf("Success!"); | 794 | printf("Success!"); |
798 | } | 795 | } |
799 | 796 | ||
@@ -890,5 +887,7 @@ int main (int argc, char** argv) | |||
890 | tox_kill(bootstrap); | 887 | tox_kill(bootstrap); |
891 | 888 | ||
892 | printf("\nTest successful!\n"); | 889 | printf("\nTest successful!\n"); |
890 | |||
891 | Pa_Terminate(); | ||
893 | return 0; | 892 | return 0; |
894 | } | 893 | } |