Astyled av code.

This commit is contained in:
irungentoo 2014-02-16 20:01:30 -05:00
parent 9d1eb27717
commit baa4a2f11d
11 changed files with 1565 additions and 1423 deletions

247
toxav/event.c Executable file → Normal file
View File

@ -1,5 +1,5 @@
/** event.c
*
*
* Copyright (C) 2013 Tox project All Rights Reserved.
*
* This file is part of Tox.
@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
*
*
*
* Report bugs/suggestions at #tox-dev @ freenode.net:6667
*/
@ -53,31 +53,30 @@ pthread_create(&_tid, NULL, func, args); assert( pthread_detach(_tid) == 0 ); }
typedef struct _EventContainer {
void* (*func)(void*);
void* func_args;
void *(*func)(void *);
void *func_args;
unsigned timeout;
long long id;
} EventContainer;
typedef struct _EventHandler {
EventContainer* timed_events;
EventContainer *timed_events;
size_t timed_events_count;
int running;
pthread_mutex_t mutex;
} 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 );
struct _Event event =
{
struct _Event event = {
throw_event,
/* reset_timer_event */ NULL,
throw_timer_event,
@ -88,62 +87,68 @@ struct _Event event =
/*
* Random functions used by this file
*/
void clear_events (EventContainer** event_container, size_t* counter)
void clear_events (EventContainer **event_container, size_t *counter)
{
free(*event_container );
*event_container = NULL;
*counter = 0;
}
int pop_id ( EventContainer** event_container, size_t* counter, int id )
int pop_id ( EventContainer **event_container, size_t *counter, int id )
{
if ( !*event_container || !*counter || !id )
return -1;
EventContainer* _it = *event_container;
EventContainer *_it = *event_container;
int i;
for ( i = *counter; i; -- i ){
for ( i = *counter; i; -- i ) {
if ( _it->id == id ) { /* Hit! */
break;
}
++_it;
}
if ( i ) {
for ( ; i; -- i ){ *_it = *(_it + 1); ++_it; }
for ( ; i; -- i ) {
*_it = *(_it + 1);
++_it;
}
-- (*counter );
if ( !(*counter)) { /* Free and set to NULL */
free(*event_container);
*event_container = NULL;
}
else {
void* _result = realloc(*event_container, sizeof(EventContainer) * (*counter )); /* resize */
if ( _result != NULL ) { *event_container = _result; return 0; }
else {
} else {
void *_result = realloc(*event_container, sizeof(EventContainer) * (*counter )); /* resize */
if ( _result != NULL ) {
*event_container = _result;
return 0;
} else {
/* Not sure what would happen next so abort execution.
*/
fprintf(stderr, "CRITICAL! Failed to reallocate memory in %s():%d, aborting...", __func__, __LINE__);
abort();
return -1;
return -1;
}
}
}
/* not found here */
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));
if ( _new == NULL ) {
EventContainer *_new = realloc((*container ), sizeof(EventContainer) * ((*counter ) + 1));
if ( _new == NULL ) {
/* Not sure what would happen next so abort execution.
* TODO: This could notice the calling function
* about realloc failing.
@ -151,188 +156,194 @@ void push_event ( EventContainer** container, size_t* counter, void* (func)(void
fprintf(stderr, "CRITICAL! Failed to reallocate memory in %s():%d, aborting...", __func__, __LINE__);
abort();
}
_new[*counter].func = func;
_new[*counter].func_args = arg;
_new[*counter].timeout = 0;
_new[*counter].id = 0;
(*container) = _new;
(*counter )++;
}
void reorder_events ( size_t counter, EventContainer* container, unsigned timeout )
void reorder_events ( size_t counter, EventContainer *container, unsigned timeout )
{
if ( counter > 1 ) {
int i = counter - 1;
/* start from behind excluding last added member */
EventContainer* _it = &container[i - 1];
EventContainer *_it = &container[i - 1];
EventContainer _last_added = container[i];
for ( ; i; --i ) {
if ( _it->timeout > timeout ){
if ( _it->timeout > timeout ) {
*(_it + 1) = *_it;
*_it = _last_added; -- _it;
*_it = _last_added;
-- _it;
}
}
}
}
/* ============================================= */
/* main poll for event execution */
void* event_poll( void* arg )
void *event_poll( void *arg )
{
EventHandler* _event_handler = arg;
while ( _event_handler->running )
{
EventHandler *_event_handler = arg;
while ( _event_handler->running ) {
LOCK( _event_handler );
if ( _event_handler->timed_events ){
if ( _event_handler->timed_events ) {
uint32_t _time = ((uint32_t)(current_time() / 1000));
if ( _event_handler->timed_events[0].timeout < _time ) {
RUN_IN_THREAD ( _event_handler->timed_events[0].func,
_event_handler->timed_events[0].func_args );
pop_id(&_event_handler->timed_events,
&_event_handler->timed_events_count,
_event_handler->timed_events[0].id);
}
}
UNLOCK( _event_handler );
usleep(FREQUENCY);
}
LOCK( _event_handler );
clear_events(&_event_handler->timed_events, &_event_handler->timed_events_count);
UNLOCK( _event_handler );
_event_handler->running = -1;
pthread_exit(NULL);
}
int throw_event( void* (func)(void*), void* arg )
int throw_event( void * (func)(void *), void *arg )
{
pthread_t _tid;
int _rc =
pthread_create(&_tid, NULL, func, arg );
pthread_create(&_tid, NULL, func, arg );
return (0 != _rc ) ? _rc : pthread_detach(_tid);
}
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;
push_event(&event_handler.timed_events, &(event_handler.timed_events_count), func, arg );
size_t _counter = event_handler.timed_events_count;
event_handler.timed_events[_counter - 1].timeout = timeout + ((uint32_t)(current_time() / 1000));
event_handler.timed_events[_counter - 1].id = _unique_id; ++_unique_id;
event_handler.timed_events[_counter - 1].id = _unique_id;
++_unique_id;
/* reorder */
reorder_events(_counter, event_handler.timed_events, timeout );
return _unique_id - 1;
}
int execute_timer_event ( int id )
{
int _status;
LOCK((&event_handler));
EventContainer* _it = event_handler.timed_events;
EventContainer *_it = event_handler.timed_events;
int _i = event_handler.timed_events_count;
/* Find it and execute */
for ( ; _i; _i-- ) {
if ( _it->id == id ) {
RUN_IN_THREAD ( _it->func, _it->func_args );
break;
}
++_it;
}
/* Now remove it from the queue */
if ( _i ) {
for ( ; _i; -- _i ){ *_it = *(_it + 1); ++_it; }
for ( ; _i; -- _i ) {
*_it = *(_it + 1);
++_it;
}
-- event_handler.timed_events_count;
if ( !event_handler.timed_events_count ) { /* Free and set to null */
free(event_handler.timed_events);
event_handler.timed_events = NULL;
}
else {
void* _result = realloc(event_handler.timed_events, sizeof(EventContainer) * event_handler.timed_events_count); /* resize */
if ( _result != NULL ) { event_handler.timed_events = _result; }
else {
} else {
void *_result = realloc(event_handler.timed_events,
sizeof(EventContainer) * event_handler.timed_events_count); /* resize */
if ( _result != NULL ) {
event_handler.timed_events = _result;
} else {
/* Not sure what would happen next so abort execution.
*/
fprintf(stderr, "CRITICAL! Failed to reallocate memory in %s():%d, aborting...", __func__, __LINE__);
abort();
return -1;
}
return -1;
}
}
_status = 0;
}
else _status = -1;
} else _status = -1;
UNLOCK((&event_handler));
return _status;
}
int reset_timer_event ( int id, uint32_t timeout )
{
int _status;
LOCK((&event_handler));
EventContainer* _it = event_handler.timed_events;
EventContainer *_it = event_handler.timed_events;
int _i = event_handler.timed_events_count;
/* Find it and change */
for ( ; _i; _i-- ) {
if ( _it->id == id ) {
_it->timeout = timeout + ((uint32_t)(current_time() / 1000));
break;
}
++_it;
}
_status = _i ? -1 : 0;
UNLOCK((&event_handler));
return _status;
}
@ -352,11 +363,11 @@ void __attribute__((constructor)) init_event_poll ()
{
event_handler.timed_events = NULL;
event_handler.timed_events_count = 0;
event_handler.running = 1;
pthread_mutex_init(&event_handler.mutex, NULL);
RUN_IN_THREAD(event_poll, &event_handler);
}
@ -365,9 +376,9 @@ void __attribute__((destructor)) terminate_event_poll()
{
/* Exit thread */
event_handler.running = 0;
/* Give it enought time to exit */
usleep(FREQUENCY*2);
usleep(FREQUENCY * 2);
pthread_mutex_destroy( &event_handler.mutex );
}

13
toxav/event.h Executable file → Normal file
View File

@ -1,5 +1,5 @@
/** event.h
*
*
* Copyright (C) 2013 Tox project All Rights Reserved.
*
* This file is part of Tox.
@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
*
*
*
* Report bugs/suggestions at #tox-dev @ freenode.net:6667
*/
@ -36,13 +36,12 @@
* - Timeout is measured in milliseconds.
*
* NOTE: timer_reset () and timer_now() are not tested nor usable atm
*
*
*/
extern struct _Event
{
int (*rise) (void* ( func ) ( void* ), void* arg);
extern struct _Event {
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;

View File

@ -1,5 +1,5 @@
/** media.c
*
*
* Audio and video codec intitialization, encoding/decoding and playback
*
* Copyright (C) 2013 Tox project All Rights Reserved.
@ -50,8 +50,8 @@ struct jitter_buffer {
struct jitter_buffer *create_queue(int capacity)
{
struct jitter_buffer *q;
q = (struct jitter_buffer *)calloc(sizeof(struct jitter_buffer),1);
q->queue = (RTPMessage **)calloc(sizeof(RTPMessage*), capacity);
q = (struct jitter_buffer *)calloc(sizeof(struct jitter_buffer), 1);
q->queue = (RTPMessage **)calloc(sizeof(RTPMessage *), capacity);
int i = 0;
for (i = 0; i < capacity; ++i) {
@ -200,7 +200,8 @@ int queue(struct jitter_buffer *q, RTPMessage *pk)
int init_video_decoder(CodecState *cs)
{
if (vpx_codec_dec_init_ver(&cs->v_decoder, VIDEO_CODEC_DECODER_INTERFACE, NULL, 0, VPX_DECODER_ABI_VERSION) != VPX_CODEC_OK) {
if (vpx_codec_dec_init_ver(&cs->v_decoder, VIDEO_CODEC_DECODER_INTERFACE, NULL, 0,
VPX_DECODER_ABI_VERSION) != VPX_CODEC_OK) {
fprintf(stderr, "Init video_decoder failed!\n");
return -1;
}
@ -211,13 +212,13 @@ int init_video_decoder(CodecState *cs)
int init_audio_decoder(CodecState *cs, uint32_t audio_channels)
{
int rc;
cs->audio_decoder = opus_decoder_create(cs->audio_sample_rate, audio_channels, &rc );
if ( rc != OPUS_OK ){
cs->audio_decoder = opus_decoder_create(cs->audio_sample_rate, audio_channels, &rc );
if ( rc != OPUS_OK ) {
fprintf(stderr, "Error while starting audio decoder!\n");
return -1;
}
}
return 0;
}
@ -226,18 +227,22 @@ int init_video_encoder(CodecState *cs, uint16_t width, uint16_t height, uint32_t
{
vpx_codec_enc_cfg_t cfg;
int res = vpx_codec_enc_config_default(VIDEO_CODEC_ENCODER_INTERFACE, &cfg, 0);
if(res) {
if (res) {
printf("Failed to get config: %s\n", vpx_codec_err_to_string(res));
return -1;
}
cfg.rc_target_bitrate = video_bitrate;
cfg.g_w = width;
cfg.g_h = height;
if(vpx_codec_enc_init_ver(&cs->v_encoder, VIDEO_CODEC_ENCODER_INTERFACE, &cfg, 0, VPX_ENCODER_ABI_VERSION) != VPX_CODEC_OK) {
if (vpx_codec_enc_init_ver(&cs->v_encoder, VIDEO_CODEC_ENCODER_INTERFACE, &cfg, 0,
VPX_ENCODER_ABI_VERSION) != VPX_CODEC_OK) {
fprintf(stderr, "Failed to initialize encoder\n");
return -1;
}
return 0;
}
@ -247,57 +252,57 @@ int init_audio_encoder(CodecState *cs, uint32_t audio_channels)
cs->audio_encoder = opus_encoder_create(cs->audio_sample_rate, audio_channels, OPUS_APPLICATION_AUDIO, &err);
err = opus_encoder_ctl(cs->audio_encoder, OPUS_SET_BITRATE(cs->audio_bitrate));
err = opus_encoder_ctl(cs->audio_encoder, OPUS_SET_COMPLEXITY(10));
return err == OPUS_OK ? 0 : -1;
}
CodecState* codec_init_session ( uint32_t audio_bitrate,
uint16_t audio_frame_duration,
uint32_t audio_sample_rate,
uint32_t audio_channels,
CodecState *codec_init_session ( uint32_t audio_bitrate,
uint16_t audio_frame_duration,
uint32_t audio_sample_rate,
uint32_t audio_channels,
uint16_t video_width,
uint16_t video_height,
uint32_t video_bitrate )
{
CodecState* _retu = calloc(sizeof(CodecState), 1);
CodecState *_retu = calloc(sizeof(CodecState), 1);
assert(_retu);
_retu->audio_bitrate = audio_bitrate;
_retu->audio_sample_rate = audio_sample_rate;
/* Encoders */
if (!video_width || !video_height) {
video_width = 320;
video_height = 240;
}
if ( 0 == init_video_encoder(_retu, video_width, video_height, video_bitrate) )
if ( 0 == init_video_encoder(_retu, video_width, video_height, video_bitrate) )
printf("Video encoder initialized!\n");
if ( 0 == init_audio_encoder(_retu, audio_channels) )
if ( 0 == init_audio_encoder(_retu, audio_channels) )
printf("Audio encoder initialized!\n");
/* Decoders */
if ( 0 == init_video_decoder(_retu) )
printf("Video decoder initialized!\n");
if ( 0 == init_audio_decoder(_retu, audio_channels) )
printf("Audio decoder initialized!\n");
return _retu;
}
void codec_terminate_session ( CodecState* cs )
void codec_terminate_session ( CodecState *cs )
{
if ( cs->audio_encoder ) {
opus_encoder_destroy(cs->audio_encoder);
printf("Terminated encoder!\n");
}
if ( cs->audio_decoder ) {
opus_decoder_destroy(cs->audio_decoder);
printf("Terminated decoder!\n");

View File

@ -1,5 +1,5 @@
/** media.h
*
*
* Audio and video codec intitialization, encoding/decoding and playback
*
* Copyright (C) 2013 Tox project All Rights Reserved.
@ -39,7 +39,7 @@
#include <opus/opus.h>
typedef struct _CodecState{
typedef struct _CodecState {
/* video encoding */
vpx_codec_ctx_t v_encoder;
@ -67,14 +67,14 @@ int queue(struct jitter_buffer *q, RTPMessage *pk);
RTPMessage *dequeue(struct jitter_buffer *q, int *success);
CodecState* codec_init_session ( uint32_t audio_bitrate,
uint16_t audio_frame_duration,
uint32_t audio_sample_rate,
uint32_t audio_channels,
CodecState *codec_init_session ( uint32_t audio_bitrate,
uint16_t audio_frame_duration,
uint32_t audio_sample_rate,
uint32_t audio_channels,
uint16_t video_width,
uint16_t video_height,
uint32_t video_bitrate );
void codec_terminate_session(CodecState* cs);
void codec_terminate_session(CodecState *cs);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/** toxmsi.h
*
*
* Copyright (C) 2013 Tox project All Rights Reserved.
*
* This file is part of Tox.
@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
*
*
*
* Report bugs/suggestions at #tox-dev @ freenode.net:6667
*/
@ -33,7 +33,7 @@
#define CALL_ID_LEN 12
typedef void* ( *MSICallback ) ( void* arg );
typedef void *( *MSICallback ) ( void *arg );
/**
@ -60,21 +60,21 @@ typedef enum {
/**
* @brief The call struct.
*
*
*/
typedef struct _MSICall { /* Call info structure */
MSICallState state;
MSICallType type_local; /* Type of payload user is ending */
MSICallType* type_peer; /* Type of payload others are sending */
MSICallType *type_peer; /* Type of payload others are sending */
uint8_t id[CALL_ID_LEN]; /* Random value identifying the call */
uint8_t* key_local; /* The key for encryption */
uint8_t* key_peer; /* The key for decryption */
uint8_t *key_local; /* The key for encryption */
uint8_t *key_peer; /* The key for decryption */
uint8_t* nonce_local; /* Local nonce */
uint8_t* nonce_peer; /* Peer nonce */
uint8_t *nonce_local; /* Local nonce */
uint8_t *nonce_peer; /* Peer nonce */
int ringing_tout_ms; /* Ringing timeout in ms */
@ -84,39 +84,39 @@ typedef struct _MSICall { /* Call info structure */
pthread_mutex_t mutex; /* It's to be assumed that call will have
* seperate thread so add mutex
*/
uint32_t* peers;
uint16_t peer_count;
uint32_t *peers;
uint16_t peer_count;
} MSICall;
/**
* @brief Control session struct
*
*
*/
typedef struct _MSISession {
/* Call handler */
struct _MSICall* call;
struct _MSICall *call;
int last_error_id; /* Determine the last error */
const uint8_t* last_error_str;
const uint8_t *last_error_str;
const uint8_t* ua_name;
const uint8_t *ua_name;
void *agent_handler; /* Pointer to an object that is handling msi */
Messenger *messenger_handle;
void* agent_handler; /* Pointer to an object that is handling msi */
Messenger* messenger_handle;
uint32_t frequ;
uint32_t call_timeout; /* Time of the timeout for some action to end; 0 if infinite */
} MSISession;
/**
* @brief Callbacks ids that handle the states
/**
* @brief Callbacks ids that handle the states
*/
typedef enum {
/* Requests */
@ -140,7 +140,7 @@ typedef enum {
/**
* @brief Callback setter.
*
*
* @param callback The callback.
* @param id The id.
* @return void
@ -150,84 +150,84 @@ void msi_register_callback(MSICallback callback, MSICallbackID id);
/**
* @brief Start the control session.
*
*
* @param messenger Tox* object.
* @param user_agent User agent, i.e. 'Venom'; 'QT-gui'
* @return MSISession* The created session.
* @retval NULL Error occured.
*/
MSISession* msi_init_session ( Messenger* messenger, const uint8_t* ua_name );
MSISession *msi_init_session ( Messenger *messenger, const uint8_t *ua_name );
/**
* @brief Terminate control session.
*
*
* @param session The session
* @return int
*/
int msi_terminate_session ( MSISession* session );
int msi_terminate_session ( MSISession *session );
/**
* @brief Send invite request to friend_id.
*
*
* @param session Control session.
* @param call_type Type of the call. Audio or Video(both audio and video)
* @param rngsec Ringing timeout.
* @param friend_id The friend.
* @return int
*/
int msi_invite ( MSISession* session, MSICallType call_type, uint32_t rngsec, uint32_t friend_id );
int msi_invite ( MSISession *session, MSICallType call_type, uint32_t rngsec, uint32_t friend_id );
/**
* @brief Hangup active call.
*
*
* @param session Control session.
* @return int
* @return int
* @retval -1 Error occured.
* @retval 0 Success.
*/
int msi_hangup ( MSISession* session );
int msi_hangup ( MSISession *session );
/**
* @brief Answer active call request.
*
*
* @param session Control session.
* @param call_type Answer with Audio or Video(both).
* @return int
*/
int msi_answer ( MSISession* session, MSICallType call_type );
int msi_answer ( MSISession *session, MSICallType call_type );
/**
* @brief Cancel request.
*
*
* @param session Control session.
* @param peer To which peer.
* @param reason Set optional reason header. Pass NULL if none.
* @return int
*/
int msi_cancel ( MSISession* session, uint32_t peer, const uint8_t* reason );
int msi_cancel ( MSISession *session, uint32_t peer, const uint8_t *reason );
/**
* @brief Reject request.
*
*
* @param session Control session.
* @param reason Set optional reason header. Pass NULL if none.
* @return int
*/
int msi_reject ( MSISession* session, const uint8_t* reason );
int msi_reject ( MSISession *session, const uint8_t *reason );
/**
* @brief Terminate the current call.
*
*
* @param session Control session.
* @return int
*/
int msi_stopcall ( MSISession* session );
int msi_stopcall ( MSISession *session );
#endif /* __TOXMSI */

972
toxav/phone.c Executable file → Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/** toxrtp.h
*
*
* Copyright (C) 2013 Tox project All Rights Reserved.
*
* This file is part of Tox.
@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
*
*
*
* Report bugs/suggestions at #tox-dev @ freenode.net:6667
*/
@ -38,7 +38,7 @@
/**
* @brief Standard rtp header
*
*
*/
typedef struct _RTPHeader {
@ -47,7 +47,7 @@ typedef struct _RTPHeader {
uint16_t sequnum; /* Sequence Number */
uint32_t timestamp; /* Timestamp */
uint32_t ssrc; /* SSRC */
uint32_t* csrc; /* CSRC's table */
uint32_t *csrc; /* CSRC's table */
uint32_t length; /* Length of the header in payload string. */
} RTPHeader;
@ -55,29 +55,29 @@ typedef struct _RTPHeader {
/**
* @brief Standard rtp extension header.
*
*
*/
typedef struct _RTPExtHeader {
uint16_t type; /* Extension profile */
uint16_t length; /* Number of extensions */
uint32_t* table; /* Extension's table */
uint32_t *table; /* Extension's table */
} RTPExtHeader;
/**
* @brief Standard rtp message.
*
*
*/
typedef struct _RTPMessage {
RTPHeader* header;
RTPExtHeader* ext_header;
RTPHeader *header;
RTPExtHeader *ext_header;
uint8_t data[MAX_RTP_SIZE];
uint32_t length;
IP_Port from;
struct _RTPMessage* next;
struct _RTPMessage *next;
} RTPMessage;
@ -87,7 +87,7 @@ typedef struct _RTPMessage {
* the entire session. There are functions for manipulating
* the session so tend to use those instead of directly modifying
* session parameters.
*
*
*/
typedef struct _RTPSession {
uint8_t version;
@ -100,14 +100,14 @@ typedef struct _RTPSession {
uint16_t rsequnum; /* Check when recving msg */
uint32_t timestamp;
uint32_t ssrc;
uint32_t* csrc;
uint32_t *csrc;
/* If some additional data must be sent via message
* apply it here. Only by allocating this member you will be
* automatically placing it within a message.
*/
RTPExtHeader* ext_header;
RTPExtHeader *ext_header;
/* External header identifiers */
int resolution;
int framerate;
@ -117,15 +117,15 @@ typedef struct _RTPSession {
* call structure don't allocate or free
*/
const uint8_t* encrypt_key;
const uint8_t* decrypt_key;
uint8_t* encrypt_nonce;
uint8_t* decrypt_nonce;
const uint8_t *encrypt_key;
const uint8_t *decrypt_key;
uint8_t *encrypt_nonce;
uint8_t *decrypt_nonce;
uint8_t* nonce_cycle;
uint8_t *nonce_cycle;
RTPMessage* oldest_msg;
RTPMessage* last_msg; /* tail */
RTPMessage *oldest_msg;
RTPMessage *last_msg; /* tail */
/* Msg prefix for core to know when recving */
uint8_t prefix;
@ -138,28 +138,28 @@ typedef struct _RTPSession {
/**
* @brief Release all messages held by session.
*
*
* @param session The session.
* @return int
* @retval -1 Error occurred.
* @retval 0 Success.
*/
int rtp_release_session_recv ( RTPSession* session );
int rtp_release_session_recv ( RTPSession *session );
/**
* @brief Get's oldest message in the list.
*
*
* @param session Where the list is.
* @return RTPMessage* The message. You need to call rtp_msg_free() to free it.
* @retval NULL No messages in the list, or no list.
*/
RTPMessage* rtp_recv_msg ( RTPSession* session );
RTPMessage *rtp_recv_msg ( RTPSession *session );
/**
* @brief Sends msg to _RTPSession::dest
*
*
* @param session The session.
* @param msg The message
* @param messenger Tox* object.
@ -167,23 +167,23 @@ RTPMessage* rtp_recv_msg ( RTPSession* session );
* @retval -1 On error.
* @retval 0 On success.
*/
int rtp_send_msg ( RTPSession* session, Messenger* messenger, const uint8_t* data, uint16_t length );
int rtp_send_msg ( RTPSession *session, Messenger *messenger, const uint8_t *data, uint16_t length );
/**
* @brief Speaks for it self.
*
*
* @param session The control session msg belongs to. It can be NULL.
* @param msg The message.
* @return void
*/
void rtp_free_msg ( RTPSession* session, RTPMessage* msg );
void rtp_free_msg ( RTPSession *session, RTPMessage *msg );
/**
* @brief Must be called before calling any other rtp function. It's used
* to initialize RTP control session.
*
*
* @param payload_type Type of payload used to send. You can use values in toxmsi.h::MSICallType
* @param messenger Tox* object.
* @param friend_num Friend id.
@ -194,25 +194,25 @@ void rtp_free_msg ( RTPSession* session, RTPMessage* msg );
* @return RTPSession* Created control session.
* @retval NULL Error occurred.
*/
RTPSession* rtp_init_session ( int payload_type,
Messenger* messenger,
int friend_num,
const uint8_t* encrypt_key,
const uint8_t* decrypt_key,
const uint8_t* encrypt_nonce,
const uint8_t* decrypt_nonce );
RTPSession *rtp_init_session ( int payload_type,
Messenger *messenger,
int friend_num,
const uint8_t *encrypt_key,
const uint8_t *decrypt_key,
const uint8_t *encrypt_nonce,
const uint8_t *decrypt_nonce );
/**
* @brief Terminate the session.
*
*
* @param session The session.
* @param messenger The messenger who owns the session
* @return int
* @retval -1 Error occurred.
* @retval 0 Success.
*/
int rtp_terminate_session ( RTPSession* session, Messenger* messenger );
int rtp_terminate_session ( RTPSession *session, Messenger *messenger );

View File

@ -1,5 +1,5 @@
/** toxav.c
*
*
* Copyright (C) 2013 Tox project All Rights Reserved.
*
* This file is part of Tox.
@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
*
*
*
* Report bugs/suggestions at #tox-dev @ freenode.net:6667
*/
@ -44,27 +44,26 @@ typedef enum {
ts_closing,
ts_running,
ts_closed
} ThreadState;
typedef struct _ToxAv
{
Messenger* messenger;
MSISession* msi_session; /** Main msi session */
RTPSession* rtp_sessions[2]; /* Audio is first and video is second */
struct jitter_buffer* j_buf;
CodecState* cs;
void* agent_handler;
typedef struct _ToxAv {
Messenger *messenger;
MSISession *msi_session; /** Main msi session */
RTPSession *rtp_sessions[2]; /* Audio is first and video is second */
struct jitter_buffer *j_buf;
CodecState *cs;
void *agent_handler;
} ToxAv;
/**
* @brief Start new A/V session. There can only be one session at the time. If you register more
* it will result in undefined behaviour.
*
*
* @param messenger The messenger handle.
* @param useragent The agent handling A/V session (i.e. phone).
* @param ua_name Useragent name.
@ -73,67 +72,69 @@ typedef struct _ToxAv
* @return ToxAv*
* @retval NULL On error.
*/
ToxAv* toxav_new( Tox* messenger, void* useragent, const char* ua_name , uint16_t video_width, uint16_t video_height)
ToxAv *toxav_new( Tox *messenger, void *useragent, const char *ua_name , uint16_t video_width, uint16_t video_height)
{
ToxAv* av = calloc ( sizeof(ToxAv), 1);
ToxAv *av = calloc ( sizeof(ToxAv), 1);
if (av == NULL)
return NULL;
av->messenger = (Messenger *)messenger;
av->msi_session = msi_init_session(av->messenger, (const unsigned char*) ua_name );
av->msi_session = msi_init_session(av->messenger, (const unsigned char *) ua_name );
av->msi_session->agent_handler = av;
av->rtp_sessions[0] = av->rtp_sessions [1] = NULL;
/* NOTE: This should be user defined or? */
av->j_buf = create_queue(20);
av->cs = codec_init_session(AUDIO_BITRATE, AUDIO_FRAME_DURATION, AUDIO_SAMPLE_RATE, AUDIO_CHANNELS, video_width, video_height, VIDEO_BITRATE);
av->cs = codec_init_session(AUDIO_BITRATE, AUDIO_FRAME_DURATION, AUDIO_SAMPLE_RATE, AUDIO_CHANNELS, video_width,
video_height, VIDEO_BITRATE);
av->agent_handler = useragent;
return av;
}
/**
* @brief Remove A/V session.
*
*
* @param av Handler.
* @return void
*/
void toxav_kill ( ToxAv* av )
{
void toxav_kill ( ToxAv *av )
{
msi_terminate_session(av->msi_session);
if ( av->rtp_sessions[audio_index] ) {
rtp_terminate_session(av->rtp_sessions[audio_index], av->msi_session->messenger_handle);
}
if ( av->rtp_sessions[video_index] ) {
rtp_terminate_session(av->rtp_sessions[video_index], av->msi_session->messenger_handle);
}
codec_terminate_session(av->cs);
free(av);
}
/**
* @brief Register callback for call state.
*
*
* @param callback The callback
* @param id One of the ToxAvCallbackID values
* @return void
*/
void toxav_register_callstate_callback ( ToxAVCallback callback, ToxAvCallbackID id )
void toxav_register_callstate_callback ( ToxAVCallback callback, ToxAvCallbackID id )
{
msi_register_callback((MSICallback)callback, (MSICallbackID) id);
}
/**
* @brief Call user. Use its friend_id.
*
*
* @param av Handler.
* @param user The user.
* @param call_type Call type.
@ -142,68 +143,68 @@ void toxav_register_callstate_callback ( ToxAVCallback callback, ToxAvCallbackID
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_call (ToxAv* av, int user, ToxAvCallType call_type, int ringing_seconds )
int toxav_call (ToxAv *av, int user, ToxAvCallType call_type, int ringing_seconds )
{
if ( av->msi_session->call ) {
return ErrorAlreadyInCall;
}
return msi_invite(av->msi_session, call_type, ringing_seconds * 1000, user);
}
/**
* @brief Hangup active call.
*
*
* @param av Handler.
* @return int
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_hangup ( ToxAv* av )
int toxav_hangup ( ToxAv *av )
{
if ( !av->msi_session->call ) {
return ErrorNoCall;
}
if ( av->msi_session->call->state != call_active ) {
return ErrorInvalidState;
}
return msi_hangup(av->msi_session);
}
/**
* @brief Answer incomming call.
*
*
* @param av Handler.
* @param call_type Answer with...
* @return int
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_answer ( ToxAv* av, ToxAvCallType call_type )
int toxav_answer ( ToxAv *av, ToxAvCallType call_type )
{
if ( !av->msi_session->call ) {
return ErrorNoCall;
}
if ( av->msi_session->call->state != call_starting ) {
return ErrorInvalidState;
}
return msi_answer(av->msi_session, call_type);
}
/**
* @brief Reject incomming call.
*
*
* @param av Handler.
* @param reason Optional reason. Set NULL if none.
* @return int
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_reject ( ToxAv* av, const char* reason )
int toxav_reject ( ToxAv *av, const char *reason )
{
if ( !av->msi_session->call ) {
return ErrorNoCall;
@ -213,126 +214,127 @@ int toxav_reject ( ToxAv* av, const char* reason )
return ErrorInvalidState;
}
return msi_reject(av->msi_session, (const uint8_t*) reason);
return msi_reject(av->msi_session, (const uint8_t *) reason);
}
/**
* @brief Cancel outgoing request.
*
*
* @param av Handler.
* @param reason Optional reason.
* @return int
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_cancel ( ToxAv* av, const char* reason )
int toxav_cancel ( ToxAv *av, const char *reason )
{
if ( !av->msi_session->call ) {
return ErrorNoCall;
}
return msi_cancel(av->msi_session, 0, (const uint8_t*)reason);
return msi_cancel(av->msi_session, 0, (const uint8_t *)reason);
}
/**
* @brief Terminate transmission. Note that transmission will be terminated without informing remote peer.
*
*
* @param av Handler.
* @return int
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_stop_call ( ToxAv* av )
int toxav_stop_call ( ToxAv *av )
{
if ( !av->msi_session->call ) {
return ErrorNoCall;
}
return msi_stopcall(av->msi_session);
}
/**
* @brief Must be call before any RTP transmission occurs.
*
*
* @param av Handler.
* @return int
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_prepare_transmission ( ToxAv* av )
int toxav_prepare_transmission ( ToxAv *av )
{
assert(av->msi_session);
if ( !av->msi_session || !av->msi_session->call ) {
return ErrorNoCall;
}
av->rtp_sessions[audio_index] = rtp_init_session(
type_audio,
av->messenger,
av->msi_session->call->peers[0],
av->msi_session->call->key_peer,
av->msi_session->call->key_local,
av->msi_session->call->nonce_peer,
av->msi_session->call->nonce_local
type_audio,
av->messenger,
av->msi_session->call->peers[0],
av->msi_session->call->key_peer,
av->msi_session->call->key_local,
av->msi_session->call->nonce_peer,
av->msi_session->call->nonce_local
);
if ( !av->rtp_sessions[audio_index] ) {
fprintf(stderr, "Error while starting audio RTP session!\n");
return ErrorStartingAudioRtp;
}
av->rtp_sessions[video_index] = rtp_init_session (
type_video,
av->messenger,
av->msi_session->call->peers[0],
av->msi_session->call->key_peer,
av->msi_session->call->key_local,
av->msi_session->call->nonce_peer,
av->msi_session->call->nonce_local
av->rtp_sessions[video_index] = rtp_init_session (
type_video,
av->messenger,
av->msi_session->call->peers[0],
av->msi_session->call->key_peer,
av->msi_session->call->key_local,
av->msi_session->call->nonce_peer,
av->msi_session->call->nonce_local
);
if ( !av->rtp_sessions[video_index] ) {
fprintf(stderr, "Error while starting video RTP session!\n");
return ErrorStartingVideoRtp;
}
return ErrorNone;
}
/**
* @brief Call this at the end of the transmission.
*
*
* @param av Handler.
* @return int
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_kill_transmission ( ToxAv* av )
int toxav_kill_transmission ( ToxAv *av )
{
/* Both sessions should be active at any time */
if ( !av->rtp_sessions[0] || !av->rtp_sessions[0] )
return ErrorNoTransmission;
if ( -1 == rtp_terminate_session(av->rtp_sessions[audio_index], av->messenger) ) {
fprintf(stderr, "Error while terminating audio RTP session!\n");
return ErrorTerminatingAudioRtp;
}
if ( -1 == rtp_terminate_session(av->rtp_sessions[video_index], av->messenger) ) {
fprintf(stderr, "Error while terminating video RTP session!\n");
return ErrorTerminatingVideoRtp;
}
return ErrorNone;
}
/**
* @brief Send RTP payload.
*
*
* @param av Handler.
* @param type Type of payload.
* @param payload The payload.
@ -341,7 +343,7 @@ int toxav_kill_transmission ( ToxAv* av )
* @retval 0 Success.
* @retval -1 Failure.
*/
inline__ int toxav_send_rtp_payload ( ToxAv* av, ToxAvCallType type, const uint8_t* payload, uint16_t length )
inline__ int toxav_send_rtp_payload ( ToxAv *av, ToxAvCallType type, const uint8_t *payload, uint16_t length )
{
if ( av->rtp_sessions[type - TypeAudio] )
return rtp_send_msg ( av->rtp_sessions[type - TypeAudio], av->msi_session->messenger_handle, payload, length );
@ -350,7 +352,7 @@ inline__ int toxav_send_rtp_payload ( ToxAv* av, ToxAvCallType type, const uint8
/**
* @brief Receive RTP payload.
*
*
* @param av Handler.
* @param type Type of the payload.
* @param dest Storage.
@ -358,123 +360,131 @@ inline__ int toxav_send_rtp_payload ( ToxAv* av, ToxAvCallType type, const uint8
* @retval ToxAvError On Error.
* @retval >=0 Size of received payload.
*/
inline__ int toxav_recv_rtp_payload ( ToxAv* av, ToxAvCallType type, uint8_t* dest )
inline__ int toxav_recv_rtp_payload ( ToxAv *av, ToxAvCallType type, uint8_t *dest )
{
if ( !dest ) return ErrorInternal;
if ( !av->rtp_sessions[type - TypeAudio] ) return ErrorNoRtpSession;
RTPMessage* message;
RTPMessage *message;
if ( type == TypeAudio ) {
do {
message = rtp_recv_msg(av->rtp_sessions[audio_index]);
if (message) {
/* push the packet into the queue */
queue(av->j_buf, message);
}
} while(message);
} while (message);
int success = 0;
message = dequeue(av->j_buf, &success);
if ( success == 2) return ErrorAudioPacketLost;
}
else {
} else {
message = rtp_recv_msg(av->rtp_sessions[video_index]);
}
if ( message ) {
if ( message ) {
memcpy(dest, message->data, message->length);
int length = message->length;
rtp_free_msg(NULL, message);
return length;
}
return 0;
}
/**
* @brief Receive decoded video packet.
*
*
* @param av Handler.
* @param output Storage.
* @return int
* @return int
* @retval 0 Success.
* @retval ToxAvError On Error.
*/
inline__ int toxav_recv_video ( ToxAv* av, vpx_image_t **output)
inline__ int toxav_recv_video ( ToxAv *av, vpx_image_t **output)
{
if ( !output ) return ErrorInternal;
uint8_t packet [RTP_PAYLOAD_SIZE];
int recved_size = 0;
do {
recved_size = toxav_recv_rtp_payload(av, TypeVideo, packet);
if (recved_size > 0) {
printf("decode: %s\n", vpx_codec_err_to_string(vpx_codec_decode(&av->cs->v_decoder, packet, recved_size, NULL, 0)));
}
}while (recved_size > 0);
} while (recved_size > 0);
vpx_codec_iter_t iter = NULL;
vpx_image_t *img;
img = vpx_codec_get_frame(&av->cs->v_decoder, &iter);
if (img == NULL)
return ErrorInternal;
*output = img;
return 0;
}
/**
* @brief Encode and send video packet.
*
*
* @param av Handler.
* @param input The packet.
* @return int
* @retval 0 Success.
* @retval ToxAvError On error.
*/
inline__ int toxav_send_video ( ToxAv* av, vpx_image_t *input)
inline__ int toxav_send_video ( ToxAv *av, vpx_image_t *input)
{
if (vpx_codec_encode(&av->cs->v_encoder, input, av->cs->frame_counter, 1, 0, MAX_ENCODE_TIME_US) != VPX_CODEC_OK) {
printf("could not encode video frame\n");
return ErrorInternal;
}
++av->cs->frame_counter;
vpx_codec_iter_t iter = NULL;
const vpx_codec_cx_pkt_t *pkt;
int sent = 0;
while( (pkt = vpx_codec_get_cx_data(&av->cs->v_encoder, &iter)) ) {
while ( (pkt = vpx_codec_get_cx_data(&av->cs->v_encoder, &iter)) ) {
if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) {
if (toxav_send_rtp_payload(av, TypeVideo, pkt->data.frame.buf, pkt->data.frame.sz) != -1)
++sent;
}
}
if (sent > 0)
return 0;
return ErrorInternal;
}
/**
* @brief Receive decoded audio frame.
*
*
* @param av Handler.
* @param frame_size ...
* @param dest Destination of the packet. Make sure it has enough space for
* @param dest Destination of the packet. Make sure it has enough space for
* RTP_PAYLOAD_SIZE bytes.
* @return int
* @retval >=0 Size of received packet.
* @retval ToxAvError On error.
*/
inline__ int toxav_recv_audio ( ToxAv* av, int frame_size, int16_t* dest )
inline__ int toxav_recv_audio ( ToxAv *av, int frame_size, int16_t *dest )
{
if ( !dest ) return ErrorInternal;
uint8_t packet [RTP_PAYLOAD_SIZE];
int recved_size = toxav_recv_rtp_payload(av, TypeAudio, packet);
@ -482,7 +492,7 @@ inline__ int toxav_recv_audio ( ToxAv* av, int frame_size, int16_t* dest )
if ( recved_size == ErrorAudioPacketLost ) {
printf("Lost packet\n");
return opus_decode(av->cs->audio_decoder, NULL, 0, dest, frame_size, 1);
} else if ( recved_size ){
} else if ( recved_size ) {
return opus_decode(av->cs->audio_decoder, packet, recved_size, dest, frame_size, 0);
} else {
return 0; /* Nothing received */
@ -491,7 +501,7 @@ inline__ int toxav_recv_audio ( ToxAv* av, int frame_size, int16_t* dest )
/**
* @brief Encode and send audio frame.
*
*
* @param av Handler.
* @param frame The frame.
* @param frame_size It's size.
@ -499,10 +509,11 @@ inline__ int toxav_recv_audio ( ToxAv* av, int frame_size, int16_t* dest )
* @retval 0 Success.
* @retval ToxAvError On error.
*/
inline__ int toxav_send_audio ( ToxAv* av, const int16_t* frame, int frame_size)
inline__ int toxav_send_audio ( ToxAv *av, const int16_t *frame, int frame_size)
{
uint8_t temp_data[RTP_PAYLOAD_SIZE];
int32_t ret = opus_encode(av->cs->audio_encoder, frame, frame_size, temp_data, sizeof(temp_data));
if (ret <= 0)
return ErrorInternal;
@ -511,29 +522,30 @@ inline__ int toxav_send_audio ( ToxAv* av, const int16_t* frame, int frame_size)
/**
* @brief Get peer transmission type. It can either be audio or video.
*
*
* @param av Handler.
* @param peer The peer
* @return int
* @retval ToxAvCallType On success.
* @retval ToxAvError On error.
*/
int toxav_get_peer_transmission_type ( ToxAv* av, int peer )
int toxav_get_peer_transmission_type ( ToxAv *av, int peer )
{
assert(av->msi_session);
if ( peer < 0 || !av->msi_session->call || av->msi_session->call->peer_count <= peer )
return ErrorInternal;
return av->msi_session->call->type_peer[peer];
}
/**
* @brief Get reference to an object that is handling av session.
*
*
* @param av Handler.
* @return void*
*/
void* toxav_get_agent_handler ( ToxAv* av )
void *toxav_get_agent_handler ( ToxAv *av )
{
return av->agent_handler;
}

View File

@ -1,5 +1,5 @@
/** toxav.h
*
*
* Copyright (C) 2013 Tox project All Rights Reserved.
*
* This file is part of Tox.
@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
*
*
*
* Report bugs/suggestions at #tox-dev @ freenode.net:6667
*/
@ -29,7 +29,7 @@
/* vpx_image_t */
#include <vpx/vpx_image.h>
typedef void* ( *ToxAVCallback ) ( void* arg );
typedef void *( *ToxAVCallback ) ( void *arg );
typedef struct _ToxAv ToxAv;
#ifndef __TOX_DEFINED__
@ -61,7 +61,7 @@ typedef struct Tox Tox;
#define MAX_ENCODE_TIME_US ((1000 / 60) * 1000)
/**
/**
* @brief Callbacks ids that handle the call states.
*/
typedef enum {
@ -71,16 +71,16 @@ typedef enum {
OnCancel,
OnReject,
OnEnd,
/* Responses */
OnRinging,
OnStarting,
OnEnding,
/* Protocol */
OnError,
OnRequestTimeout
} ToxAvCallbackID;
@ -95,7 +95,7 @@ typedef enum {
/**
* @brief Error indicators.
*
*
*/
typedef enum {
ErrorNone = 0,
@ -110,14 +110,14 @@ typedef enum {
ErrorNoTransmission = -9, /* Returned in toxav_kill_transmission() */
ErrorTerminatingAudioRtp = -10, /* Returned in toxav_kill_transmission() */
ErrorTerminatingVideoRtp = -11, /* Returned in toxav_kill_transmission() */
} ToxAvError;
/**
* @brief Start new A/V session. There can only be one session at the time. If you register more
* it will result in undefined behaviour.
*
*
* @param messenger The messenger handle.
* @param useragent The agent handling A/V session (i.e. phone).
* @param ua_name Useragent name.
@ -126,19 +126,19 @@ typedef enum {
* @return ToxAv*
* @retval NULL On error.
*/
ToxAv* toxav_new(Tox* messenger, void* useragent, const char* ua_name, uint16_t video_width, uint16_t video_height);
ToxAv *toxav_new(Tox *messenger, void *useragent, const char *ua_name, uint16_t video_width, uint16_t video_height);
/**
* @brief Remove A/V session.
*
*
* @param av Handler.
* @return void
*/
void toxav_kill(ToxAv* av);
void toxav_kill(ToxAv *av);
/**
* @brief Register callback for call state.
*
*
* @param callback The callback
* @param id One of the ToxAvCallbackID values
* @return void
@ -147,7 +147,7 @@ void toxav_register_callstate_callback (ToxAVCallback callback, ToxAvCallbackID
/**
* @brief Call user. Use its friend_id.
*
*
* @param av Handler.
* @param user The user.
* @param call_type Call type.
@ -156,119 +156,119 @@ void toxav_register_callstate_callback (ToxAVCallback callback, ToxAvCallbackID
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_call(ToxAv* av, int user, ToxAvCallType call_type, int ringing_seconds);
int toxav_call(ToxAv *av, int user, ToxAvCallType call_type, int ringing_seconds);
/**
* @brief Hangup active call.
*
*
* @param av Handler.
* @return int
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_hangup(ToxAv* av);
int toxav_hangup(ToxAv *av);
/**
* @brief Answer incomming call.
*
*
* @param av Handler.
* @param call_type Answer with...
* @return int
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_answer(ToxAv* av, ToxAvCallType call_type );
int toxav_answer(ToxAv *av, ToxAvCallType call_type );
/**
* @brief Reject incomming call.
*
*
* @param av Handler.
* @param reason Optional reason. Set NULL if none.
* @return int
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_reject(ToxAv* av, const char* reason);
int toxav_reject(ToxAv *av, const char *reason);
/**
* @brief Cancel outgoing request.
*
*
* @param av Handler.
* @param reason Optional reason.
* @return int
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_cancel(ToxAv* av, const char* reason);
int toxav_cancel(ToxAv *av, const char *reason);
/**
* @brief Terminate transmission. Note that transmission will be terminated without informing remote peer.
*
*
* @param av Handler.
* @return int
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_stop_call(ToxAv* av);
int toxav_stop_call(ToxAv *av);
/**
* @brief Must be call before any RTP transmission occurs.
*
*
* @param av Handler.
* @return int
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_prepare_transmission(ToxAv* av);
int toxav_prepare_transmission(ToxAv *av);
/**
* @brief Call this at the end of the transmission.
*
*
* @param av Handler.
* @return int
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_kill_transmission(ToxAv* av);
int toxav_kill_transmission(ToxAv *av);
/**
* @brief Receive decoded video packet.
*
*
* @param av Handler.
* @param output Storage.
* @return int
* @return int
* @retval 0 Success.
* @retval ToxAvError On Error.
*/
int toxav_recv_video ( ToxAv* av, vpx_image_t **output);
int toxav_recv_video ( ToxAv *av, vpx_image_t **output);
/**
* @brief Receive decoded audio frame.
*
*
* @param av Handler.
* @param frame_size ...
* @param dest Destination of the packet. Make sure it has enough space for
* @param dest Destination of the packet. Make sure it has enough space for
* RTP_PAYLOAD_SIZE bytes.
* @return int
* @retval >=0 Size of received packet.
* @retval ToxAvError On error.
*/
int toxav_recv_audio( ToxAv* av, int frame_size, int16_t* dest );
int toxav_recv_audio( ToxAv *av, int frame_size, int16_t *dest );
/**
* @brief Encode and send video packet.
*
*
* @param av Handler.
* @param input The packet.
* @return int
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_send_video ( ToxAv* av, vpx_image_t *input);
int toxav_send_video ( ToxAv *av, vpx_image_t *input);
/**
* @brief Encode and send audio frame.
*
*
* @param av Handler.
* @param frame The frame.
* @param frame_size It's size.
@ -276,25 +276,25 @@ int toxav_send_video ( ToxAv* av, vpx_image_t *input);
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_send_audio ( ToxAv* av, const int16_t* frame, int frame_size);
int toxav_send_audio ( ToxAv *av, const int16_t *frame, int frame_size);
/**
* @brief Get peer transmission type. It can either be audio or video.
*
*
* @param av Handler.
* @param peer The peer
* @return int
* @retval ToxAvCallType On success.
* @retval ToxAvError On error.
*/
int toxav_get_peer_transmission_type ( ToxAv* av, int peer );
int toxav_get_peer_transmission_type ( ToxAv *av, int peer );
/**
* @brief Get reference to an object that is handling av session.
*
*
* @param av Handler.
* @return void*
*/
void* toxav_get_agent_handler ( ToxAv* av );
void *toxav_get_agent_handler ( ToxAv *av );
#endif /* __TOXAV */