This works.

This commit is contained in:
mannol 2014-05-16 19:56:40 +02:00
parent 9bb910a370
commit 843171fbc8
12 changed files with 185 additions and 214 deletions

View File

@ -58,7 +58,7 @@ void accept_friend_request(Tox *m, uint8_t *public_key, uint8_t *data, uint16_t
/******************************************************************************/
void callback_recv_invite ( uint32_t call_index, void *_arg )
void callback_recv_invite ( int32_t call_index, void *_arg )
{
Status *cast = _arg;
@ -66,14 +66,14 @@ void callback_recv_invite ( uint32_t call_index, void *_arg )
cast->Bob.status = Ringing;
cast->Bob.call_index = call_index;
}
void callback_recv_ringing ( uint32_t call_index, void *_arg )
void callback_recv_ringing ( int32_t call_index, void *_arg )
{
Status *cast = _arg;
/* Alice always sends invite */
cast->Alice.status = Ringing;
}
void callback_recv_starting ( uint32_t call_index, void *_arg )
void callback_recv_starting ( int32_t call_index, void *_arg )
{
Status *cast = _arg;
@ -82,7 +82,7 @@ void callback_recv_starting ( uint32_t call_index, void *_arg )
cast->Alice.status = InCall;
toxav_prepare_transmission(cast->Alice.av, call_index, &muhcaps, 1);
}
void callback_recv_ending ( uint32_t call_index, void *_arg )
void callback_recv_ending ( int32_t call_index, void *_arg )
{
Status *cast = _arg;
@ -95,12 +95,12 @@ void callback_recv_ending ( uint32_t call_index, void *_arg )
}
}
void callback_recv_error ( uint32_t call_index, void *_arg )
void callback_recv_error ( int32_t call_index, void *_arg )
{
ck_assert_msg(0, "AV internal error");
}
void callback_call_started ( uint32_t call_index, void *_arg )
void callback_call_started ( int32_t call_index, void *_arg )
{
Status *cast = _arg;
@ -109,14 +109,14 @@ void callback_call_started ( uint32_t call_index, void *_arg )
cast->Bob.status = InCall;
toxav_prepare_transmission(cast->Bob.av, call_index, &muhcaps, 1);
}
void callback_call_canceled ( uint32_t call_index, void *_arg )
void callback_call_canceled ( int32_t call_index, void *_arg )
{
Status *cast = _arg;
printf ( "Call Canceled for Bob!\n" );
cast->Bob.status = Cancel;
}
void callback_call_rejected ( uint32_t call_index, void *_arg )
void callback_call_rejected ( int32_t call_index, void *_arg )
{
Status *cast = _arg;
@ -125,7 +125,7 @@ void callback_call_rejected ( uint32_t call_index, void *_arg )
/* If Bob rejects, call is ended for alice and she sends ending */
cast->Alice.status = Rejected;
}
void callback_call_ended ( uint32_t call_index, void *_arg )
void callback_call_ended ( int32_t call_index, void *_arg )
{
Status *cast = _arg;
@ -133,7 +133,7 @@ void callback_call_ended ( uint32_t call_index, void *_arg )
cast->Bob.status = Ended;
}
void callback_requ_timeout ( uint32_t call_index, void *_arg )
void callback_requ_timeout ( int32_t call_index, void *_arg )
{
ck_assert_msg(0, "No answer!");
}

View File

