summaryrefslogtreecommitdiff
path: root/toxav/av_test.c
diff options
context:
space:
mode:
authormannol <eniz_vukovic@hotmail.com>2015-02-22 23:41:40 +0100
committermannol <eniz_vukovic@hotmail.com>2015-02-24 23:27:20 +0100
commit9e65cd533735f1acc638241ed58400bf7029b1ef (patch)
tree59e4edc2d5b59d695bc87cfbd1b410700737dc4c /toxav/av_test.c
parent29601feb7656d1a75b4ab7cdb161f232f0ec92dc (diff)
Implement pausing
Diffstat (limited to 'toxav/av_test.c')
-rw-r--r--toxav/av_test.c173
1 files changed, 114 insertions, 59 deletions
diff --git a/toxav/av_test.c b/toxav/av_test.c
index 594e7232..41f5a758 100644
--- a/toxav/av_test.c
+++ b/toxav/av_test.c
@@ -16,13 +16,25 @@
16 16
17typedef struct { 17typedef struct {
18 bool incoming; 18 bool incoming;
19 bool ringing; 19 TOXAV_CALL_STATE state;
20 bool ended;
21 bool errored;
22 bool sending;
23 bool paused;
24} CallControl; 20} CallControl;
25 21
22const char* stringify_state(TOXAV_CALL_STATE s)
23{
24 static const char* strings[] =
25 {
26 "NOT SENDING",
27 "SENDING AUDIO",
28 "SENDING VIDEO",
29 "SENDING AUDIO AND VIDEO",
30 "PAUSED",
31 "END",
32 "ERROR"
33 };
34
35 return strings [s];
36};
37
26 38
27/** 39/**
28 * Callbacks 40 * Callbacks
@@ -34,53 +46,9 @@ void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool
34} 46}
35void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, TOXAV_CALL_STATE state, void *user_data) 47void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, TOXAV_CALL_STATE state, void *user_data)
36{ 48{
37 printf("Handling CALL STATE callback: "); 49 printf("Handling CALL STATE callback: %s\n", stringify_state(state));
38
39 if (((CallControl*)user_data)->paused)
40 ((CallControl*)user_data)->paused = false;
41
42 switch (state)
43 {
44 case TOXAV_CALL_STATE_NOT_SENDING: {
45 printf("Not sending");
46 ((CallControl*)user_data)->sending = false;
47 } break;
48
49 case TOXAV_CALL_STATE_SENDING_A: {
50 printf("Sending Audio");
51 ((CallControl*)user_data)->sending = true;
52 } break;
53
54 case TOXAV_CALL_STATE_SENDING_V: {
55 printf("Sending Video");
56 ((CallControl*)user_data)->sending = true;
57 } break;
58
59 case TOXAV_CALL_STATE_SENDING_AV: {
60 printf("Sending Both");
61 ((CallControl*)user_data)->sending = true;
62 } break;
63
64 case TOXAV_CALL_STATE_PAUSED: {
65 printf("Paused");
66 ((CallControl*)user_data)->paused = true;
67 ((CallControl*)user_data)->sending = false;
68 } break;
69
70 case TOXAV_CALL_STATE_END: {
71 printf("Ended");
72 ((CallControl*)user_data)->ended = true;
73 ((CallControl*)user_data)->sending = false;
74 } break;
75
76 case TOXAV_CALL_STATE_ERROR: {
77 printf("Error");
78 ((CallControl*)user_data)->errored = true;
79 ((CallControl*)user_data)->sending = false;
80 } break;
81 }
82 50
83 printf("\n"); 51 ((CallControl*)user_data)->state = state;
84} 52}
85void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, 53void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number,
86 uint16_t width, uint16_t height, 54 uint16_t width, uint16_t height,
@@ -211,27 +179,24 @@ int main (int argc, char** argv)
211 long long unsigned int start_time = time(NULL); \ 179 long long unsigned int start_time = time(NULL); \
212 \ 180 \
213 \ 181 \
214 while (!AliceCC.ended || !BobCC.ended) { \ 182 while (BobCC.state != TOXAV_CALL_STATE_END) { \
215 \ 183 \
216 if (BobCC.incoming) { \ 184 if (BobCC.incoming) { \
217 TOXAV_ERR_ANSWER rc; \ 185 TOXAV_ERR_ANSWER rc; \
218 toxav_answer(BobAV, 0, 48, 4000, &rc); \ 186 toxav_answer(BobAV, 0, A_BR, V_BR, &rc); \
219 \ 187 \
220 if (rc != TOXAV_ERR_ANSWER_OK) { \ 188 if (rc != TOXAV_ERR_ANSWER_OK) { \
221 printf("toxav_answer failed: %d\n", rc); \ 189 printf("toxav_answer failed: %d\n", rc); \
222 exit(1); \ 190 exit(1); \
223 } \ 191 } \
224 BobCC.incoming = false; \ 192 BobCC.incoming = false; \
225 BobCC.sending = true; /* There is no more start callback when answering */\ 193 } else { \
226 } \
227 else if (AliceCC.sending && BobCC.sending) { \
228 /* TODO rtp */ \ 194 /* TODO rtp */ \
229 \ 195 \
230 if (time(NULL) - start_time == 5) { \ 196 if (time(NULL) - start_time == 5) { \
231 \ 197 \
232 TOXAV_ERR_CALL_CONTROL rc; \ 198 TOXAV_ERR_CALL_CONTROL rc; \
233 toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_CANCEL, &rc); \ 199 toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_CANCEL, &rc); \
234 AliceCC.ended = true; /* There is no more end callback when hanging up */\
235 \ 200 \
236 if (rc != TOXAV_ERR_CALL_CONTROL_OK) { \ 201 if (rc != TOXAV_ERR_CALL_CONTROL_OK) { \
237 printf("toxav_call_control failed: %d\n", rc); \ 202 printf("toxav_call_control failed: %d\n", rc); \
@@ -286,7 +251,7 @@ int main (int argc, char** argv)
286 } 251 }
287 } 252 }
288 253
289 while (!AliceCC.ended) 254 while (AliceCC.state != TOXAV_CALL_STATE_END)
290 iterate(Bsn, AliceAV, BobAV); 255 iterate(Bsn, AliceAV, BobAV);
291 256
292 printf("Success!\n"); 257 printf("Success!\n");
@@ -323,9 +288,99 @@ int main (int argc, char** argv)
323 } 288 }
324 289
325 /* Alice will not receive end state */ 290 /* Alice will not receive end state */
326 while (!BobCC.ended) 291 while (BobCC.state != TOXAV_CALL_STATE_END)
292 iterate(Bsn, AliceAV, BobAV);
293
294 printf("Success!\n");
295 }
296
297 { /* Check Mute-Unmute etc */
298 printf("\nTrying mute functionality...\n");
299
300
301 memset(&AliceCC, 0, sizeof(CallControl));
302 memset(&BobCC, 0, sizeof(CallControl));
303
304 /* Assume sending audio and video */
305 {
306 TOXAV_ERR_CALL rc;
307 toxav_call(AliceAV, 0, 48, 1000, &rc);
308
309 if (rc != TOXAV_ERR_CALL_OK) {
310 printf("toxav_call failed: %d\n", rc);
311 exit(1);
312 }
313 }
314
315 while (!BobCC.incoming)
327 iterate(Bsn, AliceAV, BobAV); 316 iterate(Bsn, AliceAV, BobAV);
328 317
318 /* At first try all stuff while in invalid state */
319 assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_PAUSE, NULL));
320 assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_RESUME, NULL));
321 assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_MUTE_AUDIO, NULL));
322 assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_MUTE_VIDEO, NULL));
323 assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_UNMUTE_AUDIO, NULL));
324 assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_UNMUTE_VIDEO, NULL));
325
326 {
327 TOXAV_ERR_ANSWER rc;
328 toxav_answer(BobAV, 0, 48, 4000, &rc);
329
330 if (rc != TOXAV_ERR_ANSWER_OK) {
331 printf("toxav_answer failed: %d\n", rc);
332 exit(1);
333 }
334 }
335
336 iterate(Bsn, AliceAV, BobAV);
337
338 /* Pause and Resume */
339 printf("Pause and Resume\n");
340 assert(toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_PAUSE, NULL));
341 iterate(Bsn, AliceAV, BobAV);
342 assert(BobCC.state == TOXAV_CALL_STATE_PAUSED);
343 assert(toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_RESUME, NULL));
344 iterate(Bsn, AliceAV, BobAV);
345 assert(BobCC.state == TOXAV_CALL_STATE_SENDING_AV);
346
347 /* Mute/Unmute single */
348 printf("Mute/Unmute single\n");
349 assert(toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_MUTE_AUDIO, NULL));
350 iterate(Bsn, AliceAV, BobAV);
351 assert(BobCC.state == TOXAV_CALL_CONTROL_MUTE_AUDIO);
352 assert(toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_UNMUTE_AUDIO, NULL));
353 iterate(Bsn, AliceAV, BobAV);
354 assert(BobCC.state == TOXAV_CALL_CONTROL_UNMUTE_AUDIO);
355
356 /* Mute/Unmute both */
357 printf("Mute/Unmute both\n");
358 assert(toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_MUTE_AUDIO, NULL));
359 iterate(Bsn, AliceAV, BobAV);
360 assert(BobCC.state == TOXAV_CALL_STATE_SENDING_V);
361 assert(toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_MUTE_VIDEO, NULL));
362 iterate(Bsn, AliceAV, BobAV);
363 assert(BobCC.state == TOXAV_CALL_STATE_NOT_SENDING);
364 assert(toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_UNMUTE_AUDIO, NULL));
365 iterate(Bsn, AliceAV, BobAV);
366 assert(BobCC.state == TOXAV_CALL_STATE_SENDING_A);
367 assert(toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_UNMUTE_VIDEO, NULL));
368 iterate(Bsn, AliceAV, BobAV);
369 assert(BobCC.state == TOXAV_CALL_STATE_SENDING_AV);
370
371 {
372 TOXAV_ERR_CALL_CONTROL rc;
373 toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
374
375 if (rc != TOXAV_ERR_CALL_CONTROL_OK) {
376 printf("toxav_call_control failed: %d\n", rc);
377 exit(1);
378 }
379 }
380
381 iterate(Bsn, AliceAV, BobAV);
382 assert(BobCC.state == TOXAV_CALL_STATE_END);
383
329 printf("Success!\n"); 384 printf("Success!\n");
330 } 385 }
331 386