summaryrefslogtreecommitdiff
path: root/toxav
diff options
context:
space:
mode:
authormannol <eniz_vukovic@hotmail.com>2014-05-20 00:10:40 +0200
committermannol <eniz_vukovic@hotmail.com>2014-05-20 00:10:40 +0200
commita1f2a18ae4146ebea11fbd3f83df803b715813da (patch)
tree63b29cf3770a65e94e3e5d0fcd53b33f2a654585 /toxav
parentea96c1758ae42c59978c450f9e11496a55d49ee5 (diff)
Merge upstream and other stuff
Diffstat (limited to 'toxav')
-rw-r--r--toxav/Makefile.inc3
-rw-r--r--toxav/event.c7
-rw-r--r--toxav/media.h2
-rwxr-xr-xtoxav/msi.c22
-rwxr-xr-xtoxav/msi.h6
-rwxr-xr-xtoxav/rtp.c45
6 files changed, 44 insertions, 41 deletions
diff --git a/toxav/Makefile.inc b/toxav/Makefile.inc
index 060a760c..2d48d210 100644
--- a/toxav/Makefile.inc
+++ b/toxav/Makefile.inc
@@ -18,15 +18,18 @@ libtoxav_la_SOURCES = ../toxav/event.h \
18 18
19libtoxav_la_CFLAGS = -I../toxcore \ 19libtoxav_la_CFLAGS = -I../toxcore \
20 -I../toxav \ 20 -I../toxav \
21 $(LIBSODIUM_CFLAGS) \
21 $(NACL_CFLAGS) \ 22 $(NACL_CFLAGS) \
22 $(AV_CFLAGS) \ 23 $(AV_CFLAGS) \
23 $(PTHREAD_CFLAGS) 24 $(PTHREAD_CFLAGS)
24 25
25libtoxav_la_LDFLAGS = $(TOXAV_LT_LDFLAGS) \ 26libtoxav_la_LDFLAGS = $(TOXAV_LT_LDFLAGS) \
27 $(LIBSODIUM_LDFLAGS) \
26 $(NACL_LDFLAGS) \ 28 $(NACL_LDFLAGS) \
27 $(EXTRA_LT_LDFLAGS) 29 $(EXTRA_LT_LDFLAGS)
28 30
29libtoxav_la_LIBADD = libtoxcore.la \ 31libtoxav_la_LIBADD = libtoxcore.la \
32 $(LIBSODIUM_LIBS) \
30 $(NACL_LIBS) \ 33 $(NACL_LIBS) \
31 $(PTHREAD_LIBS) \ 34 $(PTHREAD_LIBS) \
32 $(AV_LIBS) 35 $(AV_LIBS)
diff --git a/toxav/event.c b/toxav/event.c
index ffda35ec..35af98bb 100644
--- a/toxav/event.c
+++ b/toxav/event.c
@@ -27,6 +27,7 @@
27#endif /* HAVE_CONFIG_H */ 27#endif /* HAVE_CONFIG_H */
28 28
29#include <stdlib.h> 29#include <stdlib.h>
30#include "../toxcore/network.h" /* current_time_monotonic() */
30#include "event.h" 31#include "event.h"
31 32
32#define _GNU_SOURCE 33#define _GNU_SOURCE
@@ -199,7 +200,7 @@ void *event_poll( void *arg )
199 200
200 if ( _event_handler->timed_events ) { 201 if ( _event_handler->timed_events ) {
201 202
202 uint32_t _time = ((uint32_t)(current_time() / 1000)); 203 uint32_t _time = ((uint32_t)current_time_monotonic());
203 204
204 if ( _event_handler->timed_events[0].timeout < _time ) { 205 if ( _event_handler->timed_events[0].timeout < _time ) {
205 206
@@ -249,7 +250,7 @@ int throw_timer_event ( void * (func)(void *), void *arg, unsigned timeout)
249 250
250 size_t _counter = event_handler.timed_events_count; 251 size_t _counter = event_handler.timed_events_count;
251 252
252 event_handler.timed_events[_counter - 1].timeout = timeout + ((uint32_t)(current_time() / 1000)); 253 event_handler.timed_events[_counter - 1].timeout = timeout + ((uint32_t)current_time_monotonic());
253 event_handler.timed_events[_counter - 1].id = _unique_id; 254 event_handler.timed_events[_counter - 1].id = _unique_id;
254 ++_unique_id; 255 ++_unique_id;
255 256
@@ -330,7 +331,7 @@ int reset_timer_event ( int id, uint32_t timeout )
330 /* Find it and change */ 331 /* Find it and change */
331 for ( ; _i; _i-- ) { 332 for ( ; _i; _i-- ) {
332 if ( _it->id == id ) { 333 if ( _it->id == id ) {
333 _it->timeout = timeout + ((uint32_t)(current_time() / 1000)); 334 _it->timeout = timeout + ((uint32_t)current_time_monotonic());
334 break; 335 break;
335 } 336 }
336 337
diff --git a/toxav/media.h b/toxav/media.h
index a1193aae..8dc495ed 100644
--- a/toxav/media.h
+++ b/toxav/media.h
@@ -36,7 +36,7 @@
36#define VIDEO_CODEC_ENCODER_INTERFACE (vpx_codec_vp8_cx()) 36#define VIDEO_CODEC_ENCODER_INTERFACE (vpx_codec_vp8_cx())
37 37
38/* Audio encoding/decoding */ 38/* Audio encoding/decoding */
39#include <opus/opus.h> 39#include <opus.h>
40 40
41typedef enum _Capabilities 41typedef enum _Capabilities
42{ 42{
diff --git a/toxav/msi.c b/toxav/msi.c
index c2d50302..aab13471 100755
--- a/toxav/msi.c
+++ b/toxav/msi.c
@@ -28,8 +28,6 @@
28 28
29#include "../toxcore/logger.h" 29#include "../toxcore/logger.h"
30 30
31/*#define _BSD_SOURCE*/
32
33#include "msi.h" 31#include "msi.h"
34#include "event.h" 32#include "event.h"
35 33
@@ -219,7 +217,7 @@ static inline__ const uint8_t *stringify_response ( MSIResponse response )
219 * @param msg Container. 217 * @param msg Container.
220 * @param data The data. 218 * @param data The data.
221 * @return int 219 * @return int
222 * @retval -1 Error occured. 220 * @retval -1 Error occurred.
223 * @retval 0 Success. 221 * @retval 0 Success.
224 */ 222 */
225int parse_raw_data ( MSIMessage *msg, const uint8_t *data, uint16_t length ) 223int parse_raw_data ( MSIMessage *msg, const uint8_t *data, uint16_t length )
@@ -354,7 +352,7 @@ void free_message ( MSIMessage *msg )
354 * @param type Request or response. 352 * @param type Request or response.
355 * @param type_id Type of request/response. 353 * @param type_id Type of request/response.
356 * @return MSIMessage* Created message. 354 * @return MSIMessage* Created message.
357 * @retval NULL Error occured. 355 * @retval NULL Error occurred.
358 */ 356 */
359MSIMessage *msi_new_message ( uint8_t type, const uint8_t *type_id ) 357MSIMessage *msi_new_message ( uint8_t type, const uint8_t *type_id )
360{ 358{
@@ -387,7 +385,7 @@ MSIMessage *msi_new_message ( uint8_t type, const uint8_t *type_id )
387 * 385 *
388 * @param data The data. 386 * @param data The data.
389 * @return MSIMessage* Parsed message. 387 * @return MSIMessage* Parsed message.
390 * @retval NULL Error occured. 388 * @retval NULL Error occurred.
391 */ 389 */
392MSIMessage *parse_message ( const uint8_t *data, uint16_t length ) 390MSIMessage *parse_message ( const uint8_t *data, uint16_t length )
393{ 391{
@@ -495,7 +493,7 @@ uint8_t *append_header_to_string (
495 493
496 *dest = field_byte; /* Set the first byte */ 494 *dest = field_byte; /* Set the first byte */
497 495
498 uint8_t *_getback_byte = dest + 1; /* remeber the byte we were on */ 496 uint8_t *_getback_byte = dest + 1; /* remember the byte we were on */
499 dest += 3; /* swith to 4th byte where field value starts */ 497 dest += 3; /* swith to 4th byte where field value starts */
500 498
501 /* Now set the field value and calculate it's length */ 499 /* Now set the field value and calculate it's length */
@@ -685,7 +683,7 @@ static inline__ const uint8_t *stringify_error_code ( MSICallError error_code )
685 * @param msg The message. 683 * @param msg The message.
686 * @param to Where to. 684 * @param to Where to.
687 * @return int 685 * @return int
688 * @retval -1 Error occured. 686 * @retval -1 Error occurred.
689 * @retval 0 Success. 687 * @retval 0 Success.
690 */ 688 */
691int send_message ( MSISession *session, MSICall* call, MSIMessage *msg, uint32_t to ) 689int send_message ( MSISession *session, MSICall* call, MSIMessage *msg, uint32_t to )
@@ -838,7 +836,7 @@ int handle_error ( MSISession *session, MSICall* call, MSICallError errid, uint3
838 * @param msg The message. 836 * @param msg The message.
839 * @return int 837 * @return int
840 * @retval -1 No error. 838 * @retval -1 No error.
841 * @retval 0 Error occured and response sent. 839 * @retval 0 Error occurred and response sent.
842 */ 840 */
843int has_call_error ( MSISession *session, MSICall* call, MSIMessage *msg ) 841int has_call_error ( MSISession *session, MSICall* call, MSIMessage *msg )
844{ 842{
@@ -951,7 +949,7 @@ MSICall *init_call ( MSISession *session, int peers, int ringing_timeout )
951 * 949 *
952 * @param session Control session. 950 * @param session Control session.
953 * @return int 951 * @return int
954 * @retval -1 Error occured. 952 * @retval -1 Error occurred.
955 * @retval 0 Success. 953 * @retval 0 Success.
956 */ 954 */
957int terminate_call ( MSISession *session, MSICall *call ) 955int terminate_call ( MSISession *session, MSICall *call )
@@ -1031,7 +1029,7 @@ int handle_recv_invite ( MSISession *session, MSICall* call, MSIMessage *msg )
1031 * B calls A. Who has advantage is set bey calculating 1029 * B calls A. Who has advantage is set bey calculating
1032 * 'bigger' Call id and then that call id is being used in 1030 * 'bigger' Call id and then that call id is being used in
1033 * future. User with 'bigger' Call id has the advantage 1031 * future. User with 'bigger' Call id has the advantage
1034 * as in he will wait the reponse from the other. 1032 * as in he will wait the response from the other.
1035 */ 1033 */
1036 1034
1037 if ( call_id_bigger (call->id, msg->callid.header_value) == 1 ) { /* Peer has advantage */ 1035 if ( call_id_bigger (call->id, msg->callid.header_value) == 1 ) { /* Peer has advantage */
@@ -1408,7 +1406,7 @@ void msi_register_callback ( MSICallback callback, MSICallbackID id, void* userd
1408 * @param messenger Tox* object. 1406 * @param messenger Tox* object.
1409 * @param max_calls Amount of calls possible 1407 * @param max_calls Amount of calls possible
1410 * @return MSISession* The created session. 1408 * @return MSISession* The created session.
1411 * @retval NULL Error occured. 1409 * @retval NULL Error occurred.
1412 */ 1410 */
1413MSISession *msi_init_session ( Messenger* messenger, int32_t max_calls ) 1411MSISession *msi_init_session ( Messenger* messenger, int32_t max_calls )
1414{ 1412{
@@ -1530,7 +1528,7 @@ int msi_invite ( MSISession* session, int32_t* call_index, MSICallType call_type
1530 * @param session Control session. 1528 * @param session Control session.
1531 * @param call_id To which call is this action handled. 1529 * @param call_id To which call is this action handled.
1532 * @return int 1530 * @return int
1533 * @retval -1 Error occured. 1531 * @retval -1 Error occurred.
1534 * @retval 0 Success. 1532 * @retval 0 Success.
1535 */ 1533 */
1536int msi_hangup ( MSISession* session, int32_t call_index ) 1534int msi_hangup ( MSISession* session, int32_t call_index )
diff --git a/toxav/msi.h b/toxav/msi.h
index 2a7c5ba8..e9e1b4d7 100755
--- a/toxav/msi.h
+++ b/toxav/msi.h
@@ -84,7 +84,7 @@ typedef struct _MSICall { /* Call info structure */
84 int ringing_timer_id; /* Timer id for ringing timeout */ 84 int ringing_timer_id; /* Timer id for ringing timeout */
85 85
86 pthread_mutex_t mutex; /* It's to be assumed that call will have 86 pthread_mutex_t mutex; /* It's to be assumed that call will have
87 * seperate thread so add mutex 87 * separate thread so add mutex
88 */ 88 */
89 uint32_t *peers; 89 uint32_t *peers;
90 uint16_t peer_count; 90 uint16_t peer_count;
@@ -156,7 +156,7 @@ void msi_register_callback(MSICallback callback, MSICallbackID id, void* userdat
156 * @param messenger Tox* object. 156 * @param messenger Tox* object.
157 * @param max_calls Amount of calls possible 157 * @param max_calls Amount of calls possible
158 * @return MSISession* The created session. 158 * @return MSISession* The created session.
159 * @retval NULL Error occured. 159 * @retval NULL Error occurred.
160 */ 160 */
161MSISession *msi_init_session ( Messenger *messenger, int32_t max_calls ); 161MSISession *msi_init_session ( Messenger *messenger, int32_t max_calls );
162 162
@@ -189,7 +189,7 @@ int msi_invite ( MSISession *session, int32_t* call_index, MSICallType call_type
189 * @param session Control session. 189 * @param session Control session.
190 * @param call_index To which call is this action handled. 190 * @param call_index To which call is this action handled.
191 * @return int 191 * @return int
192 * @retval -1 Error occured. 192 * @retval -1 Error occurred.
193 * @retval 0 Success. 193 * @retval 0 Success.
194 */ 194 */
195int msi_hangup ( MSISession *session, int32_t call_index ); 195int msi_hangup ( MSISession *session, int32_t call_index );
diff --git a/toxav/rtp.c b/toxav/rtp.c
index 8b2768f1..cdaabd3a 100755
--- a/toxav/rtp.c
+++ b/toxav/rtp.c
@@ -170,8 +170,8 @@ inline__ void increase_nonce(uint8_t *nonce, uint16_t target)
170 uint16_t _nonce_counter; 170 uint16_t _nonce_counter;
171 171
172 uint8_t _reverse_bytes[2]; 172 uint8_t _reverse_bytes[2];
173 _reverse_bytes[0] = nonce[crypto_secretbox_NONCEBYTES - 1]; 173 _reverse_bytes[0] = nonce[crypto_box_NONCEBYTES - 1];
174 _reverse_bytes[1] = nonce[crypto_secretbox_NONCEBYTES - 2]; 174 _reverse_bytes[1] = nonce[crypto_box_NONCEBYTES - 2];
175 175
176 bytes_to_U16(&_nonce_counter, _reverse_bytes ); 176 bytes_to_U16(&_nonce_counter, _reverse_bytes );
177 177
@@ -179,8 +179,8 @@ inline__ void increase_nonce(uint8_t *nonce, uint16_t target)
179 if (_nonce_counter > UINT16_MAX - target ) { /* 2 bytes are not long enough */ 179 if (_nonce_counter > UINT16_MAX - target ) { /* 2 bytes are not long enough */
180 uint8_t _it = 3; 180 uint8_t _it = 3;
181 181
182 while ( _it <= crypto_secretbox_NONCEBYTES ) _it += ++nonce[crypto_secretbox_NONCEBYTES - _it] ? 182 while ( _it <= crypto_box_NONCEBYTES ) _it += ++nonce[crypto_box_NONCEBYTES - _it] ?
183 crypto_secretbox_NONCEBYTES : 1; 183 crypto_box_NONCEBYTES : 1;
184 184
185 _nonce_counter = _nonce_counter - (UINT16_MAX - target ); /* Assign the rest of it */ 185 _nonce_counter = _nonce_counter - (UINT16_MAX - target ); /* Assign the rest of it */
186 } else { /* Increase nonce */ 186 } else { /* Increase nonce */
@@ -191,8 +191,8 @@ inline__ void increase_nonce(uint8_t *nonce, uint16_t target)
191 /* Assign the last bytes */ 191 /* Assign the last bytes */
192 192
193 U16_to_bytes( _reverse_bytes, _nonce_counter); 193 U16_to_bytes( _reverse_bytes, _nonce_counter);
194 nonce [crypto_secretbox_NONCEBYTES - 1] = _reverse_bytes[0]; 194 nonce [crypto_box_NONCEBYTES - 1] = _reverse_bytes[0];
195 nonce [crypto_secretbox_NONCEBYTES - 2] = _reverse_bytes[1]; 195 nonce [crypto_box_NONCEBYTES - 2] = _reverse_bytes[1];
196 196
197} 197}
198 198
@@ -416,7 +416,7 @@ RTPHeader *build_header ( RTPSession *session )
416 ADD_SETTING_PAYLOAD ( _retu, session->payload_type ); 416 ADD_SETTING_PAYLOAD ( _retu, session->payload_type );
417 417
418 _retu->sequnum = session->sequnum; 418 _retu->sequnum = session->sequnum;
419 _retu->timestamp = ((uint32_t)(current_time() / 1000)); /* micro to milli */ 419 _retu->timestamp = current_time_monotonic(); /* milliseconds */
420 _retu->ssrc = session->ssrc; 420 _retu->ssrc = session->ssrc;
421 421
422 int i; 422 int i;
@@ -505,7 +505,7 @@ int rtp_handle_packet ( void *object, IP_Port ip_port, uint8_t *data, uint32_t l
505 RTPSession *_session = object; 505 RTPSession *_session = object;
506 RTPMessage *_msg; 506 RTPMessage *_msg;
507 507
508 if ( !_session || length < 13 + crypto_secretbox_MACBYTES) { /* 12 is the minimum length for rtp + desc. byte */ 508 if ( !_session || length < 13 + crypto_box_MACBYTES) { /* 12 is the minimum length for rtp + desc. byte */
509 LOGGER_WARNING("No session or invalid length of received buffer!"); 509 LOGGER_WARNING("No session or invalid length of received buffer!");
510 return -1; 510 return -1;
511 } 511 }
@@ -521,12 +521,13 @@ int rtp_handle_packet ( void *object, IP_Port ip_port, uint8_t *data, uint32_t l
521 bytes_to_U16(&_sequnum, data + 1); 521 bytes_to_U16(&_sequnum, data + 1);
522 522
523 /* Clculate the right nonce */ 523 /* Clculate the right nonce */
524 uint8_t _calculated[crypto_secretbox_NONCEBYTES]; 524 uint8_t _calculated[crypto_box_NONCEBYTES];
525 memcpy(_calculated, _session->decrypt_nonce, crypto_secretbox_NONCEBYTES); 525 memcpy(_calculated, _session->decrypt_nonce, crypto_box_NONCEBYTES);
526 increase_nonce ( _calculated, _sequnum ); 526 increase_nonce ( _calculated, _sequnum );
527 527
528 /* Decrypt message */ 528 /* Decrypt message */
529 int _decrypted_length = decrypt_data_symmetric((uint8_t *)_session->decrypt_key, _calculated, data + 3, length - 3, _plain ); 529 int _decrypted_length = decrypt_data_symmetric(
530 (uint8_t *)_session->decrypt_key, _calculated, data + 3, length - 3, _plain );
530 531
531 /* This packet is either not encrypted properly or late 532 /* This packet is either not encrypted properly or late
532 */ 533 */
@@ -557,8 +558,8 @@ int rtp_handle_packet ( void *object, IP_Port ip_port, uint8_t *data, uint32_t l
557 } 558 }
558 559
559 /* A new cycle setting. */ 560 /* A new cycle setting. */
560 memcpy(_session->nonce_cycle, _session->decrypt_nonce, crypto_secretbox_NONCEBYTES); 561 memcpy(_session->nonce_cycle, _session->decrypt_nonce, crypto_box_NONCEBYTES);
561 memcpy(_session->decrypt_nonce, _calculated, crypto_secretbox_NONCEBYTES); 562 memcpy(_session->decrypt_nonce, _calculated, crypto_box_NONCEBYTES);
562 } 563 }
563 } 564 }
564 565
@@ -774,8 +775,8 @@ int rtp_send_msg ( RTPSession *session, Messenger *messenger, const uint8_t *dat
774 _send_data[0] = session->prefix; 775 _send_data[0] = session->prefix;
775 776
776 /* Generate the right nonce */ 777 /* Generate the right nonce */
777 uint8_t _calculated[crypto_secretbox_NONCEBYTES]; 778 uint8_t _calculated[crypto_box_NONCEBYTES];
778 memcpy(_calculated, session->encrypt_nonce, crypto_secretbox_NONCEBYTES); 779 memcpy(_calculated, session->encrypt_nonce, crypto_box_NONCEBYTES);
779 increase_nonce ( _calculated, msg->header->sequnum ); 780 increase_nonce ( _calculated, msg->header->sequnum );
780 781
781 /* Need to skip 2 bytes that are for sequnum */ 782 /* Need to skip 2 bytes that are for sequnum */
@@ -798,7 +799,7 @@ int rtp_send_msg ( RTPSession *session, Messenger *messenger, const uint8_t *dat
798 /* Set sequ number */ 799 /* Set sequ number */
799 if ( session->sequnum >= MAX_SEQU_NUM ) { 800 if ( session->sequnum >= MAX_SEQU_NUM ) {
800 session->sequnum = 0; 801 session->sequnum = 0;
801 memcpy(session->encrypt_nonce, _calculated, crypto_secretbox_NONCEBYTES); 802 memcpy(session->encrypt_nonce, _calculated, crypto_box_NONCEBYTES);
802 } else { 803 } else {
803 session->sequnum++; 804 session->sequnum++;
804 } 805 }
@@ -888,16 +889,16 @@ RTPSession *rtp_init_session ( int payload_type,
888 _retu->decrypt_key = decrypt_key; 889 _retu->decrypt_key = decrypt_key;
889 890
890 /* Need to allocate new memory */ 891 /* Need to allocate new memory */
891 _retu->encrypt_nonce = calloc ( crypto_secretbox_NONCEBYTES, sizeof (uint8_t) ); 892 _retu->encrypt_nonce = calloc ( crypto_box_NONCEBYTES, sizeof (uint8_t) );
892 assert(_retu->encrypt_nonce); 893 assert(_retu->encrypt_nonce);
893 _retu->decrypt_nonce = calloc ( crypto_secretbox_NONCEBYTES, sizeof (uint8_t) ); 894 _retu->decrypt_nonce = calloc ( crypto_box_NONCEBYTES, sizeof (uint8_t) );
894 assert(_retu->decrypt_nonce); 895 assert(_retu->decrypt_nonce);
895 _retu->nonce_cycle = calloc ( crypto_secretbox_NONCEBYTES, sizeof (uint8_t) ); 896 _retu->nonce_cycle = calloc ( crypto_box_NONCEBYTES, sizeof (uint8_t) );
896 assert(_retu->nonce_cycle); 897 assert(_retu->nonce_cycle);
897 898
898 memcpy(_retu->encrypt_nonce, encrypt_nonce, crypto_secretbox_NONCEBYTES); 899 memcpy(_retu->encrypt_nonce, encrypt_nonce, crypto_box_NONCEBYTES);
899 memcpy(_retu->decrypt_nonce, decrypt_nonce, crypto_secretbox_NONCEBYTES); 900 memcpy(_retu->decrypt_nonce, decrypt_nonce, crypto_box_NONCEBYTES);
900 memcpy(_retu->nonce_cycle , decrypt_nonce, crypto_secretbox_NONCEBYTES); 901 memcpy(_retu->nonce_cycle , decrypt_nonce, crypto_box_NONCEBYTES);
901 902
902 _retu->csrc = calloc(1, sizeof (uint32_t)); 903 _retu->csrc = calloc(1, sizeof (uint32_t));
903 assert(_retu->csrc); 904 assert(_retu->csrc);