Fixed building on windows.

This commit is contained in:
irungentoo 2013-10-17 08:09:06 -04:00
parent 6391208ab3
commit bdbf4a3673
3 changed files with 289 additions and 267 deletions

View File

@ -14,13 +14,13 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <termios.h>
/* #include <termios.h> Can this be removed? */
#include <pthread.h>
#include "AV_codec.h"
void INFO (const char* _format, ...)
void INFO (const char *_format, ...)
{
printf("\r[!] ");
va_list _arg;
@ -31,13 +31,13 @@ void INFO (const char* _format, ...)
fflush(stdout);
}
int rtp_handlepacket ( void* _object, tox_IP_Port ip_port, uint8_t* data, uint32_t length )
int rtp_handlepacket ( void *_object, tox_IP_Port ip_port, uint8_t *data, uint32_t length )
{
phone_t* _phone = _object;
rtp_msg_t* _msg;
phone_t *_phone = _object;
rtp_msg_t *_msg;
uint8_t _payload_id;
if ( _phone->_msi->_call && _phone->_msi->_call->_state == call_active ){
if ( _phone->_msi->_call && _phone->_msi->_call->_state == call_active ) {
_msg = rtp_msg_parse ( NULL, data + 1, length - 1 ); /* ignore marker byte */
@ -55,10 +55,10 @@ int rtp_handlepacket ( void* _object, tox_IP_Port ip_port, uint8_t* data, uint32
return SUCCESS;
}
int msi_handlepacket ( void* _object, tox_IP_Port ip_port, uint8_t* data, uint32_t length )
int msi_handlepacket ( void *_object, tox_IP_Port ip_port, uint8_t *data, uint32_t length )
{
msi_session_t* _session = _object;
msi_msg_t* _msg;
msi_session_t *_session = _object;
msi_msg_t *_msg;
_msg = msi_parse_msg ( data + 1 ); /* ignore marker byte */
@ -75,9 +75,9 @@ int msi_handlepacket ( void* _object, tox_IP_Port ip_port, uint8_t* data, uint32
return SUCCESS;
}
void* phone_receivepacket ( void* _phone_p )
void *phone_receivepacket ( void *_phone_p )
{
phone_t* _phone = _phone_p;
phone_t *_phone = _phone_p;
networking_registerhandler(_phone->_networking, MSI_PACKET, msi_handlepacket, _phone->_msi);
@ -94,31 +94,31 @@ void* phone_receivepacket ( void* _phone_p )
/* Media transport callback */
typedef struct hmtc_args_s {
rtp_session_t** _rtp_audio;
rtp_session_t** _rtp_video;
call_type* _local_type_call;
call_state* _this_call;
rtp_session_t **_rtp_audio;
rtp_session_t **_rtp_video;
call_type *_local_type_call;
call_state *_this_call;
void *_core_handler;
} hmtc_args_t;
void* phone_handle_media_transport_poll ( void* _hmtc_args_p )
void *phone_handle_media_transport_poll ( void *_hmtc_args_p )
{
rtp_msg_t* _audio_msg, * _video_msg;
rtp_msg_t *_audio_msg, * _video_msg;
hmtc_args_t* _hmtc_args = _hmtc_args_p;
hmtc_args_t *_hmtc_args = _hmtc_args_p;
rtp_session_t* _rtp_audio = *_hmtc_args->_rtp_audio;
rtp_session_t* _rtp_video = *_hmtc_args->_rtp_video;
rtp_session_t *_rtp_audio = *_hmtc_args->_rtp_audio;
rtp_session_t *_rtp_video = *_hmtc_args->_rtp_video;
call_type* _type = _hmtc_args->_local_type_call;
void* _core_handler = _hmtc_args->_core_handler;
call_type *_type = _hmtc_args->_local_type_call;
void *_core_handler = _hmtc_args->_core_handler;
call_state* _this_call = _hmtc_args->_this_call;
call_state *_this_call = _hmtc_args->_this_call;
while ( *_this_call == call_active ) {
// THREADLOCK()
// THREADLOCK()
_audio_msg = rtp_recv_msg ( _rtp_audio );
_video_msg = rtp_recv_msg ( _rtp_video );
@ -139,14 +139,15 @@ void* phone_handle_media_transport_poll ( void* _hmtc_args_p )
rtp_free_msg ( _rtp_video, _video_msg );
_video_msg = NULL;
}
/* -------------------- */
_audio_msg = rtp_msg_new ( _rtp_audio, (const uint8_t*)"audio\0", 6 ) ;
_audio_msg = rtp_msg_new ( _rtp_audio, (const uint8_t *)"audio\0", 6 ) ;
rtp_send_msg ( _rtp_audio, _audio_msg, _core_handler );
_audio_msg = NULL;
if ( *_type == type_video ){ /* if local call send video */
_video_msg = rtp_msg_new ( _rtp_video, (const uint8_t*)"video\0", 6 ) ;
if ( *_type == type_video ) { /* if local call send video */
_video_msg = rtp_msg_new ( _rtp_video, (const uint8_t *)"video\0", 6 ) ;
rtp_send_msg ( _rtp_video, _video_msg, _core_handler );
_video_msg = NULL;
}
@ -159,7 +160,7 @@ void* phone_handle_media_transport_poll ( void* _hmtc_args_p )
//THREADLOCK()
if ( _audio_msg ){
if ( _audio_msg ) {
rtp_free_msg(_rtp_audio, _audio_msg);
}
@ -185,9 +186,9 @@ void* phone_handle_media_transport_poll ( void* _hmtc_args_p )
pthread_exit ( NULL );
}
pthread_t phone_startmedia_loop ( phone_t* _phone )
pthread_t phone_startmedia_loop ( phone_t *_phone )
{
if ( !_phone ){
if ( !_phone ) {
return 0;
}
@ -207,10 +208,10 @@ pthread_t phone_startmedia_loop ( phone_t* _phone )
rtp_set_prefix ( _phone->_rtp_video, &_prefix, 1 );
rtp_add_receiver ( _phone->_rtp_video, &_phone->_msi->_friend_id );
rtp_set_payload_type(_phone->_rtp_video, _PAYLOAD_VP8);
hmtc_args_t* rtp_targs = calloc(sizeof(hmtc_args_t),1);
hmtc_args_t *rtp_targs = calloc(sizeof(hmtc_args_t), 1);
rtp_targs->_rtp_audio = &_phone->_rtp_audio;
@ -220,26 +221,29 @@ pthread_t phone_startmedia_loop ( phone_t* _phone )
rtp_targs->_core_handler = _phone->_networking;
codec_state *cs;
cs=_phone->cs;
cs = _phone->cs;
//_status = pthread_create ( &_rtp_tid, NULL, phone_handle_media_transport_poll, rtp_targs );
cs->_rtp_audio=_phone->_rtp_audio;
cs->_rtp_video=_phone->_rtp_video;
cs->_networking=_phone->_networking;
cs->socket=_phone->_tox_sock;
cs->_rtp_audio = _phone->_rtp_audio;
cs->_rtp_video = _phone->_rtp_video;
cs->_networking = _phone->_networking;
cs->socket = _phone->_tox_sock;
cs->quit = 0;
printf("support: %d %d\n",cs->support_send_audio,cs->support_send_video);
if(cs->support_send_audio&&cs->support_send_video) /* quick fix */
pthread_create(&_phone->cs->encode_audio_thread, NULL, encode_audio_thread, _phone->cs);
if(cs->support_receive_audio)
pthread_create(&_phone->cs->decode_audio_thread, NULL, decode_audio_thread, _phone->cs);
if(cs->support_send_video)
pthread_create(&_phone->cs->encode_video_thread, NULL, encode_video_thread, _phone->cs);
if(cs->support_receive_video)
pthread_create(&_phone->cs->decode_video_thread, NULL, decode_video_thread, _phone->cs);
//
printf("support: %d %d\n", cs->support_send_audio, cs->support_send_video);
if (cs->support_send_audio && cs->support_send_video) /* quick fix */
pthread_create(&_phone->cs->encode_audio_thread, NULL, encode_audio_thread, _phone->cs);
if (cs->support_receive_audio)
pthread_create(&_phone->cs->decode_audio_thread, NULL, decode_audio_thread, _phone->cs);
if (cs->support_send_video)
pthread_create(&_phone->cs->encode_video_thread, NULL, encode_video_thread, _phone->cs);
if (cs->support_receive_video)
pthread_create(&_phone->cs->decode_video_thread, NULL, decode_video_thread, _phone->cs);
//
return 1;
@ -252,20 +256,21 @@ pthread_t phone_startmedia_loop ( phone_t* _phone )
MCBTYPE callback_recv_invite ( MCBARGS )
{
const char* _call_type;
const char *_call_type;
msi_session_t* _msi = _arg;
msi_session_t *_msi = _arg;
/* Get the last one */
call_type _type = _msi->_call->_type_peer[_msi->_call->_participants - 1];
switch ( _type ){
case type_audio:
_call_type = "audio";
break;
case type_video:
_call_type = "video";
break;
switch ( _type ) {
case type_audio:
_call_type = "audio";
break;
case type_video:
_call_type = "video";
break;
}
INFO( "Incoming %s call!", _call_type );
@ -281,8 +286,9 @@ MCBTYPE callback_recv_ringing ( MCBARGS )
}
MCBTYPE callback_recv_starting ( MCBARGS )
{
msi_session_t* _session = _arg;
if ( !phone_startmedia_loop(_session->_agent_handler) ){
msi_session_t *_session = _arg;
if ( !phone_startmedia_loop(_session->_agent_handler) ) {
INFO("Starting call failed!");
} else {
INFO ("Call started! ( press h to hangup )");
@ -290,34 +296,40 @@ MCBTYPE callback_recv_starting ( MCBARGS )
}
MCBTYPE callback_recv_ending ( MCBARGS )
{
msi_session_t* _session = _arg;
phone_t * _phone = _session->_agent_handler;
_phone->cs->quit=1;
if(_phone->cs->encode_video_thread)
pthread_join(_phone->cs->encode_video_thread,NULL);
if(_phone->cs->encode_audio_thread)
pthread_join(_phone->cs->encode_audio_thread,NULL);
if(_phone->cs->decode_audio_thread)
pthread_join(_phone->cs->decode_audio_thread,NULL);
if(_phone->cs->decode_video_thread)
pthread_join(_phone->cs->decode_video_thread,NULL);
msi_session_t *_session = _arg;
phone_t *_phone = _session->_agent_handler;
_phone->cs->quit = 1;
if (_phone->cs->encode_video_thread)
pthread_join(_phone->cs->encode_video_thread, NULL);
if (_phone->cs->encode_audio_thread)
pthread_join(_phone->cs->encode_audio_thread, NULL);
if (_phone->cs->decode_audio_thread)
pthread_join(_phone->cs->decode_audio_thread, NULL);
if (_phone->cs->decode_video_thread)
pthread_join(_phone->cs->decode_video_thread, NULL);
SDL_Quit();
printf("all A/V threads successfully shut down\n");
INFO ( "Call ended!" );
}
MCBTYPE callback_recv_error ( MCBARGS )
{
msi_session_t* _session = _arg;
msi_session_t *_session = _arg;
INFO( "Error: %s", _session->_last_error_str );
}
MCBTYPE callback_call_started ( MCBARGS )
{
msi_session_t* _session = _arg;
if ( !phone_startmedia_loop(_session->_agent_handler) ){
msi_session_t *_session = _arg;
if ( !phone_startmedia_loop(_session->_agent_handler) ) {
INFO("Starting call failed!");
} else {
INFO ("Call started! ( press h to hangup )");
@ -334,21 +346,26 @@ MCBTYPE callback_call_rejected ( MCBARGS )
}
MCBTYPE callback_call_ended ( MCBARGS )
{
msi_session_t* _session = _arg;
phone_t * _phone = _session->_agent_handler;
_phone->cs->quit=1;
if(_phone->cs->encode_video_thread)
pthread_join(_phone->cs->encode_video_thread,NULL);
if(_phone->cs->encode_audio_thread)
pthread_join(_phone->cs->encode_audio_thread,NULL);
if(_phone->cs->decode_audio_thread)
pthread_join(_phone->cs->decode_audio_thread,NULL);
if(_phone->cs->decode_video_thread)
pthread_join(_phone->cs->decode_video_thread,NULL);
msi_session_t *_session = _arg;
phone_t *_phone = _session->_agent_handler;
_phone->cs->quit = 1;
if (_phone->cs->encode_video_thread)
pthread_join(_phone->cs->encode_video_thread, NULL);
if (_phone->cs->encode_audio_thread)
pthread_join(_phone->cs->encode_audio_thread, NULL);
if (_phone->cs->decode_audio_thread)
pthread_join(_phone->cs->decode_audio_thread, NULL);
if (_phone->cs->decode_video_thread)
pthread_join(_phone->cs->decode_video_thread, NULL);
SDL_Quit();
printf("all A/V threads successfully shut down\n");
INFO ( "Call ended!" );
}
@ -358,10 +375,10 @@ MCBTYPE callback_requ_timeout ( MCBARGS )
}
phone_t* initPhone(uint16_t _listen_port, uint16_t _send_port)
phone_t *initPhone(uint16_t _listen_port, uint16_t _send_port)
{
phone_t* _retu = calloc(sizeof(phone_t),1);
_retu->cs = av_calloc(sizeof(codec_state),1);
phone_t *_retu = calloc(sizeof(phone_t), 1);
_retu->cs = av_calloc(sizeof(codec_state), 1);
/* Initialize our mutex */
pthread_mutex_init ( &_mutex, NULL );
@ -388,13 +405,13 @@ phone_t* initPhone(uint16_t _listen_port, uint16_t _send_port)
/* Initialize msi */
_retu->_msi = msi_init_session ( _retu->_networking, (const uint8_t*)_USERAGENT );
_retu->_msi = msi_init_session ( _retu->_networking, (const uint8_t *)_USERAGENT );
if ( !_retu->_msi ) {
fprintf ( stderr, "msi_init_session() failed\n" );
return NULL;
}
/* Initiate codecs */
init_encoder(_retu->cs);
init_decoder(_retu->cs);
@ -425,7 +442,7 @@ phone_t* initPhone(uint16_t _listen_port, uint16_t _send_port)
return _retu;
}
pthread_t phone_startmain_loop(phone_t* _phone)
pthread_t phone_startmain_loop(phone_t *_phone)
{
int _status;
/* Start receive thread */
@ -461,9 +478,9 @@ pthread_t phone_startmain_loop(phone_t* _phone)
return _phone_loop_thread;
}
void* phone_poll ( void* _p_phone )
void *phone_poll ( void *_p_phone )
{
phone_t* _phone = _p_phone;
phone_t *_phone = _p_phone;
int _status = SUCCESS;
@ -482,121 +499,127 @@ void* phone_poll ( void* _p_phone )
"r (reject incoming call)\n"
"q (quit)\n"
"================================================================================"
);
);
while ( 1 )
{
while ( 1 ) {
fgets(_line, sizeof(_line), stdin);
int i;
int i;
for (i = 0; i < 100; i++) {
if (_line[i] == '\n') {
_line[i] = '\0';
}
}
_len = strlen(_line);
if ( !_len ){
printf(" >> "); fflush(stdout);
if ( !_len ) {
printf(" >> ");
fflush(stdout);
continue;
}
if ( _len > 1 && _line[1] != ' ' && _line[1] != '\n' ){
if ( _len > 1 && _line[1] != ' ' && _line[1] != '\n' ) {
INFO("Invalid input!");
continue;
}
switch (_line[0]){
switch (_line[0]) {
case 'c':
{
if ( _phone->_msi->_call ){
INFO("Already in a call");
break;
case 'c': {
if ( _phone->_msi->_call ) {
INFO("Already in a call");
break;
}
call_type _ctype;
if ( _len < 11 ) {
INFO("Invalid input; usage: c a/v 0.0.0.0");
break;
} else if ( _line[2] == 'a' || _line[2] != 'v' ) { /* default and audio */
_ctype = type_audio;
} else { /* video */
_ctype = type_video;
}
strcpy(_dest, _line + 4 );
_status = t_setipport(_dest, _phone->_send_port, &(_phone->_msi->_friend_id));
if ( _status < 0 ) {
INFO("Could not resolve address!");
} else {
/* Set timeout */
msi_invite ( _phone->_msi, _ctype, 30 * 1000 );
INFO("Calling!");
}
t_memset((uint8_t *)_dest, '\0', 17);
}
break;
case 'h': {
if ( !_phone->_msi->_call ) {
break;
}
msi_hangup(_phone->_msi);
INFO("Hung up...");
}
break;
case 'a': {
if ( _phone->_msi->_call && _phone->_msi->_call->_state != call_starting ) {
break;
}
if ( _len > 1 && _line[2] == 'v' )
msi_answer(_phone->_msi, type_video);
else
msi_answer(_phone->_msi, type_audio);
}
break;
case 'r': {
if ( _phone->_msi->_call && _phone->_msi->_call->_state != call_starting ) {
break;
}
msi_reject(_phone->_msi);
INFO("Call Rejected...");
}
break;
case 'q': {
INFO("Quitting!");
pthread_exit(NULL);
}
call_type _ctype;
if ( _len < 11 ){
INFO("Invalid input; usage: c a/v 0.0.0.0");
break;
default: {
INFO("Invalid command!");
}
else if ( _line[2] == 'a' || _line[2] != 'v' ){ /* default and audio */
_ctype = type_audio;
}
else { /* video */
_ctype = type_video;
}
strcpy(_dest, _line + 4 );
_status = t_setipport(_dest, _phone->_send_port, &(_phone->_msi->_friend_id));
if ( _status < 0 ){
INFO("Could not resolve address!");
} else {
/* Set timeout */
msi_invite ( _phone->_msi, _ctype, 30 * 1000 );
INFO("Calling!");
}
t_memset((uint8_t*)_dest, '\0', 17);
} break;
case 'h':
{
if ( !_phone->_msi->_call ){
break;
}
msi_hangup(_phone->_msi);
INFO("Hung up...");
} break;
case 'a':
{
if ( _phone->_msi->_call && _phone->_msi->_call->_state != call_starting ) {
break;
}
if ( _len > 1 && _line[2] == 'v' )
msi_answer(_phone->_msi, type_video);
else
msi_answer(_phone->_msi, type_audio);
} break;
case 'r':
{
if ( _phone->_msi->_call && _phone->_msi->_call->_state != call_starting ){
break;
}
msi_reject(_phone->_msi);
INFO("Call Rejected...");
} break;
case 'q':
{
INFO("Quitting!");
pthread_exit(NULL);
}
default:
{
INFO("Invalid command!");
} break;
break;
}
usleep(1000);
usleep(1000);
}
pthread_exit(NULL);
}
int quitPhone(phone_t* _phone)
int quitPhone(phone_t *_phone)
{
if ( _phone->_msi->_call ){
if ( _phone->_msi->_call ) {
msi_hangup(_phone->_msi); /* Hangup the phone first */
}
msi_terminate_session(_phone->_msi);
pthread_mutex_destroy ( &_mutex );
@ -606,17 +629,17 @@ int quitPhone(phone_t* _phone)
/* ---------------------- */
int print_help ( const char* _name )
int print_help ( const char *_name )
{
printf ( "Usage: %s -m (mode) -r/s ( for setting the ports on test version )\n", _name );
return FAILURE;
}
int main ( int argc, char* argv [] )
int main ( int argc, char *argv [] )
{
arg_t* _args = parse_args ( argc, argv );
arg_t *_args = parse_args ( argc, argv );
const char* _mode = find_arg_duble ( _args, "-m" );
const char *_mode = find_arg_duble ( _args, "-m" );
uint16_t _listen_port;
uint16_t _send_port;
@ -631,9 +654,9 @@ int main ( int argc, char* argv [] )
_listen_port = 31000;
} else return print_help ( argv[0] );
phone_t* _phone = initPhone(_listen_port, _send_port);
phone_t *_phone = initPhone(_listen_port, _send_port);
if ( _phone ){
if ( _phone ) {
phone_startmain_loop(_phone);
quitPhone(_phone);

View File

@ -31,7 +31,7 @@
#define RTP_VERSION 2
#include <inttypes.h>
#include "../toxcore/tox.h"
#include <pthread.h>
/* Extension header flags */
#define RTP_EXT_TYPE_RESOLUTION 0x01
#define RTP_EXT_TYPE_FRAMERATE 0x02
@ -72,7 +72,7 @@ typedef struct rtp_session_s {
uint32_t _time_elapsed;
uint32_t _current_timestamp;
uint32_t _ssrc;
uint32_t* _csrc;
uint32_t *_csrc;
/* If some additional data must be sent via message
@ -80,7 +80,7 @@ typedef struct rtp_session_s {
* automatically placing it within a message.
*/
struct rtp_ext_header_s* _ext_header;
struct rtp_ext_header_s *_ext_header;
/* External header identifiers */
int _exthdr_resolution;
int _exthdr_framerate;
@ -95,16 +95,16 @@ typedef struct rtp_session_s {
uint64_t _packet_loss;
const char* _last_error;
const char *_last_error;
struct rtp_dest_list_s* _dest_list;
struct rtp_dest_list_s* _last_user; /* a tail for faster appending */
struct rtp_dest_list_s *_dest_list;
struct rtp_dest_list_s *_last_user; /* a tail for faster appending */
struct rtp_msg_s* _oldest_msg;
struct rtp_msg_s* _last_msg; /* tail */
struct rtp_msg_s *_oldest_msg;
struct rtp_msg_s *_last_msg; /* tail */
uint16_t _prefix_length;
uint8_t* _prefix;
uint8_t *_prefix;
/* Specifies multiple session use.
* When using one session it uses default value ( -1 )
@ -125,35 +125,35 @@ typedef struct rtp_session_s {
*/
void rtp_free_msg ( rtp_session_t* _session, struct rtp_msg_s* _msg );
int rtp_release_session_recv ( rtp_session_t* _session );
void rtp_free_msg ( rtp_session_t *_session, struct rtp_msg_s *_msg );
int rtp_release_session_recv ( rtp_session_t *_session );
/* Functions handling receiving */
struct rtp_msg_s* rtp_recv_msg ( rtp_session_t* _session );
void rtp_store_msg ( rtp_session_t* _session, struct rtp_msg_s* _msg );
struct rtp_msg_s *rtp_recv_msg ( rtp_session_t *_session );
void rtp_store_msg ( rtp_session_t *_session, struct rtp_msg_s *_msg );
/*
* rtp_msg_parse() stores headers separately from the payload data
* and so the _length variable is set accordingly
*/
struct rtp_msg_s* rtp_msg_parse ( rtp_session_t* _session, const uint8_t* _data, uint32_t _length );
struct rtp_msg_s *rtp_msg_parse ( rtp_session_t *_session, const uint8_t *_data, uint32_t _length );
int rtp_check_late_message (rtp_session_t* _session, struct rtp_msg_s* _msg);
void rtp_register_msg ( rtp_session_t* _session, struct rtp_msg_s* );
int rtp_check_late_message (rtp_session_t *_session, struct rtp_msg_s *_msg);
void rtp_register_msg ( rtp_session_t *_session, struct rtp_msg_s * );
/* Functions handling sending */
int rtp_send_msg ( rtp_session_t* _session, struct rtp_msg_s* _msg, void* _core_handler );
int rtp_send_msg ( rtp_session_t *_session, struct rtp_msg_s *_msg, void *_core_handler );
/*
* rtp_msg_new() stores headers and payload data in one container ( _data )
* and the _length is set accordingly. Returned message is used for sending only
* so there is not much use of the headers there
*/
struct rtp_msg_s* rtp_msg_new ( rtp_session_t* _session, const uint8_t* _data, uint32_t _length );
struct rtp_msg_s *rtp_msg_new ( rtp_session_t *_session, const uint8_t *_data, uint32_t _length );
/* Convenient functions for creating a header */
struct rtp_header_s* rtp_build_header ( rtp_session_t* _session );
struct rtp_header_s *rtp_build_header ( rtp_session_t *_session );
/* Functions handling session control */
@ -163,26 +163,26 @@ struct rtp_header_s* rtp_build_header ( rtp_session_t* _session );
/* Session initiation and termination.
* Set _multi_session to -1 if not using multiple sessions
*/
rtp_session_t* rtp_init_session ( int _max_users, int _multi_session );
int rtp_terminate_session ( rtp_session_t* _session );
rtp_session_t *rtp_init_session ( int _max_users, int _multi_session );
int rtp_terminate_session ( rtp_session_t *_session );
/* Adding receiver */
int rtp_add_receiver ( rtp_session_t* _session, tox_IP_Port* _dest );
int rtp_add_receiver ( rtp_session_t *_session, tox_IP_Port *_dest );
/* Convenient functions for marking the resolution */
int rtp_add_resolution_marking ( rtp_session_t* _session, uint16_t _width, uint16_t _height );
int rtp_remove_resolution_marking ( rtp_session_t* _session );
uint16_t rtp_get_resolution_marking_height ( struct rtp_ext_header_s* _header, uint32_t _position );
uint16_t rtp_get_resolution_marking_width ( struct rtp_ext_header_s* _header, uint32_t _position );
int rtp_add_resolution_marking ( rtp_session_t *_session, uint16_t _width, uint16_t _height );
int rtp_remove_resolution_marking ( rtp_session_t *_session );
uint16_t rtp_get_resolution_marking_height ( struct rtp_ext_header_s *_header, uint32_t _position );
uint16_t rtp_get_resolution_marking_width ( struct rtp_ext_header_s *_header, uint32_t _position );
int rtp_add_framerate_marking ( rtp_session_t* _session, uint32_t _value );
int rtp_remove_framerate_marking ( rtp_session_t* _session );
uint32_t rtp_get_framerate_marking ( struct rtp_ext_header_s* _header );
int rtp_add_framerate_marking ( rtp_session_t *_session, uint32_t _value );
int rtp_remove_framerate_marking ( rtp_session_t *_session );
uint32_t rtp_get_framerate_marking ( struct rtp_ext_header_s *_header );
/* Convenient functions for marking the payload */
void rtp_set_payload_type ( rtp_session_t* _session, uint8_t _payload_value );
uint32_t rtp_get_payload_type ( rtp_session_t* _session );
void rtp_set_payload_type ( rtp_session_t *_session, uint8_t _payload_value );
uint32_t rtp_get_payload_type ( rtp_session_t *_session );
/* When using RTP in core be sure to set prefix when sending via rtp_send_msg */
int rtp_set_prefix ( rtp_session_t* _session, uint8_t* _prefix, uint16_t _prefix_length );
int rtp_set_prefix ( rtp_session_t *_session, uint8_t *_prefix, uint16_t _prefix_length );
#endif /* _RTP__IMPL_H_ */

View File

@ -31,7 +31,6 @@
#include "toxrtp_helper.h"
#include "../toxcore/network.h"
#include <arpa/inet.h> /* Fixes implicit function warning. */
#include <assert.h>
#ifdef WIN
@ -41,11 +40,11 @@
static int _seed = 0; /* Not initiated */
int t_setipport ( const char* _ip, unsigned short _port, void* _dest )
int t_setipport ( const char *_ip, unsigned short _port, void *_dest )
{
assert(_dest);
IP_Port* _dest_c = ( IP_Port* ) _dest;
IP_Port *_dest_c = ( IP_Port * ) _dest;
ip_init(&_dest_c->ip, 0);
IP_Port _ipv6_garbage;
@ -72,7 +71,7 @@ uint32_t t_random ( uint32_t _max )
}
}
void t_memcpy ( uint8_t* _dest, const uint8_t* _source, size_t _size )
void t_memcpy ( uint8_t *_dest, const uint8_t *_source, size_t _size )
{
/*
* Using countdown to zero method
@ -87,7 +86,7 @@ void t_memcpy ( uint8_t* _dest, const uint8_t* _source, size_t _size )
}
uint8_t* t_memset ( uint8_t* _dest, uint8_t _valu, size_t _size )
uint8_t *t_memset ( uint8_t *_dest, uint8_t _valu, size_t _size )
{
/*
* Again using countdown to zero method
@ -102,9 +101,9 @@ uint8_t* t_memset ( uint8_t* _dest, uint8_t _valu, size_t _size )
return _dest;
}
size_t t_memlen ( const uint8_t* _valu)
size_t t_memlen ( const uint8_t *_valu)
{
const uint8_t* _it;
const uint8_t *_it;
size_t _retu = 0;
for ( _it = _valu; *_it; ++_it ) ++_retu;
@ -112,13 +111,13 @@ size_t t_memlen ( const uint8_t* _valu)
return _retu;
}
uint8_t* t_strallcpy ( const uint8_t* _source ) /* string alloc and copy */
uint8_t *t_strallcpy ( const uint8_t *_source ) /* string alloc and copy */
{
assert(_source);
size_t _length = t_memlen(_source) + 1; /* make space for null character */
uint8_t* _dest = calloc( sizeof ( uint8_t ), _length );
uint8_t *_dest = calloc( sizeof ( uint8_t ), _length );
assert(_dest);
t_memcpy(_dest, _source, _length);
@ -126,75 +125,75 @@ uint8_t* t_strallcpy ( const uint8_t* _source ) /* string alloc and copy */
return _dest;
}
size_t t_strfind ( const uint8_t* _str, const uint8_t* _substr )
size_t t_strfind ( const uint8_t *_str, const uint8_t *_substr )
{
size_t _pos = 0;
size_t _it, _delit = 0;
for ( _it = 0; _str[_it] != '\0'; _it++ ){
if ( _str[_it] == _substr[_delit] ){
for ( _it = 0; _str[_it] != '\0'; _it++ ) {
if ( _str[_it] == _substr[_delit] ) {
_pos = _it;
while ( _str[_it] == _substr[_delit] && _str[_it] != '\0' ){
while ( _str[_it] == _substr[_delit] && _str[_it] != '\0' ) {
_it ++;
_delit++;
if ( _substr[_delit] == '\0' ){
if ( _substr[_delit] == '\0' ) {
return _pos;
}
}
_delit = 0;
_pos = 0;
}
}
return _pos;
}
#ifdef WIN
#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
#else
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
#endif
struct timezone
{
int tz_minuteswest; /* minutes W of Greenwich */
int tz_dsttime; /* type of dst correction */
struct timezone {
int tz_minuteswest; /* minutes W of Greenwich */
int tz_dsttime; /* type of dst correction */
};
int gettimeofday(struct timeval *tv, struct timezone *tz)
{
FILETIME ft;
unsigned __int64 tmpres = 0;
static int tzflag;
FILETIME ft;
unsigned __int64 tmpres = 0;
static int tzflag;
if (NULL != tv)
{
GetSystemTimeAsFileTime(&ft);
if (NULL != tv) {
GetSystemTimeAsFileTime(&ft);
tmpres |= ft.dwHighDateTime;
tmpres <<= 32;
tmpres |= ft.dwLowDateTime;
tmpres |= ft.dwHighDateTime;
tmpres <<= 32;
tmpres |= ft.dwLowDateTime;
/*converting file time to unix epoch*/
tmpres -= DELTA_EPOCH_IN_MICROSECS;
tmpres /= 10; /*convert into microseconds*/
tv->tv_sec = (long)(tmpres / 1000000UL);
tv->tv_usec = (long)(tmpres % 1000000UL);
}
if (NULL != tz)
{
if (!tzflag)
{
_tzset();
tzflag++;
/*converting file time to unix epoch*/
tmpres -= DELTA_EPOCH_IN_MICROSECS;
tmpres /= 10; /*convert into microseconds*/
tv->tv_sec = (long)(tmpres / 1000000UL);
tv->tv_usec = (long)(tmpres % 1000000UL);
}
tz->tz_minuteswest = _timezone / 60;
tz->tz_dsttime = _daylight;
}
return 0;
if (NULL != tz) {
if (!tzflag) {
_tzset();
tzflag++;
}
tz->tz_minuteswest = _timezone / 60;
tz->tz_dsttime = _daylight;
}
return 0;
}
#endif /* WIN */