summaryrefslogtreecommitdiff
path: root/toxrtp
diff options
context:
space:
mode:
Diffstat (limited to 'toxrtp')
-rw-r--r--toxrtp/toxrtp.h66
-rw-r--r--toxrtp/toxrtp_helper.c97
2 files changed, 81 insertions, 82 deletions
diff --git a/toxrtp/toxrtp.h b/toxrtp/toxrtp.h
index f6270c11..44717835 100644
--- a/toxrtp/toxrtp.h
+++ b/toxrtp/toxrtp.h
@@ -31,7 +31,7 @@
31#define RTP_VERSION 2 31#define RTP_VERSION 2
32#include <inttypes.h> 32#include <inttypes.h>
33#include "../toxcore/tox.h" 33#include "../toxcore/tox.h"
34 34#include <pthread.h>
35/* Extension header flags */ 35/* Extension header flags */
36#define RTP_EXT_TYPE_RESOLUTION 0x01 36#define RTP_EXT_TYPE_RESOLUTION 0x01
37#define RTP_EXT_TYPE_FRAMERATE 0x02 37#define RTP_EXT_TYPE_FRAMERATE 0x02
@@ -72,7 +72,7 @@ typedef struct rtp_session_s {
72 uint32_t _time_elapsed; 72 uint32_t _time_elapsed;
73 uint32_t _current_timestamp; 73 uint32_t _current_timestamp;
74 uint32_t _ssrc; 74 uint32_t _ssrc;
75 uint32_t* _csrc; 75 uint32_t *_csrc;
76 76
77 77
78 /* If some additional data must be sent via message 78 /* If some additional data must be sent via message
@@ -80,7 +80,7 @@ typedef struct rtp_session_s {
80 * automatically placing it within a message. 80 * automatically placing it within a message.
81 */ 81 */
82 82
83 struct rtp_ext_header_s* _ext_header; 83 struct rtp_ext_header_s *_ext_header;
84 /* External header identifiers */ 84 /* External header identifiers */
85 int _exthdr_resolution; 85 int _exthdr_resolution;
86 int _exthdr_framerate; 86 int _exthdr_framerate;
@@ -95,16 +95,16 @@ typedef struct rtp_session_s {
95 95
96 uint64_t _packet_loss; 96 uint64_t _packet_loss;
97 97
98 const char* _last_error; 98 const char *_last_error;
99 99
100 struct rtp_dest_list_s* _dest_list; 100 struct rtp_dest_list_s *_dest_list;
101 struct rtp_dest_list_s* _last_user; /* a tail for faster appending */ 101 struct rtp_dest_list_s *_last_user; /* a tail for faster appending */
102 102
103 struct rtp_msg_s* _oldest_msg; 103 struct rtp_msg_s *_oldest_msg;
104 struct rtp_msg_s* _last_msg; /* tail */ 104 struct rtp_msg_s *_last_msg; /* tail */
105 105
106 uint16_t _prefix_length; 106 uint16_t _prefix_length;
107 uint8_t* _prefix; 107 uint8_t *_prefix;
108 108
109 /* Specifies multiple session use. 109 /* Specifies multiple session use.
110 * When using one session it uses default value ( -1 ) 110 * When using one session it uses default value ( -1 )
@@ -125,35 +125,35 @@ typedef struct rtp_session_s {
125 */ 125 */
126 126
127 127
128void rtp_free_msg ( rtp_session_t* _session, struct rtp_msg_s* _msg ); 128void rtp_free_msg ( rtp_session_t *_session, struct rtp_msg_s *_msg );
129int rtp_release_session_recv ( rtp_session_t* _session ); 129int rtp_release_session_recv ( rtp_session_t *_session );
130 130
131/* Functions handling receiving */ 131/* Functions handling receiving */
132struct rtp_msg_s* rtp_recv_msg ( rtp_session_t* _session ); 132struct rtp_msg_s *rtp_recv_msg ( rtp_session_t *_session );
133void rtp_store_msg ( rtp_session_t* _session, struct rtp_msg_s* _msg ); 133void rtp_store_msg ( rtp_session_t *_session, struct rtp_msg_s *_msg );
134 134
135/* 135/*
136 * rtp_msg_parse() stores headers separately from the payload data 136 * rtp_msg_parse() stores headers separately from the payload data
137 * and so the _length variable is set accordingly 137 * and so the _length variable is set accordingly
138 */ 138 */
139struct rtp_msg_s* rtp_msg_parse ( rtp_session_t* _session, const uint8_t* _data, uint32_t _length ); 139struct rtp_msg_s *rtp_msg_parse ( rtp_session_t *_session, const uint8_t *_data, uint32_t _length );
140 140
141int rtp_check_late_message (rtp_session_t* _session, struct rtp_msg_s* _msg); 141int rtp_check_late_message (rtp_session_t *_session, struct rtp_msg_s *_msg);
142void rtp_register_msg ( rtp_session_t* _session, struct rtp_msg_s* ); 142void rtp_register_msg ( rtp_session_t *_session, struct rtp_msg_s * );
143 143
144/* Functions handling sending */ 144/* Functions handling sending */
145int rtp_send_msg ( rtp_session_t* _session, struct rtp_msg_s* _msg, void* _core_handler ); 145int rtp_send_msg ( rtp_session_t *_session, struct rtp_msg_s *_msg, void *_core_handler );
146 146
147/* 147/*
148 * rtp_msg_new() stores headers and payload data in one container ( _data ) 148 * rtp_msg_new() stores headers and payload data in one container ( _data )
149 * and the _length is set accordingly. Returned message is used for sending only 149 * and the _length is set accordingly. Returned message is used for sending only
150 * so there is not much use of the headers there 150 * so there is not much use of the headers there
151 */ 151 */
152struct rtp_msg_s* rtp_msg_new ( rtp_session_t* _session, const uint8_t* _data, uint32_t _length ); 152struct rtp_msg_s *rtp_msg_new ( rtp_session_t *_session, const uint8_t *_data, uint32_t _length );
153 153
154 154
155/* Convenient functions for creating a header */ 155/* Convenient functions for creating a header */
156struct rtp_header_s* rtp_build_header ( rtp_session_t* _session ); 156struct rtp_header_s *rtp_build_header ( rtp_session_t *_session );
157 157
158/* Functions handling session control */ 158/* Functions handling session control */
159 159
@@ -163,26 +163,26 @@ struct rtp_header_s* rtp_build_header ( rtp_session_t* _session );
163/* Session initiation and termination. 163/* Session initiation and termination.
164 * Set _multi_session to -1 if not using multiple sessions 164 * Set _multi_session to -1 if not using multiple sessions
165 */ 165 */
166rtp_session_t* rtp_init_session ( int _max_users, int _multi_session ); 166rtp_session_t *rtp_init_session ( int _max_users, int _multi_session );
167int rtp_terminate_session ( rtp_session_t* _session ); 167int rtp_terminate_session ( rtp_session_t *_session );
168 168
169/* Adding receiver */ 169/* Adding receiver */
170int rtp_add_receiver ( rtp_session_t* _session, tox_IP_Port* _dest ); 170int rtp_add_receiver ( rtp_session_t *_session, tox_IP_Port *_dest );
171 171
172/* Convenient functions for marking the resolution */ 172/* Convenient functions for marking the resolution */
173int rtp_add_resolution_marking ( rtp_session_t* _session, uint16_t _width, uint16_t _height ); 173int rtp_add_resolution_marking ( rtp_session_t *_session, uint16_t _width, uint16_t _height );
174int rtp_remove_resolution_marking ( rtp_session_t* _session ); 174int rtp_remove_resolution_marking ( rtp_session_t *_session );
175uint16_t rtp_get_resolution_marking_height ( struct rtp_ext_header_s* _header, uint32_t _position ); 175uint16_t rtp_get_resolution_marking_height ( struct rtp_ext_header_s *_header, uint32_t _position );
176uint16_t rtp_get_resolution_marking_width ( struct rtp_ext_header_s* _header, uint32_t _position ); 176uint16_t rtp_get_resolution_marking_width ( struct rtp_ext_header_s *_header, uint32_t _position );
177 177
178int rtp_add_framerate_marking ( rtp_session_t* _session, uint32_t _value ); 178int rtp_add_framerate_marking ( rtp_session_t *_session, uint32_t _value );
179int rtp_remove_framerate_marking ( rtp_session_t* _session ); 179int rtp_remove_framerate_marking ( rtp_session_t *_session );
180uint32_t rtp_get_framerate_marking ( struct rtp_ext_header_s* _header ); 180uint32_t rtp_get_framerate_marking ( struct rtp_ext_header_s *_header );
181/* Convenient functions for marking the payload */ 181/* Convenient functions for marking the payload */
182void rtp_set_payload_type ( rtp_session_t* _session, uint8_t _payload_value ); 182void rtp_set_payload_type ( rtp_session_t *_session, uint8_t _payload_value );
183uint32_t rtp_get_payload_type ( rtp_session_t* _session ); 183uint32_t rtp_get_payload_type ( rtp_session_t *_session );
184 184
185/* When using RTP in core be sure to set prefix when sending via rtp_send_msg */ 185/* When using RTP in core be sure to set prefix when sending via rtp_send_msg */
186int rtp_set_prefix ( rtp_session_t* _session, uint8_t* _prefix, uint16_t _prefix_length ); 186int rtp_set_prefix ( rtp_session_t *_session, uint8_t *_prefix, uint16_t _prefix_length );
187 187
188#endif /* _RTP__IMPL_H_ */ 188#endif /* _RTP__IMPL_H_ */
diff --git a/toxrtp/toxrtp_helper.c b/toxrtp/toxrtp_helper.c
index bb2dc56b..6f952359 100644
--- a/toxrtp/toxrtp_helper.c
+++ b/toxrtp/toxrtp_helper.c
@@ -31,7 +31,6 @@
31#include "toxrtp_helper.h" 31#include "toxrtp_helper.h"
32#include "../toxcore/network.h" 32#include "../toxcore/network.h"
33 33
34#include <arpa/inet.h> /* Fixes implicit function warning. */
35#include <assert.h> 34#include <assert.h>
36 35
37#ifdef WIN 36#ifdef WIN
@@ -41,11 +40,11 @@
41 40
42static int _seed = 0; /* Not initiated */ 41static int _seed = 0; /* Not initiated */
43 42
44int t_setipport ( const char* _ip, unsigned short _port, void* _dest ) 43int t_setipport ( const char *_ip, unsigned short _port, void *_dest )
45{ 44{
46 assert(_dest); 45 assert(_dest);
47 46
48 IP_Port* _dest_c = ( IP_Port* ) _dest; 47 IP_Port *_dest_c = ( IP_Port * ) _dest;
49 ip_init(&_dest_c->ip, 0); 48 ip_init(&_dest_c->ip, 0);
50 49
51 IP_Port _ipv6_garbage; 50 IP_Port _ipv6_garbage;
@@ -72,7 +71,7 @@ uint32_t t_random ( uint32_t _max )
72 } 71 }
73} 72}
74 73
75void t_memcpy ( uint8_t* _dest, const uint8_t* _source, size_t _size ) 74void t_memcpy ( uint8_t *_dest, const uint8_t *_source, size_t _size )
76{ 75{
77 /* 76 /*
78 * Using countdown to zero method 77 * Using countdown to zero method
@@ -87,7 +86,7 @@ void t_memcpy ( uint8_t* _dest, const uint8_t* _source, size_t _size )
87 86
88} 87}
89 88
90uint8_t* t_memset ( uint8_t* _dest, uint8_t _valu, size_t _size ) 89uint8_t *t_memset ( uint8_t *_dest, uint8_t _valu, size_t _size )
91{ 90{
92 /* 91 /*
93 * Again using countdown to zero method 92 * Again using countdown to zero method
@@ -102,9 +101,9 @@ uint8_t* t_memset ( uint8_t* _dest, uint8_t _valu, size_t _size )
102 return _dest; 101 return _dest;
103} 102}
104 103
105size_t t_memlen ( const uint8_t* _valu) 104size_t t_memlen ( const uint8_t *_valu)
106{ 105{
107 const uint8_t* _it; 106 const uint8_t *_it;
108 size_t _retu = 0; 107 size_t _retu = 0;
109 108
110 for ( _it = _valu; *_it; ++_it ) ++_retu; 109 for ( _it = _valu; *_it; ++_it ) ++_retu;
@@ -112,13 +111,13 @@ size_t t_memlen ( const uint8_t* _valu)
112 return _retu; 111 return _retu;
113} 112}
114 113
115uint8_t* t_strallcpy ( const uint8_t* _source ) /* string alloc and copy */ 114uint8_t *t_strallcpy ( const uint8_t *_source ) /* string alloc and copy */
116{ 115{
117 assert(_source); 116 assert(_source);
118 117
119 size_t _length = t_memlen(_source) + 1; /* make space for null character */ 118 size_t _length = t_memlen(_source) + 1; /* make space for null character */
120 119
121 uint8_t* _dest = calloc( sizeof ( uint8_t ), _length ); 120 uint8_t *_dest = calloc( sizeof ( uint8_t ), _length );
122 assert(_dest); 121 assert(_dest);
123 122
124 t_memcpy(_dest, _source, _length); 123 t_memcpy(_dest, _source, _length);
@@ -126,75 +125,75 @@ uint8_t* t_strallcpy ( const uint8_t* _source ) /* string alloc and copy */
126 return _dest; 125 return _dest;
127} 126}
128 127
129size_t t_strfind ( const uint8_t* _str, const uint8_t* _substr ) 128size_t t_strfind ( const uint8_t *_str, const uint8_t *_substr )
130{ 129{
131 size_t _pos = 0; 130 size_t _pos = 0;
132 size_t _it, _delit = 0; 131 size_t _it, _delit = 0;
133 132
134 for ( _it = 0; _str[_it] != '\0'; _it++ ){ 133 for ( _it = 0; _str[_it] != '\0'; _it++ ) {
135 if ( _str[_it] == _substr[_delit] ){ 134 if ( _str[_it] == _substr[_delit] ) {
136 _pos = _it; 135 _pos = _it;
137 while ( _str[_it] == _substr[_delit] && _str[_it] != '\0' ){ 136
137 while ( _str[_it] == _substr[_delit] && _str[_it] != '\0' ) {
138 _it ++; 138 _it ++;
139 _delit++; 139 _delit++;
140 140
141 if ( _substr[_delit] == '\0' ){ 141 if ( _substr[_delit] == '\0' ) {
142 return _pos; 142 return _pos;
143 } 143 }
144 } 144 }
145
145 _delit = 0; 146 _delit = 0;
146 _pos = 0; 147 _pos = 0;
147 } 148 }
148 } 149 }
150
149 return _pos; 151 return _pos;
150} 152}
151 153
152#ifdef WIN 154#ifdef WIN
153#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) 155#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
154 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 156#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
155#else 157#else
156 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL 158#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
157#endif 159#endif
158 160
159struct timezone 161struct timezone {
160{ 162 int tz_minuteswest; /* minutes W of Greenwich */
161 int tz_minuteswest; /* minutes W of Greenwich */ 163 int tz_dsttime; /* type of dst correction */
162 int tz_dsttime; /* type of dst correction */
163}; 164};
164 165
165int gettimeofday(struct timeval *tv, struct timezone *tz) 166int gettimeofday(struct timeval *tv, struct timezone *tz)
166{ 167{
167 FILETIME ft; 168 FILETIME ft;
168 unsigned __int64 tmpres = 0; 169 unsigned __int64 tmpres = 0;
169 static int tzflag; 170 static int tzflag;
170 171
171 if (NULL != tv) 172 if (NULL != tv) {
172 { 173 GetSystemTimeAsFileTime(&ft);
173 GetSystemTimeAsFileTime(&ft); 174
174 175 tmpres |= ft.dwHighDateTime;
175 tmpres |= ft.dwHighDateTime; 176 tmpres <<= 32;
176 tmpres <<= 32; 177 tmpres |= ft.dwLowDateTime;
177 tmpres |= ft.dwLowDateTime; 178
178 179 /*converting file time to unix epoch*/
179 /*converting file time to unix epoch*/ 180 tmpres -= DELTA_EPOCH_IN_MICROSECS;
180 tmpres -= DELTA_EPOCH_IN_MICROSECS; 181 tmpres /= 10; /*convert into microseconds*/
181 tmpres /= 10; /*convert into microseconds*/ 182 tv->tv_sec = (long)(tmpres / 1000000UL);
182 tv->tv_sec = (long)(tmpres / 1000000UL); 183 tv->tv_usec = (long)(tmpres % 1000000UL);
183 tv->tv_usec = (long)(tmpres % 1000000UL); 184 }
184 } 185
185 186 if (NULL != tz) {
186 if (NULL != tz) 187 if (!tzflag) {
187 { 188 _tzset();
188 if (!tzflag) 189 tzflag++;
189 { 190 }
190 _tzset(); 191
191 tzflag++; 192 tz->tz_minuteswest = _timezone / 60;
193 tz->tz_dsttime = _daylight;
192 } 194 }
193 tz->tz_minuteswest = _timezone / 60;
194 tz->tz_dsttime = _daylight;
195 }
196 195
197 return 0; 196 return 0;
198} 197}
199#endif /* WIN */ 198#endif /* WIN */
200 199