ffi-tox 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/ProjectTox-Core/AUTHORS +0 -0
  3. data/ProjectTox-Core/ChangeLog +0 -0
  4. data/ProjectTox-Core/INSTALL +370 -0
  5. data/ProjectTox-Core/INSTALL.md +455 -56
  6. data/ProjectTox-Core/Makefile.am +35 -0
  7. data/ProjectTox-Core/NEWS +0 -0
  8. data/ProjectTox-Core/README +43 -0
  9. data/ProjectTox-Core/README.md +34 -44
  10. data/ProjectTox-Core/auto_tests/Makefile.inc +110 -0
  11. data/ProjectTox-Core/auto_tests/TCP_test.c +519 -0
  12. data/ProjectTox-Core/auto_tests/assoc_test.c +160 -0
  13. data/ProjectTox-Core/auto_tests/crypto_test.c +302 -0
  14. data/ProjectTox-Core/auto_tests/dht_test.c +362 -0
  15. data/ProjectTox-Core/auto_tests/encryptsave_test.c +104 -0
  16. data/ProjectTox-Core/auto_tests/friends_test.c +238 -0
  17. data/ProjectTox-Core/auto_tests/helpers.h +15 -0
  18. data/ProjectTox-Core/auto_tests/messenger_test.c +365 -0
  19. data/ProjectTox-Core/auto_tests/network_test.c +171 -0
  20. data/ProjectTox-Core/auto_tests/onion_test.c +363 -0
  21. data/ProjectTox-Core/auto_tests/skeleton_test.c +49 -0
  22. data/ProjectTox-Core/auto_tests/tox_test.c +454 -0
  23. data/ProjectTox-Core/auto_tests/toxav_basic_test.c +597 -0
  24. data/ProjectTox-Core/auto_tests/toxav_many_test.c +402 -0
  25. data/ProjectTox-Core/autogen.sh +6 -0
  26. data/ProjectTox-Core/build/Makefile.am +14 -0
  27. data/ProjectTox-Core/configure.ac +694 -0
  28. data/ProjectTox-Core/dist-build/android-arm.sh +3 -0
  29. data/ProjectTox-Core/dist-build/android-armv7.sh +3 -0
  30. data/ProjectTox-Core/dist-build/android-build.sh +59 -0
  31. data/ProjectTox-Core/dist-build/android-mips.sh +3 -0
  32. data/ProjectTox-Core/dist-build/android-x86.sh +3 -0
  33. data/ProjectTox-Core/docs/Group-Chats.md +71 -0
  34. data/ProjectTox-Core/docs/Hardening.txt +60 -0
  35. data/ProjectTox-Core/docs/Hardening_docs.txt +30 -0
  36. data/ProjectTox-Core/docs/Prevent_Tracking.txt +160 -0
  37. data/ProjectTox-Core/docs/TCP_Network.txt +154 -0
  38. data/ProjectTox-Core/docs/TODO +62 -0
  39. data/ProjectTox-Core/docs/Tox_middle_level_network_protocol.txt +120 -0
  40. data/ProjectTox-Core/docs/av_api.md +194 -0
  41. data/ProjectTox-Core/libtoxav.pc.in +11 -0
  42. data/ProjectTox-Core/libtoxcore.pc.in +11 -0
  43. data/ProjectTox-Core/m4/ax_have_epoll.m4 +104 -0
  44. data/ProjectTox-Core/m4/ax_pthread.m4 +317 -0
  45. data/ProjectTox-Core/m4/pkg.m4 +199 -0
  46. data/ProjectTox-Core/other/DHT_bootstrap.c +121 -58
  47. data/ProjectTox-Core/other/DHTnodes +3 -0
  48. data/ProjectTox-Core/other/Makefile.inc +20 -0
  49. data/ProjectTox-Core/other/bootstrap_node_packets.c +65 -0
  50. data/ProjectTox-Core/other/tox.png +0 -0
  51. data/ProjectTox-Core/testing/DHT_test.c +170 -98
  52. data/ProjectTox-Core/testing/Makefile.inc +112 -0
  53. data/ProjectTox-Core/testing/Messenger_test.c +133 -69
  54. data/ProjectTox-Core/testing/dns3_test.c +115 -0
  55. data/ProjectTox-Core/testing/misc_tools.c +59 -13
  56. data/ProjectTox-Core/testing/nTox.c +1127 -264
  57. data/ProjectTox-Core/testing/nTox.h +10 -19
  58. data/ProjectTox-Core/testing/tox_shell.c +159 -0
  59. data/ProjectTox-Core/testing/tox_sync.c +299 -0
  60. data/ProjectTox-Core/tools/README +11 -0
  61. data/ProjectTox-Core/tools/astylerc +11 -0
  62. data/ProjectTox-Core/tools/pre-commit +17 -0
  63. data/ProjectTox-Core/toxav/Makefile.inc +36 -0
  64. data/ProjectTox-Core/toxav/codec.c +357 -0
  65. data/ProjectTox-Core/toxav/codec.h +116 -0
  66. data/ProjectTox-Core/toxav/msi.c +1949 -0
  67. data/ProjectTox-Core/toxav/msi.h +267 -0
  68. data/ProjectTox-Core/toxav/rtp.c +600 -0
  69. data/ProjectTox-Core/toxav/rtp.h +196 -0
  70. data/ProjectTox-Core/toxav/toxav.c +1148 -0
  71. data/ProjectTox-Core/toxav/toxav.h +389 -0
  72. data/ProjectTox-Core/toxcore/DHT.c +2521 -0
  73. data/ProjectTox-Core/toxcore/DHT.h +412 -0
  74. data/ProjectTox-Core/toxcore/LAN_discovery.c +322 -0
  75. data/ProjectTox-Core/{core → toxcore}/LAN_discovery.h +17 -12
  76. data/ProjectTox-Core/toxcore/Makefile.inc +67 -0
  77. data/ProjectTox-Core/toxcore/Messenger.c +3006 -0
  78. data/ProjectTox-Core/toxcore/Messenger.h +818 -0
  79. data/ProjectTox-Core/toxcore/TCP_client.c +858 -0
  80. data/ProjectTox-Core/toxcore/TCP_client.h +156 -0
  81. data/ProjectTox-Core/toxcore/TCP_server.c +1332 -0
  82. data/ProjectTox-Core/toxcore/TCP_server.h +181 -0
  83. data/ProjectTox-Core/toxcore/assoc.c +1033 -0
  84. data/ProjectTox-Core/toxcore/assoc.h +104 -0
  85. data/ProjectTox-Core/toxcore/crypto_core.c +278 -0
  86. data/ProjectTox-Core/toxcore/crypto_core.h +151 -0
  87. data/ProjectTox-Core/toxcore/friend_requests.c +175 -0
  88. data/ProjectTox-Core/toxcore/friend_requests.h +83 -0
  89. data/ProjectTox-Core/toxcore/group_chats.c +837 -0
  90. data/ProjectTox-Core/toxcore/group_chats.h +199 -0
  91. data/ProjectTox-Core/toxcore/list.c +256 -0
  92. data/ProjectTox-Core/toxcore/list.h +85 -0
  93. data/ProjectTox-Core/toxcore/logger.c +153 -0
  94. data/ProjectTox-Core/toxcore/logger.h +84 -0
  95. data/ProjectTox-Core/toxcore/misc_tools.h +70 -0
  96. data/ProjectTox-Core/toxcore/net_crypto.c +2753 -0
  97. data/ProjectTox-Core/toxcore/net_crypto.h +410 -0
  98. data/ProjectTox-Core/toxcore/network.c +979 -0
  99. data/ProjectTox-Core/toxcore/network.h +367 -0
  100. data/ProjectTox-Core/toxcore/onion.c +540 -0
  101. data/ProjectTox-Core/toxcore/onion.h +150 -0
  102. data/ProjectTox-Core/toxcore/onion_announce.c +433 -0
  103. data/ProjectTox-Core/toxcore/onion_announce.h +139 -0
  104. data/ProjectTox-Core/toxcore/onion_client.c +1347 -0
  105. data/ProjectTox-Core/toxcore/onion_client.h +253 -0
  106. data/ProjectTox-Core/toxcore/ping.c +346 -0
  107. data/ProjectTox-Core/toxcore/ping.h +47 -0
  108. data/ProjectTox-Core/toxcore/ping_array.c +162 -0
  109. data/ProjectTox-Core/toxcore/ping_array.h +75 -0
  110. data/ProjectTox-Core/toxcore/tox.c +940 -0
  111. data/ProjectTox-Core/toxcore/tox.h +734 -0
  112. data/ProjectTox-Core/toxcore/util.c +193 -0
  113. data/ProjectTox-Core/toxcore/util.h +63 -0
  114. data/ProjectTox-Core/toxdns/Makefile.inc +29 -0
  115. data/ProjectTox-Core/toxdns/toxdns.c +238 -0
  116. data/ProjectTox-Core/toxdns/toxdns.h +88 -0
  117. data/ProjectTox-Core/toxencryptsave/Makefile.inc +45 -0
  118. data/ProjectTox-Core/toxencryptsave/toxencryptsave.c +179 -0
  119. data/ProjectTox-Core/toxencryptsave/toxencryptsave.h +74 -0
  120. data/interfaces/libtox.i +2 -6
  121. data/lib/ffi-tox/libtox.rb +406 -28
  122. metadata +124 -46
  123. data/ProjectTox-Core/CMakeLists.txt +0 -50
  124. data/ProjectTox-Core/cmake/FindLIBCONFIG.cmake +0 -15
  125. data/ProjectTox-Core/cmake/FindNaCl.cmake +0 -17
  126. data/ProjectTox-Core/cmake/FindSODIUM.cmake +0 -15
  127. data/ProjectTox-Core/core/CMakeLists.txt +0 -19
  128. data/ProjectTox-Core/core/DHT.c +0 -1104
  129. data/ProjectTox-Core/core/DHT.h +0 -111
  130. data/ProjectTox-Core/core/LAN_discovery.c +0 -79
  131. data/ProjectTox-Core/core/Lossless_UDP.c +0 -755
  132. data/ProjectTox-Core/core/Lossless_UDP.h +0 -106
  133. data/ProjectTox-Core/core/Messenger.c +0 -596
  134. data/ProjectTox-Core/core/Messenger.h +0 -165
  135. data/ProjectTox-Core/core/friend_requests.c +0 -131
  136. data/ProjectTox-Core/core/friend_requests.h +0 -51
  137. data/ProjectTox-Core/core/net_crypto.c +0 -575
  138. data/ProjectTox-Core/core/net_crypto.h +0 -134
  139. data/ProjectTox-Core/core/network.c +0 -205
  140. data/ProjectTox-Core/core/network.h +0 -134
  141. data/ProjectTox-Core/docs/commands.md +0 -25
  142. data/ProjectTox-Core/docs/start_guide.de.md +0 -40
  143. data/ProjectTox-Core/docs/start_guide.md +0 -38
  144. data/ProjectTox-Core/other/CMakeLists.txt +0 -9
  145. data/ProjectTox-Core/testing/CMakeLists.txt +0 -18
  146. data/ProjectTox-Core/testing/DHT_cryptosendfiletest.c +0 -228
  147. data/ProjectTox-Core/testing/DHT_sendfiletest.c +0 -176
  148. data/ProjectTox-Core/testing/Lossless_UDP_testclient.c +0 -214
  149. data/ProjectTox-Core/testing/Lossless_UDP_testserver.c +0 -201
  150. data/ProjectTox-Core/testing/misc_tools.h +0 -29
  151. data/ProjectTox-Core/testing/nTox_win32.c +0 -387
  152. data/ProjectTox-Core/testing/nTox_win32.h +0 -40
  153. data/ProjectTox-Core/testing/rect.py +0 -45
