diff options
Diffstat (limited to 'auto_tests/toxav_many_test.c')
-rw-r--r-- | auto_tests/toxav_many_test.c | 133 |
1 files changed, 54 insertions, 79 deletions
diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c index 3195d1ed..ee4c812c 100644 --- a/auto_tests/toxav_many_test.c +++ b/auto_tests/toxav_many_test.c | |||
@@ -44,6 +44,7 @@ typedef struct _Party { | |||
44 | 44 | ||
45 | typedef struct _ACall { | 45 | typedef 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 | ||
57 | Status status_control; | ||
58 | |||
56 | void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata) | 59 | void 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 | /******************************************************************************/ |
65 | void callback_recv_invite ( int32_t call_index, void *_arg ) | 68 | void 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 | } |
72 | void callback_recv_ringing ( int32_t call_index, void *_arg ) | 75 | void 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 | } |
78 | void callback_recv_starting ( int32_t call_index, void *_arg ) | 80 | void 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 | } |
84 | void callback_recv_ending ( int32_t call_index, void *_arg ) | 85 | void 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 | ||
91 | void callback_recv_error ( int32_t call_index, void *_arg ) | 91 | void callback_call_started ( void* av, int32_t call_index, void *_arg ) |
92 | { | ||
93 | ck_assert_msg(0, "AV internal error"); | ||
94 | } | ||
95 | |||
96 | void 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 | } |
103 | void callback_call_canceled ( int32_t call_index, void *_arg ) | 98 | void 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 | } |
110 | void callback_call_rejected ( int32_t call_index, void *_arg ) | 105 | void 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 | } |
116 | void callback_call_ended ( int32_t call_index, void *_arg ) | 110 | void 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 | ||
124 | void callback_requ_timeout ( int32_t call_index, void *_arg ) | 118 | void 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 | |||
133 | static void callback_video(ToxAv *av, int32_t call_index, vpx_image_t *img) | 127 | static void callback_video(ToxAv *av, int32_t call_index, vpx_image_t *img) |
134 | { | 128 | { |
135 | } | 129 | } |
130 | void 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 | ||
150 | int call_running[3]; | ||
138 | 151 | ||
139 | void *in_thread_call (void *arg) | 152 | void *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); | 171 | |
157 | toxav_register_video_recv_callback(this_call->Callee.av, callback_video); | ||
158 | |||
159 | |||
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}, | 325 | |
328 | {none, toxav_new(callees[0], 1), 0}, | 326 | status_control.calls[i].Caller.av = uniqcallerav; |
329 | 327 | status_control.calls[i].Caller.id = 0; | |
330 | 0, | 328 | status_control.calls[i].Caller.status= none; |
331 | {none, uniqcallerav}, | 329 | |
332 | {none, toxav_new(callees[1], 1), 1}, | 330 | status_control.calls[i].Callee.av = toxav_new(callees[i], 1); |
333 | 331 | status_control.calls[i].Callee.id = i; | |
334 | 0, | 332 | status_control.calls[i].Callee.status= none; |
335 | {none, uniqcallerav}, | 333 | } |
336 | {none, toxav_new(callees[2], 1), 2} | 334 | |
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 | |||
350 | toxav_register_callstate_callback(callback_recv_error, av_OnError, &status_control); | ||
351 | toxav_register_callstate_callback(callback_requ_timeout, av_OnRequestTimeout, &status_control); | ||
352 | |||
353 | |||
354 | pthread_mutex_init(&muhmutex, NULL); | 335 | pthread_mutex_init(&muhmutex, NULL); |
355 | 336 | ||
356 | 337 | for ( i = 0; i < 3; i++ ) | |
357 | 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); |