diff options
-rw-r--r-- | toxmsi/phone.c | 375 | ||||
-rw-r--r-- | toxrtp/toxrtp.h | 66 | ||||
-rw-r--r-- | toxrtp/toxrtp_helper.c | 97 |
3 files changed, 280 insertions, 258 deletions
diff --git a/toxmsi/phone.c b/toxmsi/phone.c index 010f26aa..f14d0323 100644 --- a/toxmsi/phone.c +++ b/toxmsi/phone.c | |||
@@ -14,13 +14,13 @@ | |||
14 | #include <stdio.h> | 14 | #include <stdio.h> |
15 | #include <string.h> | 15 | #include <string.h> |
16 | #include <stdlib.h> | 16 | #include <stdlib.h> |
17 | #include <termios.h> | 17 | /* #include <termios.h> Can this be removed? */ |
18 | #include <pthread.h> | 18 | #include <pthread.h> |
19 | #include "AV_codec.h" | 19 | #include "AV_codec.h" |
20 | 20 | ||
21 | 21 | ||
22 | 22 | ||
23 | void INFO (const char* _format, ...) | 23 | void INFO (const char *_format, ...) |
24 | { | 24 | { |
25 | printf("\r[!] "); | 25 | printf("\r[!] "); |
26 | va_list _arg; | 26 | va_list _arg; |
@@ -31,13 +31,13 @@ void INFO (const char* _format, ...) | |||
31 | fflush(stdout); | 31 | fflush(stdout); |
32 | } | 32 | } |
33 | 33 | ||
34 | int rtp_handlepacket ( void* _object, tox_IP_Port ip_port, uint8_t* data, uint32_t length ) | 34 | int rtp_handlepacket ( void *_object, tox_IP_Port ip_port, uint8_t *data, uint32_t length ) |
35 | { | 35 | { |
36 | phone_t* _phone = _object; | 36 | phone_t *_phone = _object; |
37 | rtp_msg_t* _msg; | 37 | rtp_msg_t *_msg; |
38 | uint8_t _payload_id; | 38 | uint8_t _payload_id; |
39 | 39 | ||
40 | if ( _phone->_msi->_call && _phone->_msi->_call->_state == call_active ){ | 40 | if ( _phone->_msi->_call && _phone->_msi->_call->_state == call_active ) { |
41 | 41 | ||
42 | _msg = rtp_msg_parse ( NULL, data + 1, length - 1 ); /* ignore marker byte */ | 42 | _msg = rtp_msg_parse ( NULL, data + 1, length - 1 ); /* ignore marker byte */ |
43 | 43 | ||
@@ -55,10 +55,10 @@ int rtp_handlepacket ( void* _object, tox_IP_Port ip_port, uint8_t* data, uint32 | |||
55 | 55 | ||
56 | return SUCCESS; | 56 | return SUCCESS; |
57 | } | 57 | } |
58 | int msi_handlepacket ( void* _object, tox_IP_Port ip_port, uint8_t* data, uint32_t length ) | 58 | int msi_handlepacket ( void *_object, tox_IP_Port ip_port, uint8_t *data, uint32_t length ) |
59 | { | 59 | { |
60 | msi_session_t* _session = _object; | 60 | msi_session_t *_session = _object; |
61 | msi_msg_t* _msg; | 61 | msi_msg_t *_msg; |
62 | 62 | ||
63 | _msg = msi_parse_msg ( data + 1 ); /* ignore marker byte */ | 63 | _msg = msi_parse_msg ( data + 1 ); /* ignore marker byte */ |
64 | 64 | ||
@@ -75,9 +75,9 @@ int msi_handlepacket ( void* _object, tox_IP_Port ip_port, uint8_t* data, uint32 | |||
75 | return SUCCESS; | 75 | return SUCCESS; |
76 | } | 76 | } |
77 | 77 | ||
78 | void* phone_receivepacket ( void* _phone_p ) | 78 | void *phone_receivepacket ( void *_phone_p ) |
79 | { | 79 | { |
80 | phone_t* _phone = _phone_p; | 80 | phone_t *_phone = _phone_p; |
81 | 81 | ||
82 | 82 | ||
83 | networking_registerhandler(_phone->_networking, MSI_PACKET, msi_handlepacket, _phone->_msi); | 83 | networking_registerhandler(_phone->_networking, MSI_PACKET, msi_handlepacket, _phone->_msi); |
@@ -94,31 +94,31 @@ void* phone_receivepacket ( void* _phone_p ) | |||
94 | 94 | ||
95 | /* Media transport callback */ | 95 | /* Media transport callback */ |
96 | typedef struct hmtc_args_s { | 96 | typedef struct hmtc_args_s { |
97 | rtp_session_t** _rtp_audio; | 97 | rtp_session_t **_rtp_audio; |
98 | rtp_session_t** _rtp_video; | 98 | rtp_session_t **_rtp_video; |
99 | call_type* _local_type_call; | 99 | call_type *_local_type_call; |
100 | call_state* _this_call; | 100 | call_state *_this_call; |
101 | void *_core_handler; | 101 | void *_core_handler; |
102 | } hmtc_args_t; | 102 | } hmtc_args_t; |
103 | 103 | ||
104 | void* phone_handle_media_transport_poll ( void* _hmtc_args_p ) | 104 | void *phone_handle_media_transport_poll ( void *_hmtc_args_p ) |
105 | { | 105 | { |
106 | rtp_msg_t* _audio_msg, * _video_msg; | 106 | rtp_msg_t *_audio_msg, * _video_msg; |
107 | 107 | ||
108 | hmtc_args_t* _hmtc_args = _hmtc_args_p; | 108 | hmtc_args_t *_hmtc_args = _hmtc_args_p; |
109 | 109 | ||
110 | rtp_session_t* _rtp_audio = *_hmtc_args->_rtp_audio; | 110 | rtp_session_t *_rtp_audio = *_hmtc_args->_rtp_audio; |
111 | rtp_session_t* _rtp_video = *_hmtc_args->_rtp_video; | 111 | rtp_session_t *_rtp_video = *_hmtc_args->_rtp_video; |
112 | 112 | ||
113 | call_type* _type = _hmtc_args->_local_type_call; | 113 | call_type *_type = _hmtc_args->_local_type_call; |
114 | void* _core_handler = _hmtc_args->_core_handler; | 114 | void *_core_handler = _hmtc_args->_core_handler; |
115 | 115 | ||
116 | 116 | ||
117 | call_state* _this_call = _hmtc_args->_this_call; | 117 | call_state *_this_call = _hmtc_args->_this_call; |
118 | 118 | ||
119 | while ( *_this_call == call_active ) { | 119 | while ( *_this_call == call_active ) { |
120 | 120 | ||
121 | // THREADLOCK() | 121 | // THREADLOCK() |
122 | 122 | ||
123 | _audio_msg = rtp_recv_msg ( _rtp_audio ); | 123 | _audio_msg = rtp_recv_msg ( _rtp_audio ); |
124 | _video_msg = rtp_recv_msg ( _rtp_video ); | 124 | _video_msg = rtp_recv_msg ( _rtp_video ); |
@@ -139,14 +139,15 @@ void* phone_handle_media_transport_poll ( void* _hmtc_args_p ) | |||
139 | rtp_free_msg ( _rtp_video, _video_msg ); | 139 | rtp_free_msg ( _rtp_video, _video_msg ); |
140 | _video_msg = NULL; | 140 | _video_msg = NULL; |
141 | } | 141 | } |
142 | |||
142 | /* -------------------- */ | 143 | /* -------------------- */ |
143 | 144 | ||
144 | _audio_msg = rtp_msg_new ( _rtp_audio, (const uint8_t*)"audio\0", 6 ) ; | 145 | _audio_msg = rtp_msg_new ( _rtp_audio, (const uint8_t *)"audio\0", 6 ) ; |
145 | rtp_send_msg ( _rtp_audio, _audio_msg, _core_handler ); | 146 | rtp_send_msg ( _rtp_audio, _audio_msg, _core_handler ); |
146 | _audio_msg = NULL; | 147 | _audio_msg = NULL; |
147 | 148 | ||
148 | if ( *_type == type_video ){ /* if local call send video */ | 149 | if ( *_type == type_video ) { /* if local call send video */ |
149 | _video_msg = rtp_msg_new ( _rtp_video, (const uint8_t*)"video\0", 6 ) ; | 150 | _video_msg = rtp_msg_new ( _rtp_video, (const uint8_t *)"video\0", 6 ) ; |
150 | rtp_send_msg ( _rtp_video, _video_msg, _core_handler ); | 151 | rtp_send_msg ( _rtp_video, _video_msg, _core_handler ); |
151 | _video_msg = NULL; | 152 | _video_msg = NULL; |
152 | } | 153 | } |
@@ -159,7 +160,7 @@ void* phone_handle_media_transport_poll ( void* _hmtc_args_p ) | |||
159 | 160 | ||
160 | //THREADLOCK() | 161 | //THREADLOCK() |
161 | 162 | ||
162 | if ( _audio_msg ){ | 163 | if ( _audio_msg ) { |
163 | rtp_free_msg(_rtp_audio, _audio_msg); | 164 | rtp_free_msg(_rtp_audio, _audio_msg); |
164 | } | 165 | } |
165 | 166 | ||
@@ -185,9 +186,9 @@ void* phone_handle_media_transport_poll ( void* _hmtc_args_p ) | |||
185 | pthread_exit ( NULL ); | 186 | pthread_exit ( NULL ); |
186 | } | 187 | } |
187 | 188 | ||
188 | pthread_t phone_startmedia_loop ( phone_t* _phone ) | 189 | pthread_t phone_startmedia_loop ( phone_t *_phone ) |
189 | { | 190 | { |
190 | if ( !_phone ){ | 191 | if ( !_phone ) { |
191 | return 0; | 192 | return 0; |
192 | } | 193 | } |
193 | 194 | ||
@@ -207,10 +208,10 @@ pthread_t phone_startmedia_loop ( phone_t* _phone ) | |||
207 | rtp_set_prefix ( _phone->_rtp_video, &_prefix, 1 ); | 208 | rtp_set_prefix ( _phone->_rtp_video, &_prefix, 1 ); |
208 | rtp_add_receiver ( _phone->_rtp_video, &_phone->_msi->_friend_id ); | 209 | rtp_add_receiver ( _phone->_rtp_video, &_phone->_msi->_friend_id ); |
209 | rtp_set_payload_type(_phone->_rtp_video, _PAYLOAD_VP8); | 210 | rtp_set_payload_type(_phone->_rtp_video, _PAYLOAD_VP8); |
210 | |||
211 | |||
212 | 211 | ||
213 | hmtc_args_t* rtp_targs = calloc(sizeof(hmtc_args_t),1); | 212 | |
213 | |||
214 | hmtc_args_t *rtp_targs = calloc(sizeof(hmtc_args_t), 1); | ||
214 | 215 | ||
215 | 216 | ||
216 | rtp_targs->_rtp_audio = &_phone->_rtp_audio; | 217 | rtp_targs->_rtp_audio = &_phone->_rtp_audio; |
@@ -220,26 +221,29 @@ pthread_t phone_startmedia_loop ( phone_t* _phone ) | |||
220 | rtp_targs->_core_handler = _phone->_networking; | 221 | rtp_targs->_core_handler = _phone->_networking; |
221 | 222 | ||
222 | codec_state *cs; | 223 | codec_state *cs; |
223 | cs=_phone->cs; | 224 | cs = _phone->cs; |
224 | //_status = pthread_create ( &_rtp_tid, NULL, phone_handle_media_transport_poll, rtp_targs ); | 225 | //_status = pthread_create ( &_rtp_tid, NULL, phone_handle_media_transport_poll, rtp_targs ); |
225 | cs->_rtp_audio=_phone->_rtp_audio; | 226 | cs->_rtp_audio = _phone->_rtp_audio; |
226 | cs->_rtp_video=_phone->_rtp_video; | 227 | cs->_rtp_video = _phone->_rtp_video; |
227 | cs->_networking=_phone->_networking; | 228 | cs->_networking = _phone->_networking; |
228 | cs->socket=_phone->_tox_sock; | 229 | cs->socket = _phone->_tox_sock; |
229 | cs->quit = 0; | 230 | cs->quit = 0; |
230 | 231 | ||
231 | printf("support: %d %d\n",cs->support_send_audio,cs->support_send_video); | 232 | printf("support: %d %d\n", cs->support_send_audio, cs->support_send_video); |
232 | 233 | ||
233 | if(cs->support_send_audio&&cs->support_send_video) /* quick fix */ | 234 | if (cs->support_send_audio && cs->support_send_video) /* quick fix */ |
234 | pthread_create(&_phone->cs->encode_audio_thread, NULL, encode_audio_thread, _phone->cs); | 235 | pthread_create(&_phone->cs->encode_audio_thread, NULL, encode_audio_thread, _phone->cs); |
235 | if(cs->support_receive_audio) | 236 | |
236 | pthread_create(&_phone->cs->decode_audio_thread, NULL, decode_audio_thread, _phone->cs); | 237 | if (cs->support_receive_audio) |
237 | 238 | pthread_create(&_phone->cs->decode_audio_thread, NULL, decode_audio_thread, _phone->cs); | |
238 | if(cs->support_send_video) | 239 | |
239 | pthread_create(&_phone->cs->encode_video_thread, NULL, encode_video_thread, _phone->cs); | 240 | if (cs->support_send_video) |
240 | if(cs->support_receive_video) | 241 | pthread_create(&_phone->cs->encode_video_thread, NULL, encode_video_thread, _phone->cs); |
241 | pthread_create(&_phone->cs->decode_video_thread, NULL, decode_video_thread, _phone->cs); | 242 | |
242 | // | 243 | if (cs->support_receive_video) |
244 | pthread_create(&_phone->cs->decode_video_thread, NULL, decode_video_thread, _phone->cs); | ||
245 | |||
246 | // | ||
243 | return 1; | 247 | return 1; |
244 | 248 | ||
245 | 249 | ||
@@ -252,20 +256,21 @@ pthread_t phone_startmedia_loop ( phone_t* _phone ) | |||
252 | 256 | ||
253 | MCBTYPE callback_recv_invite ( MCBARGS ) | 257 | MCBTYPE callback_recv_invite ( MCBARGS ) |
254 | { | 258 | { |
255 | const char* _call_type; | 259 | const char *_call_type; |
256 | 260 | ||
257 | msi_session_t* _msi = _arg; | 261 | msi_session_t *_msi = _arg; |
258 | 262 | ||
259 | /* Get the last one */ | 263 | /* Get the last one */ |
260 | call_type _type = _msi->_call->_type_peer[_msi->_call->_participants - 1]; | 264 | call_type _type = _msi->_call->_type_peer[_msi->_call->_participants - 1]; |
261 | 265 | ||
262 | switch ( _type ){ | 266 | switch ( _type ) { |
263 | case type_audio: | 267 | case type_audio: |
264 | _call_type = "audio"; | 268 | _call_type = "audio"; |
265 | break; | 269 | break; |
266 | case type_video: | 270 | |
267 | _call_type = "video"; | 271 | case type_video: |
268 | break; | 272 | _call_type = "video"; |
273 | break; | ||
269 | } | 274 | } |
270 | 275 | ||
271 | INFO( "Incoming %s call!", _call_type ); | 276 | INFO( "Incoming %s call!", _call_type ); |
@@ -281,8 +286,9 @@ MCBTYPE callback_recv_ringing ( MCBARGS ) | |||
281 | } | 286 | } |
282 | MCBTYPE callback_recv_starting ( MCBARGS ) | 287 | MCBTYPE callback_recv_starting ( MCBARGS ) |
283 | { | 288 | { |
284 | msi_session_t* _session = _arg; | 289 | msi_session_t *_session = _arg; |
285 | if ( !phone_startmedia_loop(_session->_agent_handler) ){ | 290 | |
291 | if ( !phone_startmedia_loop(_session->_agent_handler) ) { | ||
286 | INFO("Starting call failed!"); | 292 | INFO("Starting call failed!"); |
287 | } else { | 293 | } else { |
288 | INFO ("Call started! ( press h to hangup )"); | 294 | INFO ("Call started! ( press h to hangup )"); |
@@ -290,34 +296,40 @@ MCBTYPE callback_recv_starting ( MCBARGS ) | |||
290 | } | 296 | } |
291 | MCBTYPE callback_recv_ending ( MCBARGS ) | 297 | MCBTYPE callback_recv_ending ( MCBARGS ) |
292 | { | 298 | { |
293 | msi_session_t* _session = _arg; | 299 | msi_session_t *_session = _arg; |
294 | phone_t * _phone = _session->_agent_handler; | 300 | phone_t *_phone = _session->_agent_handler; |
295 | _phone->cs->quit=1; | 301 | _phone->cs->quit = 1; |
296 | if(_phone->cs->encode_video_thread) | 302 | |
297 | pthread_join(_phone->cs->encode_video_thread,NULL); | 303 | if (_phone->cs->encode_video_thread) |
298 | if(_phone->cs->encode_audio_thread) | 304 | pthread_join(_phone->cs->encode_video_thread, NULL); |
299 | pthread_join(_phone->cs->encode_audio_thread,NULL); | 305 | |
300 | if(_phone->cs->decode_audio_thread) | 306 | if (_phone->cs->encode_audio_thread) |
301 | pthread_join(_phone->cs->decode_audio_thread,NULL); | 307 | pthread_join(_phone->cs->encode_audio_thread, NULL); |
302 | if(_phone->cs->decode_video_thread) | 308 | |
303 | pthread_join(_phone->cs->decode_video_thread,NULL); | 309 | if (_phone->cs->decode_audio_thread) |
310 | pthread_join(_phone->cs->decode_audio_thread, NULL); | ||
311 | |||
312 | if (_phone->cs->decode_video_thread) | ||
313 | pthread_join(_phone->cs->decode_video_thread, NULL); | ||
314 | |||
304 | SDL_Quit(); | 315 | SDL_Quit(); |
305 | printf("all A/V threads successfully shut down\n"); | 316 | printf("all A/V threads successfully shut down\n"); |
306 | 317 | ||
307 | INFO ( "Call ended!" ); | 318 | INFO ( "Call ended!" ); |
308 | } | 319 | } |
309 | 320 | ||
310 | MCBTYPE callback_recv_error ( MCBARGS ) | 321 | MCBTYPE callback_recv_error ( MCBARGS ) |
311 | { | 322 | { |
312 | msi_session_t* _session = _arg; | 323 | msi_session_t *_session = _arg; |
313 | 324 | ||
314 | INFO( "Error: %s", _session->_last_error_str ); | 325 | INFO( "Error: %s", _session->_last_error_str ); |
315 | } | 326 | } |
316 | 327 | ||
317 | MCBTYPE callback_call_started ( MCBARGS ) | 328 | MCBTYPE callback_call_started ( MCBARGS ) |
318 | { | 329 | { |
319 | msi_session_t* _session = _arg; | 330 | msi_session_t *_session = _arg; |
320 | if ( !phone_startmedia_loop(_session->_agent_handler) ){ | 331 | |
332 | if ( !phone_startmedia_loop(_session->_agent_handler) ) { | ||
321 | INFO("Starting call failed!"); | 333 | INFO("Starting call failed!"); |
322 | } else { | 334 | } else { |
323 | INFO ("Call started! ( press h to hangup )"); | 335 | INFO ("Call started! ( press h to hangup )"); |
@@ -334,21 +346,26 @@ MCBTYPE callback_call_rejected ( MCBARGS ) | |||
334 | } | 346 | } |
335 | MCBTYPE callback_call_ended ( MCBARGS ) | 347 | MCBTYPE callback_call_ended ( MCBARGS ) |
336 | { | 348 | { |
337 | 349 | ||
338 | msi_session_t* _session = _arg; | 350 | msi_session_t *_session = _arg; |
339 | phone_t * _phone = _session->_agent_handler; | 351 | phone_t *_phone = _session->_agent_handler; |
340 | _phone->cs->quit=1; | 352 | _phone->cs->quit = 1; |
341 | if(_phone->cs->encode_video_thread) | 353 | |
342 | pthread_join(_phone->cs->encode_video_thread,NULL); | 354 | if (_phone->cs->encode_video_thread) |
343 | if(_phone->cs->encode_audio_thread) | 355 | pthread_join(_phone->cs->encode_video_thread, NULL); |
344 | pthread_join(_phone->cs->encode_audio_thread,NULL); | 356 | |
345 | if(_phone->cs->decode_audio_thread) | 357 | if (_phone->cs->encode_audio_thread) |
346 | pthread_join(_phone->cs->decode_audio_thread,NULL); | 358 | pthread_join(_phone->cs->encode_audio_thread, NULL); |
347 | if(_phone->cs->decode_video_thread) | 359 | |
348 | pthread_join(_phone->cs->decode_video_thread,NULL); | 360 | if (_phone->cs->decode_audio_thread) |
361 | pthread_join(_phone->cs->decode_audio_thread, NULL); | ||
362 | |||
363 | if (_phone->cs->decode_video_thread) | ||
364 | pthread_join(_phone->cs->decode_video_thread, NULL); | ||
365 | |||
349 | SDL_Quit(); | 366 | SDL_Quit(); |
350 | printf("all A/V threads successfully shut down\n"); | 367 | printf("all A/V threads successfully shut down\n"); |
351 | 368 | ||
352 | INFO ( "Call ended!" ); | 369 | INFO ( "Call ended!" ); |
353 | } | 370 | } |
354 | 371 | ||
@@ -358,10 +375,10 @@ MCBTYPE callback_requ_timeout ( MCBARGS ) | |||
358 | } | 375 | } |
359 | 376 | ||
360 | 377 | ||
361 | phone_t* initPhone(uint16_t _listen_port, uint16_t _send_port) | 378 | phone_t *initPhone(uint16_t _listen_port, uint16_t _send_port) |
362 | { | 379 | { |
363 | phone_t* _retu = calloc(sizeof(phone_t),1); | 380 | phone_t *_retu = calloc(sizeof(phone_t), 1); |
364 | _retu->cs = av_calloc(sizeof(codec_state),1); | 381 | _retu->cs = av_calloc(sizeof(codec_state), 1); |
365 | 382 | ||
366 | /* Initialize our mutex */ | 383 | /* Initialize our mutex */ |
367 | pthread_mutex_init ( &_mutex, NULL ); | 384 | pthread_mutex_init ( &_mutex, NULL ); |
@@ -388,13 +405,13 @@ phone_t* initPhone(uint16_t _listen_port, uint16_t _send_port) | |||
388 | 405 | ||
389 | 406 | ||
390 | /* Initialize msi */ | 407 | /* Initialize msi */ |
391 | _retu->_msi = msi_init_session ( _retu->_networking, (const uint8_t*)_USERAGENT ); | 408 | _retu->_msi = msi_init_session ( _retu->_networking, (const uint8_t *)_USERAGENT ); |
392 | 409 | ||
393 | if ( !_retu->_msi ) { | 410 | if ( !_retu->_msi ) { |
394 | fprintf ( stderr, "msi_init_session() failed\n" ); | 411 | fprintf ( stderr, "msi_init_session() failed\n" ); |
395 | return NULL; | 412 | return NULL; |
396 | } | 413 | } |
397 | 414 | ||
398 | /* Initiate codecs */ | 415 | /* Initiate codecs */ |
399 | init_encoder(_retu->cs); | 416 | init_encoder(_retu->cs); |
400 | init_decoder(_retu->cs); | 417 | init_decoder(_retu->cs); |
@@ -425,7 +442,7 @@ phone_t* initPhone(uint16_t _listen_port, uint16_t _send_port) | |||
425 | return _retu; | 442 | return _retu; |
426 | } | 443 | } |
427 | 444 | ||
428 | pthread_t phone_startmain_loop(phone_t* _phone) | 445 | pthread_t phone_startmain_loop(phone_t *_phone) |
429 | { | 446 | { |
430 | int _status; | 447 | int _status; |
431 | /* Start receive thread */ | 448 | /* Start receive thread */ |
@@ -461,9 +478,9 @@ pthread_t phone_startmain_loop(phone_t* _phone) | |||
461 | return _phone_loop_thread; | 478 | return _phone_loop_thread; |
462 | } | 479 | } |
463 | 480 | ||
464 | void* phone_poll ( void* _p_phone ) | 481 | void *phone_poll ( void *_p_phone ) |
465 | { | 482 | { |
466 | phone_t* _phone = _p_phone; | 483 | phone_t *_phone = _p_phone; |
467 | 484 | ||
468 | int _status = SUCCESS; | 485 | int _status = SUCCESS; |
469 | 486 | ||
@@ -482,121 +499,127 @@ void* phone_poll ( void* _p_phone ) | |||
482 | "r (reject incoming call)\n" | 499 | "r (reject incoming call)\n" |
483 | "q (quit)\n" | 500 | "q (quit)\n" |
484 | "================================================================================" | 501 | "================================================================================" |
485 | ); | 502 | ); |
486 | 503 | ||
487 | while ( 1 ) | 504 | while ( 1 ) { |
488 | { | ||
489 | fgets(_line, sizeof(_line), stdin); | 505 | fgets(_line, sizeof(_line), stdin); |
490 | int i; | 506 | int i; |
507 | |||
491 | for (i = 0; i < 100; i++) { | 508 | for (i = 0; i < 100; i++) { |
492 | if (_line[i] == '\n') { | 509 | if (_line[i] == '\n') { |
493 | _line[i] = '\0'; | 510 | _line[i] = '\0'; |
494 | } | 511 | } |
495 | } | 512 | } |
513 | |||
496 | _len = strlen(_line); | 514 | _len = strlen(_line); |
497 | 515 | ||
498 | if ( !_len ){ | 516 | if ( !_len ) { |
499 | printf(" >> "); fflush(stdout); | 517 | printf(" >> "); |
518 | fflush(stdout); | ||
500 | continue; | 519 | continue; |
501 | } | 520 | } |
502 | 521 | ||
503 | if ( _len > 1 && _line[1] != ' ' && _line[1] != '\n' ){ | 522 | if ( _len > 1 && _line[1] != ' ' && _line[1] != '\n' ) { |
504 | INFO("Invalid input!"); | 523 | INFO("Invalid input!"); |
505 | continue; | 524 | continue; |
506 | } | 525 | } |
507 | 526 | ||
508 | switch (_line[0]){ | 527 | switch (_line[0]) { |
509 | 528 | ||
510 | case 'c': | 529 | case 'c': { |
511 | { | 530 | if ( _phone->_msi->_call ) { |
512 | if ( _phone->_msi->_call ){ | 531 | INFO("Already in a call"); |
513 | INFO("Already in a call"); | 532 | break; |
514 | break; | 533 | } |
515 | } | ||
516 | 534 | ||
517 | call_type _ctype; | 535 | call_type _ctype; |
518 | if ( _len < 11 ){ | ||
519 | INFO("Invalid input; usage: c a/v 0.0.0.0"); | ||
520 | break; | ||
521 | } | ||
522 | else if ( _line[2] == 'a' || _line[2] != 'v' ){ /* default and audio */ | ||
523 | _ctype = type_audio; | ||
524 | } | ||
525 | else { /* video */ | ||
526 | _ctype = type_video; | ||
527 | } | ||
528 | 536 | ||
529 | strcpy(_dest, _line + 4 ); | 537 | if ( _len < 11 ) { |
530 | _status = t_setipport(_dest, _phone->_send_port, &(_phone->_msi->_friend_id)); | 538 | INFO("Invalid input; usage: c a/v 0.0.0.0"); |
539 | break; | ||
540 | } else if ( _line[2] == 'a' || _line[2] != 'v' ) { /* default and audio */ | ||
541 | _ctype = type_audio; | ||
542 | } else { /* video */ | ||
543 | _ctype = type_video; | ||
544 | } | ||
545 | |||
546 | strcpy(_dest, _line + 4 ); | ||
547 | _status = t_setipport(_dest, _phone->_send_port, &(_phone->_msi->_friend_id)); | ||
548 | |||
549 | if ( _status < 0 ) { | ||
550 | INFO("Could not resolve address!"); | ||
551 | } else { | ||
552 | /* Set timeout */ | ||
553 | msi_invite ( _phone->_msi, _ctype, 30 * 1000 ); | ||
554 | INFO("Calling!"); | ||
555 | } | ||
556 | |||
557 | t_memset((uint8_t *)_dest, '\0', 17); | ||
531 | 558 | ||
532 | if ( _status < 0 ){ | ||
533 | INFO("Could not resolve address!"); | ||
534 | } else { | ||
535 | /* Set timeout */ | ||
536 | msi_invite ( _phone->_msi, _ctype, 30 * 1000 ); | ||
537 | INFO("Calling!"); | ||
538 | } | 559 | } |
560 | break; | ||
539 | 561 | ||
540 | t_memset((uint8_t*)_dest, '\0', 17); | 562 | case 'h': { |
563 | if ( !_phone->_msi->_call ) { | ||
564 | break; | ||
565 | } | ||
566 | |||
567 | msi_hangup(_phone->_msi); | ||
568 | |||
569 | INFO("Hung up..."); | ||
541 | 570 | ||
542 | } break; | ||
543 | case 'h': | ||
544 | { | ||
545 | if ( !_phone->_msi->_call ){ | ||
546 | break; | ||
547 | } | 571 | } |
572 | break; | ||
548 | 573 | ||
549 | msi_hangup(_phone->_msi); | 574 | case 'a': { |
575 | if ( _phone->_msi->_call && _phone->_msi->_call->_state != call_starting ) { | ||
576 | break; | ||
577 | } | ||
550 | 578 | ||
551 | INFO("Hung up..."); | 579 | if ( _len > 1 && _line[2] == 'v' ) |
580 | msi_answer(_phone->_msi, type_video); | ||
581 | else | ||
582 | msi_answer(_phone->_msi, type_audio); | ||
552 | 583 | ||
553 | } break; | ||
554 | case 'a': | ||
555 | { | ||
556 | if ( _phone->_msi->_call && _phone->_msi->_call->_state != call_starting ) { | ||
557 | break; | ||
558 | } | 584 | } |
585 | break; | ||
586 | |||
587 | case 'r': { | ||
588 | if ( _phone->_msi->_call && _phone->_msi->_call->_state != call_starting ) { | ||
589 | break; | ||
590 | } | ||
559 | 591 | ||
560 | if ( _len > 1 && _line[2] == 'v' ) | 592 | msi_reject(_phone->_msi); |
561 | msi_answer(_phone->_msi, type_video); | 593 | |
562 | else | 594 | INFO("Call Rejected..."); |
563 | msi_answer(_phone->_msi, type_audio); | ||
564 | 595 | ||
565 | } break; | ||
566 | case 'r': | ||
567 | { | ||
568 | if ( _phone->_msi->_call && _phone->_msi->_call->_state != call_starting ){ | ||
569 | break; | ||
570 | } | 596 | } |
597 | break; | ||
571 | 598 | ||
572 | msi_reject(_phone->_msi); | 599 | case 'q': { |
600 | INFO("Quitting!"); | ||
601 | pthread_exit(NULL); | ||
602 | } | ||
573 | 603 | ||
574 | INFO("Call Rejected..."); | 604 | default: { |
605 | INFO("Invalid command!"); | ||
606 | } | ||
607 | break; | ||
575 | 608 | ||
576 | } break; | ||
577 | case 'q': | ||
578 | { | ||
579 | INFO("Quitting!"); | ||
580 | pthread_exit(NULL); | ||
581 | } | 609 | } |
582 | default: | ||
583 | { | ||
584 | INFO("Invalid command!"); | ||
585 | } break; | ||
586 | 610 | ||
587 | } | 611 | usleep(1000); |
588 | usleep(1000); | ||
589 | } | 612 | } |
590 | 613 | ||
591 | pthread_exit(NULL); | 614 | pthread_exit(NULL); |
592 | } | 615 | } |
593 | 616 | ||
594 | int quitPhone(phone_t* _phone) | 617 | int quitPhone(phone_t *_phone) |
595 | { | 618 | { |
596 | if ( _phone->_msi->_call ){ | 619 | if ( _phone->_msi->_call ) { |
597 | msi_hangup(_phone->_msi); /* Hangup the phone first */ | 620 | msi_hangup(_phone->_msi); /* Hangup the phone first */ |
598 | } | 621 | } |
599 | 622 | ||
600 | msi_terminate_session(_phone->_msi); | 623 | msi_terminate_session(_phone->_msi); |
601 | pthread_mutex_destroy ( &_mutex ); | 624 | pthread_mutex_destroy ( &_mutex ); |
602 | 625 | ||
@@ -606,17 +629,17 @@ int quitPhone(phone_t* _phone) | |||
606 | 629 | ||
607 | /* ---------------------- */ | 630 | /* ---------------------- */ |
608 | 631 | ||
609 | int print_help ( const char* _name ) | 632 | int print_help ( const char *_name ) |
610 | { | 633 | { |
611 | printf ( "Usage: %s -m (mode) -r/s ( for setting the ports on test version )\n", _name ); | 634 | printf ( "Usage: %s -m (mode) -r/s ( for setting the ports on test version )\n", _name ); |
612 | return FAILURE; | 635 | return FAILURE; |
613 | } | 636 | } |
614 | 637 | ||
615 | int main ( int argc, char* argv [] ) | 638 | int main ( int argc, char *argv [] ) |
616 | { | 639 | { |
617 | arg_t* _args = parse_args ( argc, argv ); | 640 | arg_t *_args = parse_args ( argc, argv ); |
618 | 641 | ||
619 | const char* _mode = find_arg_duble ( _args, "-m" ); | 642 | const char *_mode = find_arg_duble ( _args, "-m" ); |
620 | uint16_t _listen_port; | 643 | uint16_t _listen_port; |
621 | uint16_t _send_port; | 644 | uint16_t _send_port; |
622 | 645 | ||
@@ -631,9 +654,9 @@ int main ( int argc, char* argv [] ) | |||
631 | _listen_port = 31000; | 654 | _listen_port = 31000; |
632 | } else return print_help ( argv[0] ); | 655 | } else return print_help ( argv[0] ); |
633 | 656 | ||
634 | phone_t* _phone = initPhone(_listen_port, _send_port); | 657 | phone_t *_phone = initPhone(_listen_port, _send_port); |
635 | 658 | ||
636 | if ( _phone ){ | 659 | if ( _phone ) { |
637 | phone_startmain_loop(_phone); | 660 | phone_startmain_loop(_phone); |
638 | 661 | ||
639 | quitPhone(_phone); | 662 | quitPhone(_phone); |
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 | ||
128 | void rtp_free_msg ( rtp_session_t* _session, struct rtp_msg_s* _msg ); | 128 | void rtp_free_msg ( rtp_session_t *_session, struct rtp_msg_s *_msg ); |
129 | int rtp_release_session_recv ( rtp_session_t* _session ); | 129 | int rtp_release_session_recv ( rtp_session_t *_session ); |
130 | 130 | ||
131 | /* Functions handling receiving */ | 131 | /* Functions handling receiving */ |
132 | struct rtp_msg_s* rtp_recv_msg ( rtp_session_t* _session ); | 132 | struct rtp_msg_s *rtp_recv_msg ( rtp_session_t *_session ); |
133 | void rtp_store_msg ( rtp_session_t* _session, struct rtp_msg_s* _msg ); | 133 | void 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 | */ |
139 | struct rtp_msg_s* rtp_msg_parse ( rtp_session_t* _session, const uint8_t* _data, uint32_t _length ); | 139 | struct rtp_msg_s *rtp_msg_parse ( rtp_session_t *_session, const uint8_t *_data, uint32_t _length ); |
140 | 140 | ||
141 | int rtp_check_late_message (rtp_session_t* _session, struct rtp_msg_s* _msg); | 141 | int rtp_check_late_message (rtp_session_t *_session, struct rtp_msg_s *_msg); |
142 | void rtp_register_msg ( rtp_session_t* _session, struct rtp_msg_s* ); | 142 | void rtp_register_msg ( rtp_session_t *_session, struct rtp_msg_s * ); |
143 | 143 | ||
144 | /* Functions handling sending */ | 144 | /* Functions handling sending */ |
145 | int rtp_send_msg ( rtp_session_t* _session, struct rtp_msg_s* _msg, void* _core_handler ); | 145 | int 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 | */ |
152 | struct rtp_msg_s* rtp_msg_new ( rtp_session_t* _session, const uint8_t* _data, uint32_t _length ); | 152 | struct 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 */ |
156 | struct rtp_header_s* rtp_build_header ( rtp_session_t* _session ); | 156 | struct 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 | */ |
166 | rtp_session_t* rtp_init_session ( int _max_users, int _multi_session ); | 166 | rtp_session_t *rtp_init_session ( int _max_users, int _multi_session ); |
167 | int rtp_terminate_session ( rtp_session_t* _session ); | 167 | int rtp_terminate_session ( rtp_session_t *_session ); |
168 | 168 | ||
169 | /* Adding receiver */ | 169 | /* Adding receiver */ |
170 | int rtp_add_receiver ( rtp_session_t* _session, tox_IP_Port* _dest ); | 170 | int 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 */ |
173 | int rtp_add_resolution_marking ( rtp_session_t* _session, uint16_t _width, uint16_t _height ); | 173 | int rtp_add_resolution_marking ( rtp_session_t *_session, uint16_t _width, uint16_t _height ); |
174 | int rtp_remove_resolution_marking ( rtp_session_t* _session ); | 174 | int rtp_remove_resolution_marking ( rtp_session_t *_session ); |
175 | uint16_t rtp_get_resolution_marking_height ( struct rtp_ext_header_s* _header, uint32_t _position ); | 175 | uint16_t rtp_get_resolution_marking_height ( struct rtp_ext_header_s *_header, uint32_t _position ); |
176 | uint16_t rtp_get_resolution_marking_width ( struct rtp_ext_header_s* _header, uint32_t _position ); | 176 | uint16_t rtp_get_resolution_marking_width ( struct rtp_ext_header_s *_header, uint32_t _position ); |
177 | 177 | ||
178 | int rtp_add_framerate_marking ( rtp_session_t* _session, uint32_t _value ); | 178 | int rtp_add_framerate_marking ( rtp_session_t *_session, uint32_t _value ); |
179 | int rtp_remove_framerate_marking ( rtp_session_t* _session ); | 179 | int rtp_remove_framerate_marking ( rtp_session_t *_session ); |
180 | uint32_t rtp_get_framerate_marking ( struct rtp_ext_header_s* _header ); | 180 | uint32_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 */ |
182 | void rtp_set_payload_type ( rtp_session_t* _session, uint8_t _payload_value ); | 182 | void rtp_set_payload_type ( rtp_session_t *_session, uint8_t _payload_value ); |
183 | uint32_t rtp_get_payload_type ( rtp_session_t* _session ); | 183 | uint32_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 */ |
186 | int rtp_set_prefix ( rtp_session_t* _session, uint8_t* _prefix, uint16_t _prefix_length ); | 186 | int 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 | ||
42 | static int _seed = 0; /* Not initiated */ | 41 | static int _seed = 0; /* Not initiated */ |
43 | 42 | ||
44 | int t_setipport ( const char* _ip, unsigned short _port, void* _dest ) | 43 | int 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 | ||
75 | void t_memcpy ( uint8_t* _dest, const uint8_t* _source, size_t _size ) | 74 | void 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 | ||
90 | uint8_t* t_memset ( uint8_t* _dest, uint8_t _valu, size_t _size ) | 89 | uint8_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 | ||
105 | size_t t_memlen ( const uint8_t* _valu) | 104 | size_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 | ||
115 | uint8_t* t_strallcpy ( const uint8_t* _source ) /* string alloc and copy */ | 114 | uint8_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 | ||
129 | size_t t_strfind ( const uint8_t* _str, const uint8_t* _substr ) | 128 | size_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 | ||
159 | struct timezone | 161 | struct 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 | ||
165 | int gettimeofday(struct timeval *tv, struct timezone *tz) | 166 | int 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 | ||