From 750c75a47dda2712bc988fecd95510ccf54c68fd Mon Sep 17 00:00:00 2001 From: irungentoo Date: Sun, 15 Jun 2014 10:36:57 -0400 Subject: Astyled code. --- toxav/event.c | 10 +++---- toxav/event.h | 4 +-- toxav/msi.c | 88 ++++++++++++++++++++++++++++++----------------------------- toxav/toxav.c | 18 ++++++++---- 4 files changed, 65 insertions(+), 55 deletions(-) (limited to 'toxav') diff --git a/toxav/event.c b/toxav/event.c index 35af98bb..870abf2a 100644 --- a/toxav/event.c +++ b/toxav/event.c @@ -68,9 +68,9 @@ typedef struct _EventHandler { } EventHandler; -int throw_event( void * (func)(void *), void *arg ); +int throw_event( void *(func)(void *), void *arg ); int reset_timer_event ( int id, uint32_t timeout ); -int throw_timer_event ( void * (func)(void *), void *arg, unsigned timeout); +int throw_timer_event ( void *(func)(void *), void *arg, unsigned timeout); int cancel_timer_event ( int id ); int execute_timer_event ( int id ); @@ -142,7 +142,7 @@ int pop_id ( EventContainer **event_container, size_t *counter, int id ) return -1; } -void push_event ( EventContainer **container, size_t *counter, void * (func)(void *), void *arg ) +void push_event ( EventContainer **container, size_t *counter, void *(func)(void *), void *arg ) { EventContainer *_new = realloc((*container ), sizeof(EventContainer) * ((*counter ) + 1)); @@ -230,7 +230,7 @@ void *event_poll( void *arg ) pthread_exit(NULL); } -int throw_event( void * (func)(void *), void *arg ) +int throw_event( void *(func)(void *), void *arg ) { pthread_t _tid; int _rc = @@ -242,7 +242,7 @@ int throw_event( void * (func)(void *), void *arg ) EventHandler event_handler; /* Place and order array of timers */ -int throw_timer_event ( void * (func)(void *), void *arg, unsigned timeout) +int throw_timer_event ( void *(func)(void *), void *arg, unsigned timeout) { static int _unique_id = 1; diff --git a/toxav/event.h b/toxav/event.h index 0fb2d120..f9e67543 100644 --- a/toxav/event.h +++ b/toxav/event.h @@ -39,9 +39,9 @@ * */ extern struct _Event { - int (*rise) (void * ( func ) ( void * ), void *arg); + int (*rise) (void *( func ) ( void *), void *arg); int (*timer_reset ) ( int id, unsigned timeout ); - int (*timer_alloc) (void * ( func ) ( void * ), void *arg, unsigned timeout); + int (*timer_alloc) (void *( func ) ( void *), void *arg, unsigned timeout); int (*timer_release) (int id); int (*timer_now) ( int id ); } event; diff --git a/toxav/msi.c b/toxav/msi.c index c7d729b9..6a529699 100644 --- a/toxav/msi.c +++ b/toxav/msi.c @@ -167,11 +167,11 @@ typedef enum { static inline__ const uint8_t *stringify_request ( MSIRequest request ) { static const uint8_t *strings[] = { - ( uint8_t * ) "INVITE", - ( uint8_t * ) "START", - ( uint8_t * ) "CANCEL", - ( uint8_t * ) "REJECT", - ( uint8_t * ) "END" + ( uint8_t *) "INVITE", + ( uint8_t *) "START", + ( uint8_t *) "CANCEL", + ( uint8_t *) "REJECT", + ( uint8_t *) "END" }; return strings[request]; @@ -196,10 +196,10 @@ typedef enum { static inline__ const uint8_t *stringify_response ( MSIResponse response ) { static const uint8_t *strings[] = { - ( uint8_t * ) "ringing", - ( uint8_t * ) "starting", - ( uint8_t * ) "ending", - ( uint8_t * ) "error" + ( uint8_t *) "ringing", + ( uint8_t *) "starting", + ( uint8_t *) "ending", + ( uint8_t *) "error" }; return strings[response]; @@ -243,7 +243,7 @@ iterator = iterator + 2 + _value_size; /* set iterator at new header or end_byte const uint8_t *_it = data; uint16_t size_max = length; - + while ( *_it ) {/* until end_byte is hit */ uint16_t itedlen = (_it - data) + 2; @@ -251,14 +251,14 @@ iterator = iterator + 2 + _value_size; /* set iterator at new header or end_byte if ( *_it == field_byte && itedlen < length ) { uint16_t _size; - memcpy(&_size, _it + 1, sizeof(_size)); + memcpy(&_size, _it + 1, sizeof(_size)); _size = ntohs(_size); - + if ( itedlen + _size > length ) return -1; _it += 3; /* place it at the field value beginning */ size_max -= 3; - + switch ( _size ) { /* Compare the size of the hardcoded values ( vary fast and convenient ) */ case 4: { /* INFO header */ @@ -278,9 +278,9 @@ iterator = iterator + 2 + _value_size; /* set iterator at new header or end_byte case 7: { /* Version, Request, Call-id headers */ if ON_HEADER ( _it, size_max, msg->version, VERSION_FIELD, 7 ) - else if ON_HEADER ( _it, size_max, msg->request, REQUEST_FIELD, 7 ) - else if ON_HEADER ( _it, size_max, msg->callid, CALLID_FIELD, 7 ) - } + else if ON_HEADER ( _it, size_max, msg->request, REQUEST_FIELD, 7 ) + else if ON_HEADER ( _it, size_max, msg->callid, CALLID_FIELD, 7 ) + } break; case 8: { /* Response header */ @@ -513,9 +513,10 @@ uint8_t *append_header_to_string ( /* Now set the length of the field byte */ uint16_t _convert; - - + + _convert = htons(_i); + memcpy(_getback_byte, &_convert, sizeof(_convert)); /* for value part do it regulary */ @@ -523,11 +524,12 @@ uint8_t *append_header_to_string ( dest++; - + _convert = htons(value_len); + memcpy(dest, &_convert, sizeof(_convert)); - - dest+=2; + + dest += 2; for ( _i = value_len; _i; --_i ) { *dest = *_hvit; @@ -645,13 +647,13 @@ typedef enum { static inline__ const uint8_t *stringify_error ( MSICallError error_code ) { static const uint8_t *strings[] = { - ( uint8_t * ) "", - ( uint8_t * ) "Using dead call", - ( uint8_t * ) "Call id not set to any call", - ( uint8_t * ) "Call id not available", - ( uint8_t * ) "No active call in session", - ( uint8_t * ) "No Crypto-key set", - ( uint8_t * ) "Callee busy" + ( uint8_t *) "", + ( uint8_t *) "Using dead call", + ( uint8_t *) "Call id not set to any call", + ( uint8_t *) "Call id not available", + ( uint8_t *) "No active call in session", + ( uint8_t *) "No Crypto-key set", + ( uint8_t *) "Callee busy" }; return strings[error_code]; @@ -667,13 +669,13 @@ static inline__ const uint8_t *stringify_error ( MSICallError error_code ) static inline__ const uint8_t *stringify_error_code ( MSICallError error_code ) { static const uint8_t *strings[] = { - ( uint8_t * ) "", - ( uint8_t * ) "1", - ( uint8_t * ) "2", - ( uint8_t * ) "3", - ( uint8_t * ) "4", - ( uint8_t * ) "5", - ( uint8_t * ) "6" + ( uint8_t *) "", + ( uint8_t *) "1", + ( uint8_t *) "2", + ( uint8_t *) "3", + ( uint8_t *) "4", + ( uint8_t *) "5", + ( uint8_t *) "6" }; return strings[error_code]; @@ -756,10 +758,10 @@ void flush_peer_type ( MSICall *call, MSIMessage *msg, int peer_id ) memcpy(hdrval, msg->calltype.header_value, msg->calltype.size); hdrval[msg->calltype.size] = '\0'; - if ( strcmp ( ( const char * ) hdrval, CT_AUDIO_HEADER_VALUE ) == 0 ) { + if ( strcmp ( ( const char *) hdrval, CT_AUDIO_HEADER_VALUE ) == 0 ) { call->type_peer[peer_id] = type_audio; - } else if ( strcmp ( ( const char * ) hdrval, CT_VIDEO_HEADER_VALUE ) == 0 ) { + } else if ( strcmp ( ( const char *) hdrval, CT_VIDEO_HEADER_VALUE ) == 0 ) { call->type_peer[peer_id] = type_video; } else {} /* Error */ } else {} /* Error */ @@ -831,7 +833,7 @@ int handle_error ( MSISession *session, MSICall *call, MSICallError errid, uint3 const uint8_t *_error_code_str = stringify_error_code ( errid ); - msi_msg_set_reason ( _msg_error, _error_code_str, strlen ( ( const char * ) _error_code_str ) ); + msi_msg_set_reason ( _msg_error, _error_code_str, strlen ( ( const char *) _error_code_str ) ); send_message ( session, call, _msg_error, to ); free_message ( _msg_error ); @@ -1325,7 +1327,7 @@ int handle_recv_error ( MSISession *session, MSICall *call, MSIMessage *msg ) /* Handle error accordingly */ if ( msg->reason.header_value ) { - session->last_error_id = atoi ( ( const char * ) msg->reason.header_value ); + session->last_error_id = atoi ( ( const char *) msg->reason.header_value ); session->last_error_str = stringify_error ( session->last_error_id ); LOGGER_DEBUG("Error reason: %s", session->last_error_str); } @@ -1612,9 +1614,9 @@ int msi_invite ( MSISession *session, int32_t *call_index, MSICallType call_type /* Do whatever with message */ if ( call_type == type_audio ) { - msi_msg_set_calltype ( _msg_invite, ( const uint8_t * ) CT_AUDIO_HEADER_VALUE, strlen ( CT_AUDIO_HEADER_VALUE ) ); + msi_msg_set_calltype ( _msg_invite, ( const uint8_t *) CT_AUDIO_HEADER_VALUE, strlen ( CT_AUDIO_HEADER_VALUE ) ); } else { - msi_msg_set_calltype ( _msg_invite, ( const uint8_t * ) CT_VIDEO_HEADER_VALUE, strlen ( CT_VIDEO_HEADER_VALUE ) ); + msi_msg_set_calltype ( _msg_invite, ( const uint8_t *) CT_VIDEO_HEADER_VALUE, strlen ( CT_VIDEO_HEADER_VALUE ) ); } send_message ( session, _call, _msg_invite, friend_id ); @@ -1702,10 +1704,10 @@ int msi_answer ( MSISession *session, int32_t call_index, MSICallType call_type if ( call_type == type_audio ) { msi_msg_set_calltype - ( _msg_starting, ( const uint8_t * ) CT_AUDIO_HEADER_VALUE, strlen ( CT_AUDIO_HEADER_VALUE ) ); + ( _msg_starting, ( const uint8_t *) CT_AUDIO_HEADER_VALUE, strlen ( CT_AUDIO_HEADER_VALUE ) ); } else { msi_msg_set_calltype - ( _msg_starting, ( const uint8_t * ) CT_VIDEO_HEADER_VALUE, strlen ( CT_VIDEO_HEADER_VALUE ) ); + ( _msg_starting, ( const uint8_t *) CT_VIDEO_HEADER_VALUE, strlen ( CT_VIDEO_HEADER_VALUE ) ); } /* Now set the local encryption key and pass it with STARTING message */ diff --git a/toxav/toxav.c b/toxav/toxav.c index 959ef54c..a042b9dd 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c @@ -351,7 +351,7 @@ int toxav_prepare_transmission ( ToxAv *av, int32_t call_index, ToxAvCodecSettin int toxav_kill_transmission ( ToxAv *av, int32_t call_index ) { if (cii(call_index, av->msi_session)) return ErrorNoCall; - + CallSpecific *call = &av->calls[call_index]; if ( call->crtps[audio_index] && -1 == rtp_terminate_session(call->crtps[audio_index], av->messenger) ) { @@ -398,7 +398,7 @@ inline__ int toxav_send_rtp_payload ( ToxAv *av, int32_t call_index, ToxAvCallTy uint16_t length ) { if (cii(call_index, av->msi_session)) return ErrorNoCall; - + 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 ); @@ -418,6 +418,7 @@ inline__ int toxav_send_rtp_payload ( ToxAv *av, int32_t call_index, ToxAvCallTy inline__ int toxav_recv_rtp_payload ( ToxAv *av, int32_t call_index, ToxAvCallType type, uint8_t *dest ) { if ( !dest ) return ErrorInternal; + if (cii(call_index, av->msi_session)) return ErrorNoCall; CallSpecific *call = &av->calls[call_index]; @@ -470,6 +471,7 @@ inline__ int toxav_recv_rtp_payload ( ToxAv *av, int32_t call_index, ToxAvCallTy inline__ int toxav_recv_video ( ToxAv *av, int32_t call_index, vpx_image_t **output) { if ( !output ) return ErrorInternal; + if (cii(call_index, av->msi_session)) return ErrorNoCall; uint8_t packet [RTP_PAYLOAD_SIZE]; @@ -507,6 +509,7 @@ inline__ int toxav_recv_video ( ToxAv *av, int32_t call_index, vpx_image_t **out inline__ int toxav_send_video ( ToxAv *av, int32_t call_index, const uint8_t *frame, int frame_size) { if (cii(call_index, av->msi_session)) return ErrorNoCall; + return toxav_send_rtp_payload(av, call_index, TypeVideo, frame, frame_size); } @@ -524,7 +527,7 @@ inline__ int toxav_send_video ( ToxAv *av, int32_t call_index, const uint8_t *fr inline__ int toxav_prepare_video_frame(ToxAv *av, int32_t call_index, uint8_t *dest, int dest_max, vpx_image_t *input) { if (cii(call_index, av->msi_session)) return ErrorNoCall; - + CallSpecific *call = &av->calls[call_index]; int rc = vpx_codec_encode(&call->cs->v_encoder, input, call->cs->frame_counter, 1, 0, MAX_ENCODE_TIME_US); @@ -567,6 +570,7 @@ inline__ int toxav_prepare_video_frame(ToxAv *av, int32_t call_index, uint8_t *d inline__ int toxav_recv_audio ( ToxAv *av, int32_t call_index, int frame_size, int16_t *dest ) { if ( !dest ) return ErrorInternal; + if (cii(call_index, av->msi_session)) return ErrorNoCall; CallSpecific *call = &av->calls[call_index]; @@ -609,6 +613,7 @@ inline__ int toxav_recv_audio ( ToxAv *av, int32_t call_index, int frame_size, i inline__ int toxav_send_audio ( ToxAv *av, int32_t call_index, const uint8_t *frame, int frame_size) { if (cii(call_index, av->msi_session)) return ErrorNoCall; + return toxav_send_rtp_payload(av, call_index, TypeAudio, frame, frame_size); } @@ -628,6 +633,7 @@ inline__ int toxav_prepare_audio_frame ( ToxAv *av, int32_t call_index, uint8_t const int16_t *frame, int frame_size) { if (cii(call_index, av->msi_session)) return ErrorNoCall; + int32_t rc = opus_encode(av->calls[call_index].cs->audio_encoder, frame, frame_size, dest, dest_max); if (rc < 0) { @@ -649,7 +655,8 @@ inline__ int toxav_prepare_audio_frame ( ToxAv *av, int32_t call_index, uint8_t */ int toxav_get_peer_transmission_type ( ToxAv *av, int32_t call_index, int peer ) { - if ( peer < 0 || cii(call_index, av->msi_session) || !av->msi_session->calls[call_index] || av->msi_session->calls[call_index]->peer_count <= peer ) + if ( peer < 0 || cii(call_index, av->msi_session) || !av->msi_session->calls[call_index] + || av->msi_session->calls[call_index]->peer_count <= peer ) return ErrorInternal; return av->msi_session->calls[call_index]->type_peer[peer]; @@ -667,7 +674,8 @@ int toxav_get_peer_id ( ToxAv *av, int32_t call_index, int peer ) { assert(av->msi_session); - if ( peer < 0 || cii(call_index, av->msi_session) || !av->msi_session->calls[call_index] || av->msi_session->calls[call_index]->peer_count <= peer ) + if ( peer < 0 || cii(call_index, av->msi_session) || !av->msi_session->calls[call_index] + || av->msi_session->calls[call_index]->peer_count <= peer ) return ErrorInternal; return av->msi_session->calls[call_index]->peers[peer]; -- cgit v1.2.3