summaryrefslogtreecommitdiff
path: root/toxav
diff options
context:
space:
mode:
Diffstat (limited to 'toxav')
-rw-r--r--toxav/av_test.c68
-rw-r--r--toxav/group.c12
-rw-r--r--toxav/msi.c8
-rw-r--r--toxav/rtp.c28
-rw-r--r--toxav/toxav.c2
5 files changed, 70 insertions, 48 deletions
diff --git a/toxav/av_test.c b/toxav/av_test.c
index 507a708e..e24f0a06 100644
--- a/toxav/av_test.c
+++ b/toxav/av_test.c
@@ -211,21 +211,21 @@ void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number,
211 uint32_t sampling_rate, 211 uint32_t sampling_rate,
212 void *user_data) 212 void *user_data)
213{ 213{
214 CallControl* cc = user_data; 214// CallControl* cc = user_data;
215 frame* f = malloc(sizeof(frame) + sample_count * sizeof(int16_t)); 215// frame* f = malloc(sizeof(frame) + sample_count * sizeof(int16_t));
216 memcpy(f->data, pcm, sample_count); 216// memcpy(f->data, pcm, sample_count);
217 f->size = sample_count/channels; 217// f->size = sample_count/channels;
218 218//
219 pthread_mutex_lock(cc->arb_mutex); 219// pthread_mutex_lock(cc->arb_mutex);
220 free(rb_write(cc->arb, f)); 220// free(rb_write(cc->arb, f));
221 pthread_mutex_unlock(cc->arb_mutex); 221// pthread_mutex_unlock(cc->arb_mutex);
222 222
223// Pa_WriteStream(adout, pcm, sample_count/channels); 223 Pa_WriteStream(adout, pcm, sample_count/channels);
224} 224}
225void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata) 225void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata)
226{ 226{
227 if (length == 7 && memcmp("gentoo", data, 7) == 0) { 227 if (length == 7 && memcmp("gentoo", data, 7) == 0) {
228 tox_add_friend_norequest(m, public_key); 228 assert(tox_friend_add_norequest(m, public_key, NULL) != ~0);
229 } 229 }
230} 230}
231 231
@@ -237,11 +237,17 @@ void initialize_tox(Tox** bootstrap, ToxAV** AliceAV, CallControl* AliceCC, ToxA
237 Tox* Alice; 237 Tox* Alice;
238 Tox* Bob; 238 Tox* Bob;
239 239
240 *bootstrap = tox_new(0); 240 {
241 Alice = tox_new(0); 241 TOX_ERR_NEW error;
242 Bob = tox_new(0); 242 *bootstrap = tox_new(NULL, NULL, 0, &error);
243 243 assert(error == TOX_ERR_NEW_OK);
244 assert(bootstrap && Alice && Bob); 244
245 Alice = tox_new(NULL, NULL, 0, &error);
246 assert(error == TOX_ERR_NEW_OK);
247
248 Bob = tox_new(NULL, NULL, 0, &error);
249 assert(error == TOX_ERR_NEW_OK);
250 }
245 251
246 printf("Created 3 instances of Tox\n"); 252 printf("Created 3 instances of Tox\n");
247 253
@@ -249,26 +255,30 @@ void initialize_tox(Tox** bootstrap, ToxAV** AliceAV, CallControl* AliceCC, ToxA
249 long long unsigned int cur_time = time(NULL); 255 long long unsigned int cur_time = time(NULL);
250 256
251 uint32_t to_compare = 974536; 257 uint32_t to_compare = 974536;
252 uint8_t address[TOX_FRIEND_ADDRESS_SIZE]; 258 uint8_t address[TOX_ADDRESS_SIZE];
253 259
254 tox_callback_friend_request(Alice, t_accept_friend_request_cb, &to_compare); 260 tox_callback_friend_request(Alice, t_accept_friend_request_cb, &to_compare);
255 tox_get_address(Alice, address); 261 tox_self_get_address(Alice, address);
262
256 263
257 assert(tox_add_friend(Bob, address, (uint8_t *)"gentoo", 7) >= 0); 264 assert(tox_friend_add(Bob, address, (uint8_t *)"gentoo", 7, NULL) != ~0);
258 265
259 uint8_t off = 1; 266 uint8_t off = 1;
260 267
261 while (1) { 268 while (1) {
262 tox_do(*bootstrap); 269 tox_iterate(*bootstrap);
263 tox_do(Alice); 270 tox_iterate(Alice);
264 tox_do(Bob); 271 tox_iterate(Bob);
265 272
266 if (tox_isconnected(*bootstrap) && tox_isconnected(Alice) && tox_isconnected(Bob) && off) { 273 if (tox_self_get_connection_status(*bootstrap) &&
274 tox_self_get_connection_status(Alice) &&
275 tox_self_get_connection_status(Bob) && off) {
267 printf("Toxes are online, took %llu seconds\n", time(NULL) - cur_time); 276 printf("Toxes are online, took %llu seconds\n", time(NULL) - cur_time);
268 off = 0; 277 off = 0;
269 } 278 }
270 279
271 if (tox_get_friend_connection_status(Alice, 0) == 1 && tox_get_friend_connection_status(Bob, 0) == 1) 280 if (tox_friend_get_connection_status(Alice, 0, NULL) == TOX_CONNECTION_UDP &&
281 tox_friend_get_connection_status(Bob, 0, NULL) == TOX_CONNECTION_UDP)
272 break; 282 break;
273 283
274 c_sleep(20); 284 c_sleep(20);
@@ -300,11 +310,11 @@ void initialize_tox(Tox** bootstrap, ToxAV** AliceAV, CallControl* AliceCC, ToxA
300} 310}
301int iterate_tox(Tox* bootstrap, ToxAV* AliceAV, ToxAV* BobAV) 311int iterate_tox(Tox* bootstrap, ToxAV* AliceAV, ToxAV* BobAV)
302{ 312{
303 tox_do(bootstrap); 313 tox_iterate(bootstrap);
304 tox_do(toxav_get_tox(AliceAV)); 314 tox_iterate(toxav_get_tox(AliceAV));
305 tox_do(toxav_get_tox(BobAV)); 315 tox_iterate(toxav_get_tox(BobAV));
306 316
307 return MIN(tox_do_interval(toxav_get_tox(AliceAV)), tox_do_interval(toxav_get_tox(BobAV))); 317 return MIN(tox_iteration_interval(toxav_get_tox(AliceAV)), tox_iteration_interval(toxav_get_tox(BobAV)));
308} 318}
309void* iterate_toxav (void * data) 319void* iterate_toxav (void * data)
310{ 320{
diff --git a/toxav/group.c b/toxav/group.c
index 3c09878a..817ee6e6 100644
--- a/toxav/group.c
+++ b/toxav/group.c
@@ -23,9 +23,11 @@
23#endif 23#endif
24 24
25#include "group.h" 25#include "group.h"
26#include "../toxcore/util.h"
26#include "../toxcore/logger.h" 27#include "../toxcore/logger.h"
27 28
28#define GROUP_JBUF_SIZE 6 29#define GROUP_JBUF_SIZE 6
30#define GROUP_JBUF_DEAD_SECONDS 4
29 31
30typedef struct { 32typedef struct {
31 uint16_t sequnum; 33 uint16_t sequnum;
@@ -39,6 +41,7 @@ typedef struct {
39 uint32_t capacity; 41 uint32_t capacity;
40 uint16_t bottom; 42 uint16_t bottom;
41 uint16_t top; 43 uint16_t top;
44 uint64_t last_queued_time;
42} Group_JitterBuffer; 45} Group_JitterBuffer;
43 46
44static Group_JitterBuffer *create_queue(unsigned int capacity) 47static Group_JitterBuffer *create_queue(unsigned int capacity)
@@ -90,11 +93,19 @@ static int queue(Group_JitterBuffer *q, Group_Audio_Packet *pk)
90 93
91 unsigned int num = sequnum % q->size; 94 unsigned int num = sequnum % q->size;
92 95
96 if (!is_timeout(q->last_queued_time, GROUP_JBUF_DEAD_SECONDS)) {
97 if ((uint32_t)(sequnum - q->bottom) > (1 << 15)) {
98 /* Drop old packet. */
99 return -1;
100 }
101 }
102
93 if ((uint32_t)(sequnum - q->bottom) > q->size) { 103 if ((uint32_t)(sequnum - q->bottom) > q->size) {
94 clear_queue(q); 104 clear_queue(q);
95 q->bottom = sequnum - q->capacity; 105 q->bottom = sequnum - q->capacity;
96 q->queue[num] = pk; 106 q->queue[num] = pk;
97 q->top = sequnum + 1; 107 q->top = sequnum + 1;
108 q->last_queued_time = unix_time();
98 return 0; 109 return 0;
99 } 110 }
100 111
@@ -106,6 +117,7 @@ static int queue(Group_JitterBuffer *q, Group_Audio_Packet *pk)
106 if ((sequnum - q->bottom) >= (q->top - q->bottom)) 117 if ((sequnum - q->bottom) >= (q->top - q->bottom))
107 q->top = sequnum + 1; 118 q->top = sequnum + 1;
108 119
120 q->last_queued_time = unix_time();
109 return 0; 121 return 0;
110} 122}
111 123
diff --git a/toxav/msi.c b/toxav/msi.c
index 29e053ec..c313e288 100644
--- a/toxav/msi.c
+++ b/toxav/msi.c
@@ -88,10 +88,10 @@ static int invoke_callback(MSICall* call, MSICallbackID cb);
88static MSICall *get_call ( MSISession *session, uint32_t friend_id ); 88static MSICall *get_call ( MSISession *session, uint32_t friend_id );
89MSICall *new_call ( MSISession *session, uint32_t friend_id ); 89MSICall *new_call ( MSISession *session, uint32_t friend_id );
90void kill_call ( MSICall *call ); 90void kill_call ( MSICall *call );
91void on_peer_status(Messenger *m, int friend_id, uint8_t status, void *data); 91void on_peer_status(Messenger *m, uint32_t friend_id, uint8_t status, void *data);
92void handle_push ( MSICall *call, const MSIMessage *msg ); 92void handle_push ( MSICall *call, const MSIMessage *msg );
93void handle_pop ( MSICall *call, const MSIMessage *msg ); 93void handle_pop ( MSICall *call, const MSIMessage *msg );
94void handle_msi_packet ( Messenger *m, int friend_id, const uint8_t *data, uint16_t length, void *object ); 94void handle_msi_packet ( Messenger *m, uint32_t friend_id, const uint8_t *data, uint16_t length, void *object );
95 95
96 96
97/** 97/**
@@ -572,7 +572,7 @@ CLEAR_CONTAINER:
572 free(call); 572 free(call);
573 session->calls = NULL; 573 session->calls = NULL;
574} 574}
575void on_peer_status(Messenger *m, int friend_id, uint8_t status, void *data) 575void on_peer_status(Messenger* m, uint32_t friend_id, uint8_t status, void* data)
576{ 576{
577 (void)m; 577 (void)m;
578 MSISession *session = data; 578 MSISession *session = data;
@@ -744,7 +744,7 @@ void handle_pop ( MSICall *call, const MSIMessage *msg )
744 744
745 kill_call ( call ); 745 kill_call ( call );
746} 746}
747void handle_msi_packet ( Messenger *m, int friend_id, const uint8_t *data, uint16_t length, void *object ) 747void handle_msi_packet ( Messenger* m, uint32_t friend_id, const uint8_t* data, uint16_t length, void* object )
748{ 748{
749 LOGGER_DEBUG("Got msi message"); 749 LOGGER_DEBUG("Got msi message");
750 750
diff --git a/toxav/rtp.c b/toxav/rtp.c
index 665ebf86..e1e6dbac 100644
--- a/toxav/rtp.c
+++ b/toxav/rtp.c
@@ -25,6 +25,7 @@
25 25
26#include "../toxcore/logger.h" 26#include "../toxcore/logger.h"
27#include "../toxcore/util.h" 27#include "../toxcore/util.h"
28#include "../toxcore/Messenger.h"
28 29
29#include "rtp.h" 30#include "rtp.h"
30#include <stdlib.h> 31#include <stdlib.h>
@@ -77,11 +78,9 @@ RTPMessage *msg_parse ( const uint8_t *data, int length );
77uint8_t *parse_header_out ( const RTPHeader* header, uint8_t* payload ); 78uint8_t *parse_header_out ( const RTPHeader* header, uint8_t* payload );
78uint8_t *parse_ext_header_out ( const RTPExtHeader* header, uint8_t* payload ); 79uint8_t *parse_ext_header_out ( const RTPExtHeader* header, uint8_t* payload );
79void build_header ( RTPSession* session, RTPHeader* header ); 80void build_header ( RTPSession* session, RTPHeader* header );
80void send_rtcp_report ( RTCPSession* session, Messenger* m, int32_t friendnumber ); 81void send_rtcp_report ( RTCPSession* session, Messenger* m, uint32_t friendnumber );
81int handle_rtp_packet ( Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length, void *object ); 82int handle_rtp_packet ( Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t length, void *object );
82int handle_rtcp_packet ( Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length, void *object ); 83int handle_rtcp_packet ( Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t length, void *object );
83
84
85 84
86 85
87RTPSession *rtp_new ( int payload_type, Messenger *messenger, int friend_num ) 86RTPSession *rtp_new ( int payload_type, Messenger *messenger, int friend_num )
@@ -121,7 +120,7 @@ RTPSession *rtp_new ( int payload_type, Messenger *messenger, int friend_num )
121 return NULL; 120 return NULL;
122 } 121 }
123 122
124 retu->rtcp_session->prefix = 222 + payload_type % 192; 123 retu->rtcp_session->prefix = payload_type + 2;
125 retu->rtcp_session->pl_stats = rb_new(4); 124 retu->rtcp_session->pl_stats = rb_new(4);
126 retu->rtcp_session->rtp_session = retu; 125 retu->rtcp_session->rtp_session = retu;
127 126
@@ -201,15 +200,15 @@ int rtp_start_receiving(RTPSession* session)
201 if (session == NULL) 200 if (session == NULL)
202 return -1; 201 return -1;
203 202
204 if (custom_lossy_packet_registerhandler(session->m, session->dest, session->prefix, 203 if (m_callback_rtp_packet(session->m, session->dest, session->prefix,
205 handle_rtp_packet, session) == -1) { 204 handle_rtp_packet, session) == -1) {
206 LOGGER_WARNING("Failed to register rtp receive handler"); 205 LOGGER_WARNING("Failed to register rtp receive handler");
207 return -1; 206 return -1;
208 } 207 }
209 if (custom_lossy_packet_registerhandler(session->m, session->dest, session->rtcp_session->prefix, 208 if (m_callback_rtp_packet(session->m, session->dest, session->rtcp_session->prefix,
210 handle_rtcp_packet, session->rtcp_session) == -1) { 209 handle_rtcp_packet, session->rtcp_session) == -1) {
211 LOGGER_WARNING("Failed to register rtcp receive handler"); 210 LOGGER_WARNING("Failed to register rtcp receive handler");
212 custom_lossy_packet_registerhandler(session->m, session->dest, session->prefix, NULL, NULL); 211 m_callback_rtp_packet(session->m, session->dest, session->prefix, NULL, NULL);
213 return -1; 212 return -1;
214 } 213 }
215 214
@@ -220,8 +219,8 @@ int rtp_stop_receiving(RTPSession* session)
220 if (session == NULL) 219 if (session == NULL)
221 return -1; 220 return -1;
222 221
223 custom_lossy_packet_registerhandler(session->m, session->dest, session->prefix, NULL, NULL); 222 m_callback_rtp_packet(session->m, session->dest, session->prefix, NULL, NULL);
224 custom_lossy_packet_registerhandler(session->m, session->dest, session->rtcp_session->prefix, NULL, NULL); /* RTCP */ 223 m_callback_rtp_packet(session->m, session->dest, session->rtcp_session->prefix, NULL, NULL); /* RTCP */
225 224
226 return 0; 225 return 0;
227} 226}
@@ -251,6 +250,7 @@ int rtp_send_msg ( RTPSession *session, const uint8_t *data, uint16_t length )
251 250
252 memcpy ( it, data, length ); 251 memcpy ( it, data, length );
253 252
253
254 if ( -1 == send_custom_lossy_packet(session->m, session->dest, parsed, parsed_len) ) { 254 if ( -1 == send_custom_lossy_packet(session->m, session->dest, parsed, parsed_len) ) {
255 LOGGER_WARNING("Failed to send full packet (len: %d)! std error: %s", length, strerror(errno)); 255 LOGGER_WARNING("Failed to send full packet (len: %d)! std error: %s", length, strerror(errno));
256 return -1; 256 return -1;
@@ -514,7 +514,7 @@ void build_header ( RTPSession *session, RTPHeader *header )
514 514
515 header->length = 12 /* Minimum header len */ + ( session->cc * size_32 ); 515 header->length = 12 /* Minimum header len */ + ( session->cc * size_32 );
516} 516}
517void send_rtcp_report(RTCPSession* session, Messenger* m, int32_t friendnumber) 517void send_rtcp_report(RTCPSession* session, Messenger* m, uint32_t friendnumber)
518{ 518{
519 if (session->last_expected_packets == 0) 519 if (session->last_expected_packets == 0)
520 return; 520 return;
@@ -538,7 +538,7 @@ void send_rtcp_report(RTCPSession* session, Messenger* m, int32_t friendnumber)
538 session->last_sent_report_ts = current_time_monotonic(); 538 session->last_sent_report_ts = current_time_monotonic();
539 } 539 }
540} 540}
541int handle_rtp_packet ( Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length, void *object ) 541int handle_rtp_packet ( Messenger* m, uint32_t friendnumber, const uint8_t* data, uint16_t length, void* object )
542{ 542{
543 RTPSession *session = object; 543 RTPSession *session = object;
544 RTPMessage *msg; 544 RTPMessage *msg;
@@ -574,7 +574,7 @@ int handle_rtp_packet ( Messenger *m, int32_t friendnumber, const uint8_t *data,
574 queue_message(session, msg); 574 queue_message(session, msg);
575 return 0; 575 return 0;
576} 576}
577int handle_rtcp_packet ( Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length, void *object ) 577int handle_rtcp_packet ( Messenger* m, uint32_t friendnumber, const uint8_t* data, uint16_t length, void* object )
578{ 578{
579 if (length < 9) 579 if (length < 9)
580 return -1; 580 return -1;
diff --git a/toxav/toxav.c b/toxav/toxav.c
index dbc06587..2e6326fd 100644
--- a/toxav/toxav.c
+++ b/toxav/toxav.c
@@ -904,7 +904,7 @@ ToxAVCall* call_new(ToxAV* av, uint32_t friend_number, TOXAV_ERR_CALL* error)
904 goto END; 904 goto END;
905 } 905 }
906 906
907 if (m_get_friend_connectionstatus(av->m, friend_number) != 1) { 907 if (m_get_friend_connectionstatus(av->m, friend_number) < 1) {
908 rc = TOXAV_ERR_CALL_FRIEND_NOT_CONNECTED; 908 rc = TOXAV_ERR_CALL_FRIEND_NOT_CONNECTED;
909 goto END; 909 goto END;
910 } 910 }