@@ -0,0 +1,597 @@
1
+ #ifdef HAVE_CONFIG_H
2
+ #include "config.h"
3
+ #endif
4
+
5
+ #include <sys/types.h>
6
+ #include <stdint.h>
7
+ #include <string.h>
8
+ #include <stdio.h>
9
+ #include <check.h>
10
+ #include <stdlib.h>
11
+ #include <time.h>
12
+ #include <assert.h>
13
+
14
+ #include "../toxcore/tox.h"
15
+ #include "../toxcore/logger.h"
16
+ #include "../toxcore/crypto_core.h"
17
+ #include "../toxav/toxav.h"
18
+
19
+ #include "helpers.h"
20
+
21
+ #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
22
+ #define c_sleep(x) Sleep(1*x)
23
+ #else
24
+ #include <unistd.h>
25
+ #define c_sleep(x) usleep(1000*x)
26
+ #endif
27
+
28
+
29
+
30
+ typedef enum _CallStatus {
31
+ none,
32
+ InCall,
33
+ Ringing,
34
+ Ended,
35
+ Rejected,
36
+ Cancel,
37
+ TimedOut
38
+
39
+ } CallStatus;
40
+
41
+ typedef struct _Party {
42
+ CallStatus status;
43
+ ToxAv *av;
44
+ time_t *CallStarted;
45
+ int call_index;
46
+ } Party;
47
+
48
+ typedef struct _Status {
49
+ Party Alice;
50
+ Party Bob;
51
+ } Status;
52
+
53
+ /* My default settings */
54
+ static ToxAvCSettings muhcaps;
55
+
56
+ void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata)
57
+ {
58
+ if (length == 7 && memcmp("gentoo", data, 7) == 0) {
59
+ tox_add_friend_norequest(m, public_key);
60
+ }
61
+ }
62
+
63
+
64
+ /******************************************************************************/
65
+ void callback_recv_invite ( void *av, int32_t call_index, void *_arg )
66
+ {
67
+ Status *cast = _arg;
68
+
69
+ /* Bob always receives invite */
70
+ cast->Bob.status = Ringing;
71
+ cast->Bob.call_index = call_index;
72
+ }
73
+ void callback_recv_ringing ( void *av, int32_t call_index, void *_arg )
74
+ {
75
+ Status *cast = _arg;
76
+
77
+ /* Alice always sends invite */
78
+ cast->Alice.status = Ringing;
79
+ }
80
+ void callback_recv_starting ( void *av, int32_t call_index, void *_arg )
81
+ {
82
+ Status *cast = _arg;
83
+
84
+ /* Alice always sends invite */
85
+ printf("Call started on Alice side...\n");
86
+ cast->Alice.status = InCall;
87
+ toxav_prepare_transmission(av, call_index, av_jbufdc, av_VADd, 1);
88
+ }
89
+ void callback_recv_ending ( void *av, int32_t call_index, void *_arg )
90
+ {
91
+ Status *cast = _arg;
92
+
93
+ if ( cast->Alice.status == Rejected) {
94
+ printf ( "Call ended for Bob!\n" );
95
+ cast->Bob.status = Ended;
96
+ } else {
97
+ printf ( "Call ended for Alice!\n" );
98
+ cast->Alice.status = Ended;
99
+ }
100
+ }
101
+
102
+
103
+ void callback_call_started ( void *av, int32_t call_index, void *_arg )
104
+ {
105
+ Status *cast = _arg;
106
+
107
+ /* Alice always sends invite */
108
+ printf("Call started on Bob side...\n");
109
+ cast->Bob.status = InCall;
110
+ toxav_prepare_transmission(av, call_index, av_jbufdc, av_VADd, 1);
111
+ }
112
+ void callback_call_canceled ( void *av, int32_t call_index, void *_arg )
113
+ {
114
+ Status *cast = _arg;
115
+
116
+ printf ( "Call Canceled for Bob!\n" );
117
+ cast->Bob.status = Cancel;
118
+ }
119
+ void callback_call_rejected ( void *av, int32_t call_index, void *_arg )
120
+ {
121
+ Status *cast = _arg;
122
+
123
+ printf ( "Call rejected by Bob!\n"
124
+ "Call ended for Alice!\n" );
125
+ /* If Bob rejects, call is ended for alice and she sends ending */
126
+ cast->Alice.status = Rejected;
127
+ }
128
+ void callback_call_ended ( void *av, int32_t call_index, void *_arg )
129
+ {
130
+ Status *cast = _arg;
131
+
132
+ printf ( "Call ended for Bob!\n" );
133
+ cast->Bob.status = Ended;
134
+ }
135
+
136
+ void callback_call_type_change ( void *av, int32_t call_index, void *_arg )
137
+ {
138
+ ToxAvCSettings csettings;
139
+ toxav_get_peer_csettings(av, call_index, 0, &csettings);
140
+
141
+ printf("New settings: \n"
142
+ "Type: %u \n"
143
+ "Video bitrate: %u \n"
144
+ "Video height: %u \n"
145
+ "Video width: %u \n"
146
+ "Audio bitrate: %u \n"
147
+ "Audio framedur: %u \n"
148
+ "Audio sample rate: %u \n"
149
+ "Audio channels: %u \n",
150
+ csettings.call_type,
151
+ csettings.video_bitrate,
152
+ csettings.max_video_height,
153
+ csettings.max_video_width,
154
+ csettings.audio_bitrate,
155
+ csettings.audio_frame_duration,
156
+ csettings.audio_sample_rate,
157
+ csettings.audio_channels
158
+ );
159
+ }
160
+
161
+ void callback_requ_timeout ( void *av, int32_t call_index, void *_arg )
162
+ {
163
+ Status *cast = _arg;
164
+ printf("Call timed-out!\n");
165
+ cast->Alice.status = TimedOut;
166
+ }
167
+
168
+ static void callback_audio(ToxAv *av, int32_t call_index, int16_t *data, int length, void *userdata)
169
+ {
170
+ }
171
+
172
+ static void callback_video(ToxAv *av, int32_t call_index, vpx_image_t *img, void *userdata)
173
+ {
174
+ }
175
+
176
+ void register_callbacks(ToxAv *av, void *data)
177
+ {
178
+ toxav_register_callstate_callback(av, callback_call_started, av_OnStart, data);
179
+ toxav_register_callstate_callback(av, callback_call_canceled, av_OnCancel, data);
180
+ toxav_register_callstate_callback(av, callback_call_rejected, av_OnReject, data);
181
+ toxav_register_callstate_callback(av, callback_call_ended, av_OnEnd, data);
182
+ toxav_register_callstate_callback(av, callback_recv_invite, av_OnInvite, data);
183
+
184
+ toxav_register_callstate_callback(av, callback_recv_ringing, av_OnRinging, data);
185
+ toxav_register_callstate_callback(av, callback_recv_starting, av_OnStarting, data);
186
+ toxav_register_callstate_callback(av, callback_recv_ending, av_OnEnding, data);
187
+
188
+ toxav_register_callstate_callback(av, callback_requ_timeout, av_OnRequestTimeout, data);
189
+ toxav_register_callstate_callback(av, callback_call_type_change, av_OnMediaChange, data);
190
+
191
+
192
+ toxav_register_audio_recv_callback(av, callback_audio, NULL);
193
+ toxav_register_video_recv_callback(av, callback_video, NULL);
194
+ }
195
+
196
+
197
+ /*************************************************************************************************/
198
+
199
+ /* Alice calls bob and the call starts.
200
+ * What happens during the call is defined after. To quit the loop use: step++;
201
+ */
202
+ #define CALL_AND_START_LOOP(AliceCallType, BobCallType) \
203
+ { int step = 0, running = 1; while (running) {\
204
+ tox_do(bootstrap_node); tox_do(Alice); tox_do(Bob); \
205
+ switch ( step ) {\
206
+ case 0: /* Alice */ printf("Alice is calling...\n");\
207
+ toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, &muhcaps, 10); step++; break;\
208
+ case 1: /* Bob */ if (status_control.Bob.status == Ringing) { printf("Bob answers...\n");\
209
+ cur_time = time(NULL); toxav_answer(status_control.Bob.av, status_control.Bob.call_index, &muhcaps); step++; } break; \
210
+ case 2: /* Rtp transmission */ \
211
+ if (status_control.Bob.status == InCall && status_control.Alice.status == InCall)
212
+
213
+
214
+ #define TERMINATE_SCOPE() break;\
215
+ case 3: /* Wait for Both to have status ended */\
216
+ if (status_control.Alice.status == Ended && status_control.Bob.status == Ended) running = 0; break; } c_sleep(20); } } printf("\n");
217
+
218
+ START_TEST(test_AV_flows)
219
+ {
220
+ long long unsigned int cur_time = time(NULL);
221
+ Tox *bootstrap_node = tox_new(0);
222
+ Tox *Alice = tox_new(0);
223
+ Tox *Bob = tox_new(0);
224
+
225
+ ck_assert_msg(bootstrap_node || Alice || Bob, "Failed to create 3 tox instances");
226
+
227
+ uint32_t to_compare = 974536;
228
+ tox_callback_friend_request(Alice, accept_friend_request, &to_compare);
229
+ uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
230
+ tox_get_address(Alice, address);
231
+ int test = tox_add_friend(Bob, address, (uint8_t *)"gentoo", 7);
232
+
233
+ ck_assert_msg(test == 0, "Failed to add friend error code: %i", test);
234
+
235
+ uint8_t off = 1;
236
+
237
+ while (1) {
238
+ tox_do(bootstrap_node);
239
+ tox_do(Alice);
240
+ tox_do(Bob);
241
+
242
+ if (tox_isconnected(bootstrap_node) && tox_isconnected(Alice) && tox_isconnected(Bob) && off) {
243
+ printf("Toxes are online, took %llu seconds\n", time(NULL) - cur_time);
244
+ off = 0;
245
+ }
246
+
247
+ if (tox_get_friend_connection_status(Alice, 0) == 1 && tox_get_friend_connection_status(Bob, 0) == 1)
248
+ break;
249
+
250
+ c_sleep(20);
251
+ }
252
+
253
+ printf("All set after %llu seconds! Starting call...\n", time(NULL) - cur_time);
254
+
255
+ muhcaps = av_DefaultSettings;
256
+ muhcaps.max_video_height = muhcaps.max_video_width = 128;
257
+
258
+ Status status_control = {
259
+ {none, toxav_new(Alice, 1), NULL, -1},
260
+ {none, toxav_new(Bob, 1), NULL, -1},
261
+ };
262
+
263
+ ck_assert_msg(status_control.Alice.av || status_control.Bob.av, "Failed to create 2 toxav instances");
264
+
265
+
266
+ register_callbacks(status_control.Alice.av, &status_control);
267
+ register_callbacks(status_control.Bob.av, &status_control);
268
+
269
+ const int frame_size = (av_DefaultSettings.audio_sample_rate * av_DefaultSettings.audio_frame_duration / 1000);
270
+ int16_t sample_payload[frame_size];
271
+ randombytes((uint8_t *)sample_payload, sizeof(int16_t) * frame_size);
272
+
273
+ uint8_t prepared_payload[RTP_PAYLOAD_SIZE];
274
+ int payload_size;
275
+
276
+ vpx_image_t *sample_image = vpx_img_alloc(NULL, VPX_IMG_FMT_I420, 128, 128, 1);
277
+
278
+ memcpy(sample_image->planes[VPX_PLANE_Y], sample_payload, 10);
279
+ memcpy(sample_image->planes[VPX_PLANE_U], sample_payload, 10);
280
+ memcpy(sample_image->planes[VPX_PLANE_V], sample_payload, 10);
281
+
282
+
283
+ /*************************************************************************************************
284
+ * Successful flows (when call starts)
285
+ */
286
+
287
+ /*
288
+ * Call with audio only on both sides. Alice calls Bob.
289
+ */
290
+
291
+
292
+ CALL_AND_START_LOOP(TypeAudio, TypeAudio) {
293
+ /* Both send */
294
+ payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload,
295
+ 1000, sample_payload, frame_size);
296
+
297
+ if ( payload_size < 0 ) {
298
+ ck_assert_msg ( 0, "Failed to encode payload" );
299
+ }
300
+
301
+ toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size);
302
+
303
+ payload_size = toxav_prepare_audio_frame(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, 1000,
304
+ sample_payload, frame_size);
305
+
306
+ if ( payload_size < 0 ) {
307
+ ck_assert_msg ( 0, "Failed to encode payload" );
308
+ }
309
+
310
+ toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size);
311
+
312
+ if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */
313
+ step++; /* This terminates the loop */
314
+ toxav_kill_transmission(status_control.Alice.av, status_control.Alice.call_index);
315
+ toxav_kill_transmission(status_control.Bob.av, status_control.Bob.call_index);
316
+
317
+ /* Call over Alice hangs up */
318
+ toxav_hangup(status_control.Alice.av, status_control.Alice.call_index);
319
+ }
320
+ }
321
+ TERMINATE_SCOPE()
322
+
323
+
324
+ /*
325
+ * Call with audio on both sides and video on one side. Alice calls Bob.
326
+ */
327
+ CALL_AND_START_LOOP(TypeAudio, TypeVideo) {
328
+ /* Both send */
329
+ payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload,
330
+ 1000, sample_payload, frame_size);
331
+
332
+ if ( payload_size < 0 ) {
333
+ ck_assert_msg ( 0, "Failed to encode payload" );
334
+ }
335
+
336
+ toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size);
337
+
338
+ payload_size = toxav_prepare_audio_frame(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, 1000,
339
+ sample_payload, frame_size);
340
+
341
+ if ( payload_size < 0 ) {
342
+ ck_assert_msg ( 0, "Failed to encode payload" );
343
+ }
344
+
345
+ toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size);
346
+
347
+ // toxav_send_video(status_control.Bob.av, status_control.Bob.call_index, sample_image);
348
+
349
+ if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */
350
+ step++; /* This terminates the loop */
351
+ toxav_kill_transmission(status_control.Alice.av, status_control.Alice.call_index);
352
+ toxav_kill_transmission(status_control.Bob.av, status_control.Bob.call_index);
353
+
354
+ /* Call over Alice hangs up */
355
+ toxav_hangup(status_control.Alice.av, status_control.Alice.call_index);
356
+ }
357
+ }
358
+ TERMINATE_SCOPE()
359
+
360
+
361
+ /*
362
+ * Call with audio and video on both sides. Alice calls Bob.
363
+ */
364
+ CALL_AND_START_LOOP(TypeVideo, TypeVideo) {
365
+ /* Both send */
366
+
367
+ payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload,
368
+ 1000, sample_payload, frame_size);
369
+
370
+ if ( payload_size < 0 ) {
371
+ ck_assert_msg ( 0, "Failed to encode payload" );
372
+ }
373
+
374
+ toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size);
375
+
376
+ payload_size = toxav_prepare_audio_frame(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, 1000,
377
+ sample_payload, frame_size);
378
+
379
+ if ( payload_size < 0 ) {
380
+ ck_assert_msg ( 0, "Failed to encode payload" );
381
+ }
382
+
383
+ toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size);
384
+
385
+ // toxav_send_video(status_control.Alice.av, status_control.Alice.call_index, sample_image);
386
+ // toxav_send_video(status_control.Bob.av, status_control.Bob.call_index, sample_image);
387
+
388
+
389
+ if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */
390
+ step++; /* This terminates the loop */
391
+ toxav_kill_transmission(status_control.Alice.av, status_control.Alice.call_index);
392
+ toxav_kill_transmission(status_control.Bob.av, status_control.Bob.call_index);
393
+
394
+ /* Call over Alice hangs up */
395
+ toxav_hangup(status_control.Alice.av, status_control.Alice.call_index);
396
+ }
397
+ }
398
+ TERMINATE_SCOPE()
399
+
400
+
401
+ uint64_t times_they_are_a_changin = time(NULL);
402
+ /* Media change */
403
+ CALL_AND_START_LOOP(TypeAudio, TypeAudio) {
404
+ /* Both send */
405
+ payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload,
406
+ 1000, sample_payload, frame_size);
407
+
408
+ if ( payload_size < 0 ) {
409
+ ck_assert_msg ( 0, "Failed to encode payload" );
410
+ }
411
+
412
+ toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size);
413
+
414
+ payload_size = toxav_prepare_audio_frame(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, 1000,
415
+ sample_payload, frame_size);
416
+
417
+ if ( payload_size < 0 ) {
418
+ ck_assert_msg ( 0, "Failed to encode payload" );
419
+ }
420
+
421
+ toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size);
422
+
423
+ /* Wait 2 seconds and change transmission type */
424
+ if (time(NULL) - times_they_are_a_changin > 2) {
425
+ times_they_are_a_changin = time(NULL);
426
+ muhcaps.audio_bitrate ++;
427
+ toxav_change_settings(status_control.Alice.av, status_control.Alice.call_index, &muhcaps);
428
+ }
429
+
430
+ if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */
431
+ step++; /* This terminates the loop */
432
+ toxav_kill_transmission(status_control.Alice.av, status_control.Alice.call_index);
433
+ toxav_kill_transmission(status_control.Bob.av, status_control.Bob.call_index);
434
+
435
+ /* Call over Alice hangs up */
436
+ toxav_hangup(status_control.Alice.av, status_control.Alice.call_index);
437
+ }
438
+ }
439
+ TERMINATE_SCOPE()
440
+
441
+
442
+ /*************************************************************************************************
443
+ * Other flows
444
+ */
445
+
446
+ /*
447
+ * Call and reject
448
+ */
449
+ {
450
+ int step = 0;
451
+ int running = 1;
452
+
453
+ while (running) {
454
+ tox_do(bootstrap_node);
455
+ tox_do(Alice);
456
+ tox_do(Bob);
457
+
458
+ switch ( step ) {
459
+ case 0: /* Alice */
460
+ printf("Alice is calling...\n");
461
+ toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, &muhcaps, 10);
462
+ step++;
463
+ break;
464
+
465
+ case 1: /* Bob */
466
+ if (status_control.Bob.status == Ringing) {
467
+ printf("Bob rejects...\n");
468
+ toxav_reject(status_control.Bob.av, status_control.Bob.call_index, "Who likes D's anyway?");
469
+ step++;
470
+ }
471
+
472
+ break;
473
+
474
+ case 2: /* Wait for Both to have status ended */
475
+ if (status_control.Alice.status == Rejected && status_control.Bob.status == Ended) running = 0;
476
+
477
+ break;
478
+ }
479
+
480
+ c_sleep(20);
481
+ }
482
+
483
+ printf("\n");
484
+ }
485
+
486
+
487
+ /*
488
+ * Call and cancel
489
+ */
490
+ {
491
+ int step = 0;
492
+ int running = 1;
493
+
494
+ while (running) {
495
+ tox_do(bootstrap_node);
496
+ tox_do(Alice);
497
+ tox_do(Bob);
498
+
499
+ switch ( step ) {
500
+ case 0: /* Alice */
501
+ printf("Alice is calling...\n");
502
+ toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, &muhcaps, 10);
503
+ step++;
504
+ break;
505
+
506
+
507
+ case 1: /* Alice again */
508
+ if (status_control.Bob.status == Ringing) {
509
+ printf("Alice cancels...\n");
510
+ toxav_cancel(status_control.Alice.av, status_control.Alice.call_index, 0, "Who likes D's anyway?");
511
+ step++;
512
+ }
513
+
514
+ break;
515
+
516
+ case 2: /* Wait for Both to have status ended */
517
+ if (status_control.Bob.status == Cancel) running = 0;
518
+
519
+ break;
520
+ }
521
+
522
+ c_sleep(20);
523
+ }
524
+
525
+ printf("\n");
526
+ }
527
+
528
+ /*
529
+ * Timeout
530
+ */
531
+ {
532
+ int step = 0;
533
+ int running = 1;
534
+
535
+ while (running) {
536
+ tox_do(bootstrap_node);
537
+ tox_do(Alice);
538
+ tox_do(Bob);
539
+
540
+ switch ( step ) {
541
+ case 0:
542
+ printf("Alice is calling...\n");
543
+ toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, &muhcaps, 10);
544
+ step++;
545
+ break;
546
+
547
+ case 1:
548
+ if (status_control.Alice.status == TimedOut) running = 0;
549
+
550
+ break;
551
+ }
552
+
553
+ c_sleep(20);
554
+ }
555
+
556
+ printf("\n");
557
+ }
558
+
559
+
560
+
561
+
562
+ printf("Calls ended!\n");
563
+ }
564
+ END_TEST
565
+
566
+ /*************************************************************************************************/
567
+
568
+
569
+ /*************************************************************************************************/
570
+
571
+ /*************************************************************************************************/
572
+
573
+
574
+ Suite *tox_suite(void)
575
+ {
576
+ Suite *s = suite_create("ToxAV");
577
+
578
+ DEFTESTCASE_SLOW(AV_flows, 200);
579
+
580
+ return s;
581
+ }
582
+ int main(int argc, char *argv[])
583
+ {
584
+ Suite *tox = tox_suite();
585
+ SRunner *test_runner = srunner_create(tox);
586
+
587
+ setbuf(stdout, NULL);
588
+
589
+ srunner_run_all(test_runner, CK_NORMAL);
590
+ int number_failed = srunner_ntests_failed(test_runner);
591
+
592
+ srunner_free(test_runner);
593
+
594
+ return number_failed;
595
+
596
+ // return test_AV_flows();
597
+ }