@ -60,62 +60,62 @@ void accept_friend_request(Tox *m, uint8_t *public_key, uint8_t *data, uint16_t
/******************************************************************************/
void callback_recv_invite ( uint32_t call_index, void *_arg )
void callback_recv_invite ( int32_t call_index, void *_arg )
{/*
Status *cast = _arg;
cast->calls[call_index].Callee.status = Ringing;*/
}
void callback_recv_ringing ( uint32_t call_index, void *_arg )
void callback_recv_ringing ( int32_t call_index, void *_arg )
{
Status *cast = _arg;
cast->calls[call_index].Caller.status = Ringing;
}
void callback_recv_starting ( uint32_t call_index, void *_arg )
void callback_recv_starting ( int32_t call_index, void *_arg )
{
Status *cast = _arg;
cast->calls[call_index].Caller.status = InCall;
}
void callback_recv_ending ( uint32_t call_index, void *_arg )
void callback_recv_ending ( int32_t call_index, void *_arg )
{
Status *cast = _arg;
cast->calls[call_index].Caller.status = Ended;
}
void callback_recv_error ( uint32_t call_index, void *_arg )
void callback_recv_error ( int32_t call_index, void *_arg )
{
ck_assert_msg(0, "AV internal error");
}
void callback_call_started ( uint32_t call_index, void *_arg )
void callback_call_started ( int32_t call_index, void *_arg )
{/*
Status *cast = _arg;
cast->calls[call_index].Callee.status = InCall;*/
}
void callback_call_canceled ( uint32_t call_index, void *_arg )
void callback_call_canceled ( int32_t call_index, void *_arg )
{/*
Status *cast = _arg;
cast->calls[call_index].Callee.status = Cancel;*/
}
void callback_call_rejected ( uint32_t call_index, void *_arg )
void callback_call_rejected ( int32_t call_index, void *_arg )
{
Status *cast = _arg;
cast->calls[call_index].Caller.status = Rejected;
}
void callback_call_ended ( uint32_t call_index, void *_arg )
void callback_call_ended ( int32_t call_index, void *_arg )
{/*
Status *cast = _arg;
cast->calls[call_index].Callee.status = Ended;*/
}
void callback_requ_timeout ( uint32_t call_index, void *_arg )
void callback_requ_timeout ( int32_t call_index, void *_arg )
{
ck_assert_msg(0, "No answer!");
}

View File

@ -71,10 +71,7 @@ JitterBuffer *create_queue(int capacity)
void terminate_queue(JitterBuffer* q)
{
int i;
for ( i = 0; i < q->capacity; i ++ ) {
rtp_free_msg(NULL, q->queue[i]);
}
empty_queue(q);
free(q->queue);
free(q);
}

View File

@ -122,7 +122,7 @@ static struct _Callbacks {
void* data;
} callbacks[11] = {0};
inline__ void invoke_callback(uint32_t call_index, MSICallbackID id)
inline__ void invoke_callback(int32_t call_index, MSICallbackID id)
{
/*if ( callbacks[id].function ) event.rise ( callbacks[id].function, callbacks[id].data );*/
if ( callbacks[id].function ) {
@ -209,18 +209,7 @@ static inline__ const uint8_t *stringify_response ( MSIResponse response )
}
#define ON_HEADER(iterator, header, descriptor, size_const) \
( memcmp(iterator, descriptor, size_const) == 0){ /* Okay */ \
iterator += size_const; /* Set iterator at begining of value part */ \
if ( *iterator != value_byte ) { assert(0); return -1; }\
iterator ++;\
uint16_t _value_size = (uint16_t) *(iterator ) << 8 | \
(uint16_t) *(iterator + 1); \
header.header_value = calloc(sizeof(uint8_t), _value_size); \
header.size = _value_size; \
memcpy(header.header_value, iterator + 2, _value_size);\
iterator = iterator + 2 + _value_size; /* set iterator at new header or end_byte */ \
}
/**
* @brief Parse raw 'data' received from socket into MSIMessage struct.
@ -235,6 +224,19 @@ static inline__ const uint8_t *stringify_response ( MSIResponse response )
*/
int parse_raw_data ( MSIMessage *msg, const uint8_t *data, uint16_t length )
{
#define ON_HEADER(iterator, header, descriptor, size_const) \
( memcmp(iterator, descriptor, size_const) == 0){ /* Okay */ \
iterator += size_const; /* Set iterator at begining of value part */ \
if ( *iterator != value_byte ) { assert(0); return -1; }\
iterator ++;\
uint16_t _value_size = (uint16_t) *(iterator ) << 8 | \
(uint16_t) *(iterator + 1); \
header.header_value = calloc(sizeof(uint8_t), _value_size); \
header.size = _value_size; \
memcpy(header.header_value, iterator + 2, _value_size);\
iterator = iterator + 2 + _value_size; /* set iterator at new header or end_byte */ }
if ( msg == NULL ) {
LOGGER_ERROR("Could not parse message: no storage!");
}
@ -537,10 +539,6 @@ uint8_t *append_header_to_string (
}
#define CLEAN_ASSIGN(added, var, field, header)\
if ( header.header_value ) { var = append_header_to_string(var, (const uint8_t*)field, header.header_value, header.size, &added); }
/**
* @brief Convert MSIMessage struct to _sendable_ string.
*
@ -550,6 +548,9 @@ if ( header.header_value ) { var = append_header_to_string(var, (const uint8_t*)
*/
uint16_t message_to_send ( MSIMessage *msg, uint8_t *dest )
{
#define CLEAN_ASSIGN(added, var, field, header)\
if ( header.header_value ) { var = append_header_to_string(var, (const uint8_t*)field, header.header_value, header.size, &added); }
if (msg == NULL) {
LOGGER_ERROR("Empty message!");
return 0;
@ -856,35 +857,6 @@ int has_call_error ( MSISession *session, MSICall* call, MSIMessage *msg )
}
/**
* @brief Function called at request timeout. If not called in thread it might cause trouble
*
* @param arg Control session
* @return void*
*/
void *handle_timeout ( void *arg )
{
/* TODO: Cancel might not arrive there; set up
* timers on these cancels and terminate call on
* their timeout
*/
MSICall *_call = arg;
LOGGER_DEBUG("[Call: %s] Request timed out!", _call->id);
invoke_callback(_call->call_idx, MSI_OnRequestTimeout);
if ( _call && _call->session ) {
/* TODO: Cancel all? */
/* uint16_t _it = 0;
for ( ; _it < _session->call->peer_count; _it++ ) */
msi_cancel ( _call->session, _call->call_idx, _call->peers [0], "Request timed out" );
}
pthread_exit(NULL);
}
/**
* @brief Add peer to peer list.
*
@ -903,6 +875,8 @@ void add_peer( MSICall *call, int peer_id )
}
call->peers[call->peer_count - 1] = peer_id;
LOGGER_DEBUG("Added peer: %d", peer_id);
}
@ -922,7 +896,7 @@ MSICall *init_call ( MSISession *session, int peers, int ringing_timeout )
return NULL;
}
uint32_t _call_idx = 0;
int32_t _call_idx = 0;
for (; _call_idx < session->max_calls; _call_idx ++) {
if ( !session->calls[_call_idx] ) {
session->calls[_call_idx] = calloc ( sizeof ( MSICall ), 1 );
@ -1015,6 +989,37 @@ int terminate_call ( MSISession *session, MSICall *call )
}
/**
* @brief Function called at request timeout. If not called in thread it might cause trouble
*
* @param arg Control session
* @return void*
*/
void *handle_timeout ( void *arg )
{
/* TODO: Cancel might not arrive there; set up
* timers on these cancels and terminate call on
* their timeout
*/
MSICall *_call = arg;
LOGGER_DEBUG("[Call: %s] Request timed out!", _call->id);
invoke_callback(_call->call_idx, MSI_OnRequestTimeout);
if ( _call && _call->session ) {
/* TODO: Cancel all? */
/* uint16_t _it = 0;
* for ( ; _it < _session->call->peer_count; _it++ ) */
msi_cancel ( _call->session, _call->call_idx, _call->peers [0], "Request timed out" );
terminate_call(_call->session, _call);
}
pthread_exit(NULL);
}
/********** Request handlers **********/
int handle_recv_invite ( MSISession *session, MSICall* call, MSIMessage *msg )
{
@ -1072,7 +1077,7 @@ int handle_recv_invite ( MSISession *session, MSICall* call, MSIMessage *msg )
}
int handle_recv_start ( MSISession *session, MSICall* call, MSIMessage *msg )
{
LOGGER_DEBUG("Session: %p Handling 'start' on call: %s", session, call->id );
LOGGER_DEBUG("Session: %p Handling 'start' on call: %s, friend id: %d", session, call->id, msg->friend_id );
if ( has_call_error ( session, call, msg ) == 0 )
return -1;
@ -1125,10 +1130,10 @@ int handle_recv_cancel ( MSISession *session, MSICall* call, MSIMessage *msg )
return 0;
/* Act as end message */
/*
MSIMessage *_msg_ending = msi_new_message ( TYPE_RESPONSE, stringify_response ( ending ) );
send_message ( session, call, _msg_ending, msg->friend_id );
free_message ( _msg_ending );
free_message ( _msg_ending );*/
invoke_callback(call->call_idx, MSI_OnCancel);
@ -1383,31 +1388,6 @@ void msi_handle_packet ( Messenger *messenger, int source, uint8_t *data, uint16
}
/********************************************************************************************************************
* *******************************************************************************************************************
********************************************************************************************************************
********************************************************************************************************************
********************************************************************************************************************
*
*
*
* PUBLIC API FUNCTIONS IMPLEMENTATIONS
*
*
*
********************************************************************************************************************
********************************************************************************************************************
********************************************************************************************************************
********************************************************************************************************************
********************************************************************************************************************/
/**
* @brief Callback setter.
*
@ -1430,7 +1410,7 @@ void msi_register_callback ( MSICallback callback, MSICallbackID id, void* userd
* @return MSISession* The created session.
* @retval NULL Error occured.
*/
MSISession *msi_init_session ( Messenger* messenger, uint32_t max_calls )
MSISession *msi_init_session ( Messenger* messenger, int32_t max_calls )
{
if (messenger == NULL) {
LOGGER_ERROR("Could not init session on empty messenger!");
@ -1507,13 +1487,13 @@ int msi_terminate_session ( MSISession *session )
* @param friend_id The friend.
* @return int
*/
int msi_invite ( MSISession* session, uint32_t* call_index, MSICallType call_type, uint32_t rngsec, uint32_t friend_id )
int msi_invite ( MSISession* session, int32_t* call_index, MSICallType call_type, uint32_t rngsec, uint32_t friend_id )
{
LOGGER_DEBUG("Session: %p Inviting friend: %u", session, friend_id);
MSIMessage *_msg_invite = msi_new_message ( TYPE_REQUEST, stringify_request ( invite ) );
MSICall* _call = init_call ( session, 1, rngsec ); /* Just one for now */
MSICall* _call = init_call ( session, 1, rngsec ); /* Just one peer for now */
if ( !_call ) return -1; /* Cannot handle more calls */
*call_index = _call->call_idx;
@ -1553,11 +1533,11 @@ int msi_invite ( MSISession* session, uint32_t* call_index, MSICallType call_typ
* @retval -1 Error occured.
* @retval 0 Success.
*/
int msi_hangup ( MSISession* session, uint32_t call_index )
int msi_hangup ( MSISession* session, int32_t call_index )
{
LOGGER_DEBUG("Session: %p Hanging up call: %u", session, call_index);
if ( call_index >= session->max_calls || !session->calls[call_index] ) {
if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ) {
LOGGER_ERROR("Invalid call index!");
return -1;
}
@ -1592,11 +1572,11 @@ int msi_hangup ( MSISession* session, uint32_t call_index )
* @param call_type Answer with Audio or Video(both).
* @return int
*/
int msi_answer ( MSISession* session, uint32_t call_index, MSICallType call_type )
int msi_answer ( MSISession* session, int32_t call_index, MSICallType call_type )
{
LOGGER_DEBUG("Session: %p Answering call: %u", session, call_index);
if ( call_index >= session->max_calls || !session->calls[call_index] ){
if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ){
LOGGER_ERROR("Invalid call index!");
return -1;
}
@ -1641,11 +1621,11 @@ int msi_answer ( MSISession* session, uint32_t call_index, MSICallType call_type
* @param reason Set optional reason header. Pass NULL if none.
* @return int
*/
int msi_cancel ( MSISession *session, uint32_t call_index, uint32_t peer, const char *reason )
int msi_cancel ( MSISession* session, int32_t call_index, uint32_t peer, const char* reason )
{
LOGGER_DEBUG("Session: %p Canceling call: %u; reason:", session, call_index, reason? reason : "Unknown");
if ( call_index >= session->max_calls || !session->calls[call_index] ){
if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ){
LOGGER_ERROR("Invalid call index!");
return -1;
}
@ -1670,11 +1650,11 @@ int msi_cancel ( MSISession *session, uint32_t call_index, uint32_t peer, const
* @param call_id To which call is this action handled.
* @return int
*/
int msi_reject ( MSISession *session, uint32_t call_index, const uint8_t *reason )
int msi_reject ( MSISession* session, int32_t call_index, const uint8_t* reason )
{
LOGGER_DEBUG("Session: %p Rejecting call: %u; reason:", session, call_index, reason? (char*)reason : "Unknown");
if ( call_index >= session->max_calls || !session->calls[call_index] ){
if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ){
LOGGER_ERROR("Invalid call index!");
return -1;
}
@ -1699,11 +1679,11 @@ int msi_reject ( MSISession *session, uint32_t call_index, const uint8_t *reason
* @param call_id To which call is this action handled.
* @return int
*/
int msi_stopcall ( MSISession *session, uint32_t call_index )
int msi_stopcall ( MSISession* session, int32_t call_index )
{
LOGGER_DEBUG("Session: %p Stopping call index: %u", session, call_index);
if ( call_index >= session->max_calls || !session->calls[call_index] )
if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] )
return -1;
/* just terminate it */

View File

@ -33,7 +33,7 @@
#define CALL_ID_LEN 12
typedef void ( *MSICallback ) ( uint32_t, void *arg );
typedef void ( *MSICallback ) ( int32_t, void *arg );
/**
@ -89,7 +89,7 @@ typedef struct _MSICall { /* Call info structure */
uint32_t *peers;
uint16_t peer_count;
uint32_t call_idx; /* Index of this call in MSISession */
int32_t call_idx; /* Index of this call in MSISession */
} MSICall;
@ -101,7 +101,7 @@ typedef struct _MSISession {
/* Call handlers */
struct _MSICall **calls;
uint32_t max_calls;
int32_t max_calls;
int last_error_id; /* Determine the last error */
const uint8_t *last_error_str;
@ -158,7 +158,7 @@ void msi_register_callback(MSICallback callback, MSICallbackID id, void* userdat
* @return MSISession* The created session.
* @retval NULL Error occured.
*/
MSISession *msi_init_session ( Messenger *messenger, uint32_t max_calls );
MSISession *msi_init_session ( Messenger *messenger, int32_t max_calls );
/**
@ -180,7 +180,7 @@ int msi_terminate_session ( MSISession *session );
* @param friend_id The friend.
* @return int
*/
int msi_invite ( MSISession *session, uint32_t* call_index, MSICallType call_type, uint32_t rngsec, uint32_t friend_id );
int msi_invite ( MSISession *session, int32_t* call_index, MSICallType call_type, uint32_t rngsec, uint32_t friend_id );
/**
@ -192,7 +192,7 @@ int msi_invite ( MSISession *session, uint32_t* call_index, MSICallType call_typ
* @retval -1 Error occured.
* @retval 0 Success.
*/
int msi_hangup ( MSISession *session, uint32_t call_index );
int msi_hangup ( MSISession *session, int32_t call_index );
/**
@ -203,7 +203,7 @@ int msi_hangup ( MSISession *session, uint32_t call_index );
* @param call_type Answer with Audio or Video(both).
* @return int
*/
int msi_answer ( MSISession *session, uint32_t call_index, MSICallType call_type );
int msi_answer ( MSISession *session, int32_t call_index, MSICallType call_type );
/**
@ -215,7 +215,7 @@ int msi_answer ( MSISession *session, uint32_t call_index, MSICallType call_type
* @param reason Set optional reason header. Pass NULL if none.
* @return int
*/
int msi_cancel ( MSISession* session, uint32_t call_index, uint32_t peer, const char* reason );
int msi_cancel ( MSISession* session, int32_t call_index, uint32_t peer, const char* reason );
/**
@ -226,7 +226,7 @@ int msi_cancel ( MSISession* session, uint32_t call_index, uint32_t peer, const
* @param reason Set optional reason header. Pass NULL if none.
* @return int
*/
int msi_reject ( MSISession *session, uint32_t call_index, const uint8_t *reason );
int msi_reject ( MSISession *session, int32_t call_index, const uint8_t *reason );
/**
@ -236,6 +236,6 @@ int msi_reject ( MSISession *session, uint32_t call_index, const uint8_t *reason
* @param call_index To which call is this action handled.
* @return int
*/
int msi_stopcall ( MSISession *session, uint32_t call_index );
int msi_stopcall ( MSISession *session, int32_t call_index );
#endif /* __TOXMSI */

View File

@ -652,36 +652,6 @@ RTPMessage *rtp_new_message ( RTPSession *session, const uint8_t *data, uint32_t
/********************************************************************************************************************
********************************************************************************************************************
********************************************************************************************************************
********************************************************************************************************************
********************************************************************************************************************
*
*
*
* PUBLIC API FUNCTIONS IMPLEMENTATIONS
*
*
*
********************************************************************************************************************
********************************************************************************************************************
********************************************************************************************************************
********************************************************************************************************************
********************************************************************************************************************/
/**
* @brief Release all messages held by session.
*
@ -757,6 +727,7 @@ RTPMessage *rtp_recv_msg ( RTPSession *session )
pthread_mutex_lock(&session->mutex);
if ( session->queue_size == 0 ) {
pthread_mutex_unlock(&session->mutex);
return NULL;
}
@ -890,12 +861,13 @@ RTPSession *rtp_init_session ( int payload_type,
assert(_retu);
if ( -1 == custom_user_packet_registerhandler(messenger, friend_num, payload_type, rtp_handle_packet, _retu) ||
!encrypt_key, !decrypt_key, !encrypt_nonce, !decrypt_nonce
) {
!encrypt_key || !decrypt_key || !encrypt_nonce || !decrypt_nonce) {
LOGGER_ERROR("Error setting custom register handler for rtp session");
free(_retu);
return NULL;
}
LOGGER_DEBUG("Registered packet handler: pt: %d; fid: %d", payload_type, friend_num);
_retu->version = RTP_VERSION; /* It's always 2 */
_retu->padding = 0; /* If some additional data is needed about the packet */

View File

@ -92,7 +92,7 @@ const ToxAvCodecSettings av_DefaultSettings = {
* @return ToxAv*
* @retval NULL On error.
*/
ToxAv *toxav_new( Tox* messenger, uint32_t max_calls)
ToxAv *toxav_new( Tox* messenger, int32_t max_calls)
{
ToxAv *av = calloc ( sizeof(ToxAv), 1);
@ -171,7 +171,7 @@ void toxav_register_callstate_callback ( ToxAVCallback callback, ToxAvCallbackID
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_call (ToxAv* av, uint32_t* call_index, int user, ToxAvCallType call_type, int ringing_seconds )
int toxav_call (ToxAv* av, int32_t* call_index, int user, ToxAvCallType call_type, int ringing_seconds )
{
return msi_invite(av->msi_session, call_index, call_type, ringing_seconds * 1000, user);
}
@ -184,7 +184,7 @@ int toxav_call (ToxAv* av, uint32_t* call_index, int user, ToxAvCallType call_ty
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_hangup ( ToxAv* av, uint32_t call_index )
int toxav_hangup ( ToxAv* av, int32_t call_index )
{
if ( !av->msi_session->calls[call_index] ) {
return ErrorNoCall;
@ -206,7 +206,7 @@ int toxav_hangup ( ToxAv* av, uint32_t call_index )
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_answer ( ToxAv* av, uint32_t call_index, ToxAvCallType call_type )
int toxav_answer ( ToxAv* av, int32_t call_index, ToxAvCallType call_type )
{
if ( !av->msi_session->calls[call_index] ) {
return ErrorNoCall;
@ -228,7 +228,7 @@ int toxav_answer ( ToxAv* av, uint32_t call_index, ToxAvCallType call_type )
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_reject ( ToxAv* av, uint32_t call_index, const char* reason )
int toxav_reject ( ToxAv* av, int32_t call_index, const char* reason )
{
if ( !av->msi_session->calls[call_index] ) {
return ErrorNoCall;
@ -251,7 +251,7 @@ int toxav_reject ( ToxAv* av, uint32_t call_index, const char* reason )
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_cancel ( ToxAv* av, uint32_t call_index, int peer_id, const char* reason )
int toxav_cancel ( ToxAv* av, int32_t call_index, int peer_id, const char* reason )
{
if ( !av->msi_session->calls[call_index] ) {
return ErrorNoCall;
@ -268,7 +268,7 @@ int toxav_cancel ( ToxAv* av, uint32_t call_index, int peer_id, const char* reas
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_stop_call ( ToxAv* av, uint32_t call_index )
int toxav_stop_call ( ToxAv* av, int32_t call_index )
{
if ( !av->msi_session->calls[call_index] ) {
return ErrorNoCall;
@ -285,7 +285,7 @@ int toxav_stop_call ( ToxAv* av, uint32_t call_index )
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_prepare_transmission ( ToxAv* av, uint32_t call_index, ToxAvCodecSettings* codec_settings, int support_video )
int toxav_prepare_transmission ( ToxAv* av, int32_t call_index, ToxAvCodecSettings* codec_settings, int support_video )
{
if ( !av->msi_session || av->msi_session->max_calls <= call_index || !av->msi_session->calls[call_index] ) {
/*fprintf(stderr, "Error while starting audio RTP session: invalid call!\n");*/
@ -350,7 +350,7 @@ int toxav_prepare_transmission ( ToxAv* av, uint32_t call_index, ToxAvCodecSetti
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_kill_transmission ( ToxAv *av, uint32_t call_index )
int toxav_kill_transmission ( ToxAv *av, int32_t call_index )
{
CallSpecific* call = &av->calls[call_index];
@ -370,12 +370,16 @@ int toxav_kill_transmission ( ToxAv *av, uint32_t call_index )
if ( call->j_buf ) {
terminate_queue(call->j_buf);
call->j_buf = NULL;
LOGGER_DEBUG("Terminated j queue");
}
else LOGGER_DEBUG("No j queue");
if ( call->cs ) {
codec_terminate_session(call->cs);
call->cs = NULL;
LOGGER_DEBUG("Terminated codec session");
}
else LOGGER_DEBUG("No codec session");
return ErrorNone;
}
@ -392,7 +396,7 @@ int toxav_kill_transmission ( ToxAv *av, uint32_t call_index )
* @retval 0 Success.
* @retval -1 Failure.
*/
inline__ int toxav_send_rtp_payload ( ToxAv *av, uint32_t call_index, ToxAvCallType type, const uint8_t *payload, uint16_t length )
inline__ int toxav_send_rtp_payload ( ToxAv *av, int32_t call_index, ToxAvCallType type, const uint8_t *payload, uint16_t length )
{
if ( av->calls[call_index].crtps[type - TypeAudio] )
return rtp_send_msg ( av->calls[call_index].crtps[type - TypeAudio], av->msi_session->messenger_handle, payload, length );
@ -409,7 +413,7 @@ inline__ int toxav_send_rtp_payload ( ToxAv *av, uint32_t call_index, ToxAvCallT
* @retval ToxAvError On Error.
* @retval >=0 Size of received payload.
*/
inline__ int toxav_recv_rtp_payload ( ToxAv *av, uint32_t call_index, ToxAvCallType type, uint8_t *dest )
inline__ int toxav_recv_rtp_payload ( ToxAv *av, int32_t call_index, ToxAvCallType type, uint8_t *dest )
{
if ( !dest ) return ErrorInternal;
@ -460,7 +464,7 @@ inline__ int toxav_recv_rtp_payload ( ToxAv *av, uint32_t call_index, ToxAvCallT
* @retval 0 Success.
* @retval ToxAvError On Error.
*/
inline__ int toxav_recv_video ( ToxAv *av, uint32_t call_index, vpx_image_t **output)
inline__ int toxav_recv_video ( ToxAv *av, int32_t call_index, vpx_image_t **output)
{
if ( !output ) return ErrorInternal;
@ -496,7 +500,7 @@ inline__ int toxav_recv_video ( ToxAv *av, uint32_t call_index, vpx_image_t **ou
* @retval 0 Success.
* @retval ToxAvError On error.
*/
inline__ int toxav_send_video ( ToxAv *av, uint32_t call_index, const uint8_t* frame, int frame_size)
inline__ int toxav_send_video ( ToxAv *av, int32_t call_index, const uint8_t* frame, int frame_size)
{
return toxav_send_rtp_payload(av, call_index, TypeVideo, frame, frame_size);
}
@ -512,7 +516,7 @@ inline__ int toxav_send_video ( ToxAv *av, uint32_t call_index, const uint8_t* f
* @retval ToxAvError On error.
* @retval >0 On success
*/
inline__ int toxav_prepare_video_frame(ToxAv* av, uint32_t call_index, uint8_t* dest, int dest_max, vpx_image_t* input)
inline__ int toxav_prepare_video_frame(ToxAv* av, int32_t call_index, uint8_t* dest, int dest_max, vpx_image_t* input)
{
CallSpecific* call = &av->calls[call_index];
@ -551,7 +555,7 @@ inline__ int toxav_prepare_video_frame(ToxAv* av, uint32_t call_index, uint8_t*
* @retval >=0 Size of received data in frames/samples.
* @retval ToxAvError On error.
*/
inline__ int toxav_recv_audio ( ToxAv *av, uint32_t call_index, int frame_size, int16_t *dest )
inline__ int toxav_recv_audio ( ToxAv *av, int32_t call_index, int frame_size, int16_t *dest )
{
if ( !dest ) return ErrorInternal;
@ -592,7 +596,7 @@ inline__ int toxav_recv_audio ( ToxAv *av, uint32_t call_index, int frame_size,
* @retval 0 Success.
* @retval ToxAvError On error.
*/
inline__ int toxav_send_audio ( ToxAv *av, uint32_t call_index, const uint8_t *frame, int frame_size)
inline__ int toxav_send_audio ( ToxAv *av, int32_t call_index, const uint8_t *frame, int frame_size)
{
return toxav_send_rtp_payload(av, call_index, TypeAudio, frame, frame_size);
}
@ -609,7 +613,7 @@ inline__ int toxav_send_audio ( ToxAv *av, uint32_t call_index, const uint8_t *f
* @retval ToxAvError On error.
* @retval >0 On success
*/
inline__ int toxav_prepare_audio_frame ( ToxAv* av, uint32_t call_index, uint8_t* dest, int dest_max, const int16_t* frame, int frame_size)
inline__ int toxav_prepare_audio_frame ( ToxAv* av, int32_t call_index, uint8_t* dest, int dest_max, const int16_t* frame, int frame_size)
{
int32_t rc = opus_encode(av->calls[call_index].cs->audio_encoder, frame, frame_size, dest, dest_max);
@ -629,7 +633,7 @@ inline__ int toxav_prepare_audio_frame ( ToxAv* av, uint32_t call_index, uint8_t
* @retval ToxAvCallType On success.
* @retval ToxAvError On error.
*/
int toxav_get_peer_transmission_type ( ToxAv *av, uint32_t call_index, int peer )
int toxav_get_peer_transmission_type ( ToxAv *av, int32_t call_index, int peer )
{
assert(av->msi_session);
@ -647,7 +651,7 @@ int toxav_get_peer_transmission_type ( ToxAv *av, uint32_t call_index, int peer
* @return int
* @retval ToxAvError No peer id
*/
int toxav_get_peer_id ( ToxAv* av, uint32_t call_index, int peer )
int toxav_get_peer_id ( ToxAv* av, int32_t call_index, int peer )
{
assert(av->msi_session);
@ -665,9 +669,10 @@ int toxav_get_peer_id ( ToxAv* av, uint32_t call_index, int peer )
* @retval 1 Yes.
* @retval 0 No.
*/
inline__ int toxav_capability_supported ( ToxAv* av, uint32_t call_index, ToxAvCapabilities capability )
inline__ int toxav_capability_supported ( ToxAv* av, int32_t call_index, ToxAvCapabilities capability )
{
return av->calls[call_index].cs->capabilities & (Capabilities) capability;
return av->calls[call_index].cs ? av->calls[call_index].cs->capabilities & (Capabilities) capability : 0;
/* 0 is error here */
}
/**
@ -678,9 +683,14 @@ inline__ int toxav_capability_supported ( ToxAv* av, uint32_t call_index, ToxAvC
* @param limit the limit
* @return void
*/
void toxav_set_audio_queue_limit(ToxAv* av, uint32_t call_index, uint64_t limit)
inline__ int toxav_set_audio_queue_limit(ToxAv* av, int32_t call_index, uint64_t limit)
{
rtp_queue_adjust_limit(av->calls[call_index].crtps[audio_index], limit);
if ( av->calls[call_index].crtps[audio_index] )
rtp_queue_adjust_limit(av->calls[call_index].crtps[audio_index], limit);
else
return ErrorNoRtpSession;
return ErrorNone;
}
/**
@ -691,7 +701,17 @@ void toxav_set_audio_queue_limit(ToxAv* av, uint32_t call_index, uint64_t limit)
* @param limit the limit
* @return void
*/
void toxav_set_video_queue_limit(ToxAv* av, uint32_t call_index, uint64_t limit)
{
rtp_queue_adjust_limit(av->calls[call_index].crtps[video_index], limit);
inline__ int toxav_set_video_queue_limit(ToxAv* av, int32_t call_index, uint64_t limit)
{
if ( av->calls[call_index].crtps[video_index] )
rtp_queue_adjust_limit(av->calls[call_index].crtps[video_index], limit);
else
return ErrorNoRtpSession;
return ErrorNone;
}
inline__ Tox* toxav_get_tox(ToxAv* av)
{
return (Tox*)av->messenger;
}

View File

@ -29,7 +29,7 @@
/* vpx_image_t */
#include <vpx/vpx_image.h>
typedef void ( *ToxAVCallback ) ( uint32_t, void *arg );
typedef void ( *ToxAVCallback ) ( int32_t, void *arg );
typedef struct _ToxAv ToxAv;
#ifndef __TOX_DEFINED__
@ -133,7 +133,7 @@ extern const ToxAvCodecSettings av_DefaultSettings;
* @return ToxAv*
* @retval NULL On error.
*/
ToxAv *toxav_new(Tox *messenger, uint32_t max_calls);
ToxAv *toxav_new(Tox *messenger, int32_t max_calls);
/**
* @brief Remove A/V session.
@ -163,7 +163,7 @@ void toxav_register_callstate_callback (ToxAVCallback callback, ToxAvCallbackID
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_call(ToxAv *av, uint32_t* call_index, int user, ToxAvCallType call_type, int ringing_seconds);
int toxav_call(ToxAv *av, int32_t* call_index, int user, ToxAvCallType call_type, int ringing_seconds);
/**
* @brief Hangup active call.
@ -173,7 +173,7 @@ int toxav_call(ToxAv *av, uint32_t* call_index, int user, ToxAvCallType call_typ
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_hangup(ToxAv *av, uint32_t call_index);
int toxav_hangup(ToxAv *av, int32_t call_index);
/**
* @brief Answer incomming call.
@ -184,7 +184,7 @@ int toxav_hangup(ToxAv *av, uint32_t call_index);
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_answer(ToxAv *av, uint32_t call_index, ToxAvCallType call_type );
int toxav_answer(ToxAv *av, int32_t call_index, ToxAvCallType call_type );
/**
* @brief Reject incomming call.
@ -195,7 +195,7 @@ int toxav_answer(ToxAv *av, uint32_t call_index, ToxAvCallType call_type );
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_reject(ToxAv *av, uint32_t call_index, const char *reason);
int toxav_reject(ToxAv *av, int32_t call_index, const char *reason);
/**
* @brief Cancel outgoing request.
@ -207,7 +207,7 @@ int toxav_reject(ToxAv *av, uint32_t call_index, const char *reason);
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_cancel(ToxAv* av, uint32_t call_index, int peer_id, const char* reason);
int toxav_cancel(ToxAv* av, int32_t call_index, int peer_id, const char* reason);
/**
* @brief Terminate transmission. Note that transmission will be terminated without informing remote peer.
@ -217,7 +217,7 @@ int toxav_cancel(ToxAv* av, uint32_t call_index, int peer_id, const char* reason
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_stop_call(ToxAv *av, uint32_t call_index);
int toxav_stop_call(ToxAv *av, int32_t call_index);
/**
* @brief Must be call before any RTP transmission occurs.
@ -228,7 +228,7 @@ int toxav_stop_call(ToxAv *av, uint32_t call_index);
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_prepare_transmission(ToxAv* av, uint32_t call_index, ToxAvCodecSettings* codec_settings, int support_video);
int toxav_prepare_transmission(ToxAv* av, int32_t call_index, ToxAvCodecSettings* codec_settings, int support_video);
/**
* @brief Call this at the end of the transmission.
@ -238,7 +238,7 @@ int toxav_prepare_transmission(ToxAv* av, uint32_t call_index, ToxAvCodecSetting
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_kill_transmission(ToxAv *av, uint32_t call_index);
int toxav_kill_transmission(ToxAv* av, int32_t call_index);
/**
* @brief Receive decoded video packet.
@ -249,7 +249,7 @@ int toxav_kill_transmission(ToxAv *av, uint32_t call_index);
* @retval 0 Success.
* @retval ToxAvError On Error.
*/
int toxav_recv_video ( ToxAv* av, uint32_t call_index, vpx_image_t** output);
int toxav_recv_video ( ToxAv* av, int32_t call_index, vpx_image_t** output);
/**
* @brief Receive decoded audio frame.
@ -263,7 +263,7 @@ int toxav_recv_video ( ToxAv* av, uint32_t call_index, vpx_image_t** output);
* @retval >=0 Size of received data in frames/samples.
* @retval ToxAvError On error.
*/
int toxav_recv_audio( ToxAv* av, uint32_t call_index, int frame_size, int16_t* dest );
int toxav_recv_audio( ToxAv* av, int32_t call_index, int frame_size, int16_t* dest );
/**
* @brief Encode and send video packet.
@ -275,7 +275,7 @@ int toxav_recv_audio( ToxAv* av, uint32_t call_index, int frame_size, int16_t* d
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_send_video ( ToxAv* av, uint32_t call_index, const uint8_t* frame, int frame_size);
int toxav_send_video ( ToxAv* av, int32_t call_index, const uint8_t* frame, int frame_size);
/**
* @brief Send audio frame.
@ -288,7 +288,7 @@ int toxav_send_video ( ToxAv* av, uint32_t call_index, const uint8_t* frame, int
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_send_audio ( ToxAv* av, uint32_t call_index, const uint8_t* frame, int frame_size);
int toxav_send_audio ( ToxAv* av, int32_t call_index, const uint8_t* frame, int frame_size);
/**
* @brief Encode video frame
@ -301,7 +301,7 @@ int toxav_send_audio ( ToxAv* av, uint32_t call_index, const uint8_t* frame, int
* @retval ToxAvError On error.
* @retval >0 On success
*/
int toxav_prepare_video_frame ( ToxAv* av, uint32_t call_index, uint8_t* dest, int dest_max, vpx_image_t* input );
int toxav_prepare_video_frame ( ToxAv* av, int32_t call_index, uint8_t* dest, int dest_max, vpx_image_t* input );
/**
* @brief Encode audio frame
@ -315,7 +315,7 @@ int toxav_prepare_video_frame ( ToxAv* av, uint32_t call_index, uint8_t* dest, i
* @retval ToxAvError On error.
* @retval >0 On success
*/
int toxav_prepare_audio_frame ( ToxAv* av, uint32_t call_index, uint8_t* dest, int dest_max, const int16_t* frame, int frame_size);
int toxav_prepare_audio_frame ( ToxAv* av, int32_t call_index, uint8_t* dest, int dest_max, const int16_t* frame, int frame_size);
/**
* @brief Get peer transmission type. It can either be audio or video.
@ -326,7 +326,7 @@ int toxav_prepare_audio_frame ( ToxAv* av, uint32_t call_index, uint8_t* dest, i
* @retval ToxAvCallType On success.
* @retval ToxAvError On error.
*/
int toxav_get_peer_transmission_type ( ToxAv *av, uint32_t call_index, int peer );
int toxav_get_peer_transmission_type ( ToxAv* av, int32_t call_index, int peer );
/**
* @brief Get id of peer participating in conversation
@ -336,7 +336,7 @@ int toxav_get_peer_transmission_type ( ToxAv *av, uint32_t call_index, int peer
* @return int
* @retval ToxAvError No peer id
*/
int toxav_get_peer_id ( ToxAv* av, uint32_t call_index, int peer );
int toxav_get_peer_id ( ToxAv* av, int32_t call_index, int peer );
/**
* @brief Is certain capability supported
@ -346,7 +346,7 @@ int toxav_get_peer_id ( ToxAv* av, uint32_t call_index, int peer );
* @retval 1 Yes.
* @retval 0 No.
*/
int toxav_capability_supported ( ToxAv* av, uint32_t call_index, ToxAvCapabilities capability );
int toxav_capability_supported ( ToxAv* av, int32_t call_index, ToxAvCapabilities capability );
/**
* @brief Set queue limit
@ -356,7 +356,7 @@ int toxav_capability_supported ( ToxAv* av, uint32_t call_index, ToxAvCapabiliti
* @param limit the limit
* @return void
*/
void toxav_set_audio_queue_limit ( ToxAv* av, uint32_t call_index, uint64_t limit );
int toxav_set_audio_queue_limit ( ToxAv* av, int32_t call_index, uint64_t limit );
/**
* @brief Set queue limit
@ -366,6 +366,8 @@ void toxav_set_audio_queue_limit ( ToxAv* av, uint32_t call_index, uint64_t limi
* @param limit the limit
* @return void
*/
void toxav_set_video_queue_limit ( ToxAv* av, uint32_t call_index, uint64_t limit );
int toxav_set_video_queue_limit ( ToxAv* av, int32_t call_index, uint64_t limit );
Tox* toxav_get_tox(ToxAv* av);
#endif /* __TOXAV */

View File

@ -2275,7 +2275,7 @@ void do_messenger(Messenger *m)
if (last_pinged > 999)
last_pinged = 999;
LOGGER_DEBUG("C[%2u] %s:%u [%3u] %s",
LOGGER_INFO("C[%2u] %s:%u [%3u] %s",
client, ip_ntoa(&assoc->ip_port.ip), ntohs(assoc->ip_port.port),
last_pinged, ID2String(cptr->client_id));
}
@ -2308,7 +2308,7 @@ void do_messenger(Messenger *m)
dht2m[m2dht[friend]] = friend;
if (m->numfriends != m->dht->num_friends) {
LOGGER_DEBUG("Friend num in DHT %u != friend num in msger %u\n", m->dht->num_friends, m->numfriends);
LOGGER_INFO("Friend num in DHT %u != friend num in msger %u\n", m->dht->num_friends, m->numfriends);
}
uint32_t ping_lastrecv;
@ -2329,11 +2329,11 @@ void do_messenger(Messenger *m)
if (ping_lastrecv > 999)
ping_lastrecv = 999;
LOGGER_DEBUG("F[%2u:%2u] <%s> %02i [%03u] %s",
LOGGER_INFO("F[%2u:%2u] <%s> %02i [%03u] %s",
dht2m[friend], friend, msgfptr->name, msgfptr->crypt_connection_id,
ping_lastrecv, ID2String(msgfptr->client_id));
} else {
LOGGER_DEBUG("F[--:%2u] %s", friend, ID2String(dhtfptr->client_id));
LOGGER_INFO("F[--:%2u] %s", friend, ID2String(dhtfptr->client_id));
}
for (client = 0; client < MAX_FRIEND_CLIENTS; client++) {
@ -2348,7 +2348,7 @@ void do_messenger(Messenger *m)
if (last_pinged > 999)
last_pinged = 999;
LOGGER_DEBUG("F[%2u] => C[%2u] %s:%u [%3u] %s",
LOGGER_INFO("F[%2u] => C[%2u] %s:%u [%3u] %s",
friend, client, ip_ntoa(&assoc->ip_port.ip),
ntohs(assoc->ip_port.port), last_pinged,
ID2String(cptr->client_id));

View File

@ -60,8 +60,8 @@ void __attribute__((destructor)) terminate_logger()
time_t tim = time(NULL);
logger_write(ERROR, "============== Closing logger ==============\n"
"Time: %s", asctime(localtime(&tim)));
logger_write(ERROR, "\n============== Closing logger [%u] ==============\n"
"Time: %s", logger_get_pid(), asctime(localtime(&tim)));
fclose(logger.log_file);
}
@ -96,12 +96,12 @@ int logger_init(const char* file_name, LoggerLevel level)
sprintf(final_l, "%s"/*.%u"*/, file_name, logger_get_pid());
if ( logger.log_file ) {
fprintf(stderr, "Error opening logger name: %s with level %d: already opened!\n", final_l, level);
fprintf(stderr, "Error opening logger name: %s with level %d: %s!\n", final_l, level, strerror(errno));
free (final_l);
return -1;
}
logger.log_file = fopen(final_l, "wb");
logger.log_file = fopen(final_l, "ab");
if ( logger.log_file == NULL ) {
char error[1000];
@ -120,8 +120,8 @@ int logger_init(const char* file_name, LoggerLevel level)
time_t tim = time(NULL);
logger_write(ERROR, "============== Starting logger ==============\n"
"Time: %s", asctime(localtime(&tim)));
logger_write(ERROR, "\n============== Starting logger [%u] ==============\n"
"Time: %s", logger_get_pid(), asctime(localtime(&tim)));

View File

@ -53,7 +53,7 @@ char* logger_timestr (char* dest);
#define _SFILE (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#endif
#define WRITE_FORMAT(__LEVEL__, format) char* the_str = calloc(sizeof(char), strlen(format)+ 500); sprintf(the_str, "[%u] [%s] [%s] [%s:%d %s()] %s\n", \
#define WRITE_FORMAT(__LEVEL__, format) char* the_str = calloc(sizeof(char), strlen(format)+ 500); sprintf(the_str, "\n[%u] [%s] [%s] [%s:%d %s()] %s", \
logger_get_pid(), logger_stringify_level(__LEVEL__), logger_timestr(__time__), _SFILE, __LINE__, __func__, format)
/* Use these macros */

View File

@ -374,7 +374,7 @@ void networking_poll(Networking_Core *net)
if (length < 1) continue;
if (!(net->packethandlers[data[0]].function)) {
LOGGER_WARNING("[%02u] -- Packet has no handler.\n", data[0]);
LOGGER_WARNING("[%02u] -- Packet has no handler", data[0]);
continue;
}