Added custom callback data and capability identifier

This commit is contained in:
mannol 2014-03-11 00:36:47 +01:00
parent 7b87975dec
commit d1fbbae5e9
8 changed files with 69 additions and 155 deletions

View File

@ -273,12 +273,12 @@ CodecState *codec_init_session ( uint32_t audio_bitrate,
video_height = 240; */
}
else {
retu->supported_actions |= ( 0 == init_video_encoder(retu, video_width, video_height, video_bitrate) ) ? v_encoding : 0;
retu->supported_actions |= ( 0 == init_video_decoder(retu) ) ? v_decoding : 0;
retu->capabilities |= ( 0 == init_video_encoder(retu, video_width, video_height, video_bitrate) ) ? v_encoding : 0;
retu->capabilities |= ( 0 == init_video_decoder(retu) ) ? v_decoding : 0;
}
retu->supported_actions |= ( 0 == init_audio_encoder(retu, audio_channels) ) ? a_encoding : 0;
retu->supported_actions |= ( 0 == init_audio_decoder(retu, audio_channels) ) ? a_decoding : 0;
retu->capabilities |= ( 0 == init_audio_encoder(retu, audio_channels) ) ? a_encoding : 0;
retu->capabilities |= ( 0 == init_audio_decoder(retu, audio_channels) ) ? a_decoding : 0;
return retu;
}
@ -295,9 +295,9 @@ void codec_terminate_session ( CodecState *cs )
/* TODO: Terminate video
* Do what???
*/
if ( cs->supported_actions & v_decoding )
if ( cs->capabilities & v_decoding )
vpx_codec_destroy(&cs->v_decoder);
if ( cs->supported_actions & v_encoding )
if ( cs->capabilities & v_encoding )
vpx_codec_destroy(&cs->v_encoder);
}

View File

@ -38,14 +38,14 @@
/* Audio encoding/decoding */
#include <opus/opus.h>
enum _actions
typedef enum _Capabilities
{
no_actions,
none,
a_encoding = 1 << 0,
a_decoding = 1 << 1,
v_encoding = 1 << 2,
v_decoding = 1 << 3
};
} Capabilities;
typedef struct _CodecState {
@ -64,7 +64,7 @@ typedef struct _CodecState {
/* audio decoding */
OpusDecoder *audio_decoder;
uint64_t supported_actions; /* Encoding decoding etc */
uint64_t capabilities; /* supports*/
} CodecState;

View File

@ -112,8 +112,12 @@ typedef struct _MSIMessage {
} MSIMessage;
static struct _Callbacks {
MSICallback function;
void* data;
} callbacks[10] = {0};
static MSICallback callbacks[10] = {0};
/*static MSICallback callbacks[10] = {0};*/
/* define strings for the identifiers */
@ -675,7 +679,7 @@ int handle_error ( MSISession *session, MSICallError errid, uint32_t to )
session->last_error_id = errid;
session->last_error_str = stringify_error ( errid );
if ( callbacks[MSI_OnError] ) event.rise ( callbacks[MSI_OnError], session->agent_handler );
if ( callbacks[MSI_OnError].function ) event.rise ( callbacks[MSI_OnError].function, callbacks[MSI_OnError].data );
return 0;
}
@ -732,8 +736,8 @@ void *handle_timeout ( void *arg )
}
if ( callbacks[MSI_OnRequestTimeout] ) callbacks[MSI_OnRequestTimeout] ( _session->agent_handler );
if ( callbacks[MSI_OnEnding] ) callbacks[MSI_OnEnding ] ( _session->agent_handler );
if ( callbacks[MSI_OnRequestTimeout].function ) callbacks[MSI_OnRequestTimeout].function ( callbacks[MSI_OnRequestTimeout].data );
if ( callbacks[MSI_OnEnding].function ) callbacks[MSI_OnEnding ].function ( callbacks[MSI_OnEnding].data );
return NULL;
}
@ -869,7 +873,7 @@ int handle_recv_invite ( MSISession *session, MSIMessage *msg )
send_message ( session, _msg_ringing, msg->friend_id );
free_message ( _msg_ringing );
if ( callbacks[MSI_OnInvite] ) event.rise ( callbacks[MSI_OnInvite], session->agent_handler );
if ( callbacks[MSI_OnInvite].function ) event.rise ( callbacks[MSI_OnInvite].function, callbacks[MSI_OnInvite].data );
return 1;
}
@ -893,7 +897,7 @@ int handle_recv_start ( MSISession *session, MSIMessage *msg )
flush_peer_type ( session, msg, 0 );
if ( callbacks[MSI_OnStart] ) event.rise ( callbacks[MSI_OnStart], session->agent_handler );
if ( callbacks[MSI_OnStart].function ) event.rise ( callbacks[MSI_OnStart].function, callbacks[MSI_OnStart].data );
return 1;
}
@ -910,7 +914,7 @@ int handle_recv_reject ( MSISession *session, MSIMessage *msg )
free_message ( _msg_end );
event.timer_release ( session->call->request_timer_id );
if ( callbacks[MSI_OnReject] ) event.rise ( callbacks[MSI_OnReject], session->agent_handler );
if ( callbacks[MSI_OnReject].function ) event.rise ( callbacks[MSI_OnReject].function, callbacks[MSI_OnReject].data );
session->call->request_timer_id = event.timer_alloc ( handle_timeout, session, m_deftout );
return 1;
@ -925,7 +929,7 @@ int handle_recv_cancel ( MSISession *session, MSIMessage *msg )
terminate_call ( session );
if ( callbacks[MSI_OnCancel] ) event.rise ( callbacks[MSI_OnCancel], session->agent_handler );
if ( callbacks[MSI_OnCancel].function ) event.rise ( callbacks[MSI_OnCancel].function, callbacks[MSI_OnCancel].data );
return 1;
}
@ -943,7 +947,7 @@ int handle_recv_end ( MSISession *session, MSIMessage *msg )
terminate_call ( session );
if ( callbacks[MSI_OnEnd] ) event.rise ( callbacks[MSI_OnEnd], session->agent_handler );
if ( callbacks[MSI_OnEnd].function ) event.rise ( callbacks[MSI_OnEnd].function, callbacks[MSI_OnEnd].data );
return 1;
}
@ -957,7 +961,7 @@ int handle_recv_ringing ( MSISession *session, MSIMessage *msg )
return 0;
session->call->ringing_timer_id = event.timer_alloc ( handle_timeout, session, session->call->ringing_tout_ms );
if ( callbacks[MSI_OnRinging] ) event.rise ( callbacks[MSI_OnRinging], session->agent_handler );
if ( callbacks[MSI_OnRinging].function ) event.rise ( callbacks[MSI_OnRinging].function, callbacks[MSI_OnRinging].data );
return 1;
}
@ -996,7 +1000,7 @@ int handle_recv_starting ( MSISession *session, MSIMessage *msg )
flush_peer_type ( session, msg, 0 );
if ( callbacks[MSI_OnStarting] ) event.rise ( callbacks[MSI_OnStarting], session->agent_handler );
if ( callbacks[MSI_OnStarting].function ) event.rise ( callbacks[MSI_OnStarting].function, callbacks[MSI_OnStarting].data );
event.timer_release ( session->call->ringing_timer_id );
return 1;
@ -1008,15 +1012,11 @@ int handle_recv_ending ( MSISession *session, MSIMessage *msg )
if ( has_call_error ( session, msg ) == 0 )
return 0;
/* Do the callback before ending
if ( callbacks[MSI_OnEnding] ) event.rise ( callbacks[MSI_OnEnding], session->agent_handler );
*/
/* Stop timer */
event.timer_release ( session->call->request_timer_id );
/* Call callback */
if ( callbacks[MSI_OnEnding] ) callbacks[MSI_OnEnding](session->agent_handler);
if ( callbacks[MSI_OnEnding].function ) callbacks[MSI_OnEnding].function (callbacks[MSI_OnEnding].data);
/* Terminate call */
terminate_call ( session );
@ -1036,7 +1036,7 @@ int handle_recv_error ( MSISession *session, MSIMessage *msg )
terminate_call ( session );
if ( callbacks[MSI_OnEnding] ) event.rise ( callbacks[MSI_OnEnding], session->agent_handler );
if ( callbacks[MSI_OnEnding].function ) event.rise ( callbacks[MSI_OnEnding].function, callbacks[MSI_OnEnding].data );
return 1;
}
@ -1185,9 +1185,10 @@ void msi_handle_packet ( Messenger *messenger, int source, uint8_t *data, uint16
* @param id The id.
* @return void
*/
void msi_register_callback ( MSICallback callback, MSICallbackID id )
void msi_register_callback ( MSICallback callback, MSICallbackID id, void* userdata )
{
callbacks[id] = callback;
callbacks[id].function = callback;
callbacks[id].data = userdata;
}

View File

@ -143,7 +143,7 @@ typedef enum {
* @param id The id.
* @return void
*/
void msi_register_callback(MSICallback callback, MSICallbackID id);
void msi_register_callback(MSICallback callback, MSICallbackID id, void* userdata);
/**

View File

@ -126,7 +126,7 @@ typedef struct av_session_s {
AVCodec *webcam_decoder;
#endif
} av_session_t;
av_session_t *_phone;
void av_allocate_friend(av_session_t *_phone, int _id, int _active)
{
@ -858,7 +858,7 @@ int phone_startmedia_loop ( ToxAv *arg )
/* Only checks for last peer */
if ( toxav_get_peer_transmission_type(arg, 0) == TypeVideo &&
0 > event.rise(encode_video_thread, toxav_get_agent_handler(arg)) ) {
0 > event.rise(encode_video_thread, _phone) ) {
INFO("Error while starting encode_video_thread()");
return -1;
}
@ -873,7 +873,7 @@ int phone_startmedia_loop ( ToxAv *arg )
/* Only checks for last peer */
if ( toxav_get_peer_transmission_type(arg, 0) == TypeVideo &&
0 > event.rise(decode_video_thread, toxav_get_agent_handler(arg)) ) {
0 > event.rise(decode_video_thread, _phone) ) {
INFO("Error while starting decode_video_thread()");
return -1;
}
@ -886,7 +886,7 @@ int phone_startmedia_loop ( ToxAv *arg )
/* One threaded audio */
if ( 0 > event.rise(one_threaded_audio, toxav_get_agent_handler(arg)) ) {
if ( 0 > event.rise(one_threaded_audio, _phone) ) {
INFO ("Shit-head");
return -1;
}
@ -945,8 +945,6 @@ void *callback_recv_starting ( void *_arg )
}
void *callback_recv_ending ( void *_arg )
{
av_session_t *_phone = toxav_get_agent_handler(_arg);
_phone->running_encaud = 0;
_phone->running_decaud = 0;
_phone->running_encvid = 0;
@ -995,8 +993,6 @@ void *callback_call_rejected ( void *_arg )
}
void *callback_call_ended ( void *_arg )
{
av_session_t *_phone = toxav_get_agent_handler(_arg);
_phone->running_encaud = 0;
_phone->running_decaud = 0;
_phone->running_encvid = 0;
@ -1137,22 +1133,22 @@ failed_init_ffmpeg: ;
fraddr_to_str( _byte_address, _retu->_my_public_id );
_retu->av = toxav_new(_retu->_messenger, _retu, width, height);
_retu->av = toxav_new(_retu->_messenger, width, height);
/* ------------------ */
toxav_register_callstate_callback(callback_call_started, av_OnStart);
toxav_register_callstate_callback(callback_call_canceled, av_OnCancel);
toxav_register_callstate_callback(callback_call_rejected, av_OnReject);
toxav_register_callstate_callback(callback_call_ended, av_OnEnd);
toxav_register_callstate_callback(callback_recv_invite, av_OnInvite);
toxav_register_callstate_callback(callback_call_started, av_OnStart, _retu->av);
toxav_register_callstate_callback(callback_call_canceled, av_OnCancel, _retu->av);
toxav_register_callstate_callback(callback_call_rejected, av_OnReject, _retu->av);
toxav_register_callstate_callback(callback_call_ended, av_OnEnd, _retu->av);
toxav_register_callstate_callback(callback_recv_invite, av_OnInvite, _retu->av);
toxav_register_callstate_callback(callback_recv_ringing, av_OnRinging);
toxav_register_callstate_callback(callback_recv_starting, av_OnStarting);
toxav_register_callstate_callback(callback_recv_ending, av_OnEnding);
toxav_register_callstate_callback(callback_recv_ringing, av_OnRinging, _retu->av);
toxav_register_callstate_callback(callback_recv_starting, av_OnStarting, _retu->av);
toxav_register_callstate_callback(callback_recv_ending, av_OnEnding, _retu->av);
toxav_register_callstate_callback(callback_recv_error, av_OnError);
toxav_register_callstate_callback(callback_requ_timeout, av_OnRequestTimeout);
toxav_register_callstate_callback(callback_recv_error, av_OnError, _retu->av);
toxav_register_callstate_callback(callback_requ_timeout, av_OnRequestTimeout, _retu->av);
/* ------------------ */
@ -1426,7 +1422,7 @@ int main ( int argc, char *argv [] )
return 1;
}
av_session_t *_phone = av_init_session();
_phone = av_init_session();
assert ( _phone );

View File

@ -751,7 +751,7 @@ int rtp_send_msg ( RTPSession *session, Messenger *messenger, const uint8_t *dat
/*if ( full_length != sendpacket ( messenger->net, *((IP_Port*) &session->dest), _send_data, full_length) ) {*/
if ( full_length != send_custom_user_packet(messenger, session->dest, _send_data, full_length) ) {
printf("Rtp error: %s\n", strerror(errno));
fprintf(stderr, "Rtp error: %s\n", strerror(errno));
return -1;
}

View File

@ -67,7 +67,6 @@ typedef struct _ToxAv {
struct jitter_buffer *j_buf;
CodecState *cs;
void *agent_handler;
} ToxAv;
/**
@ -81,7 +80,7 @@ typedef struct _ToxAv {
* @return ToxAv*
* @retval NULL On error.
*/
ToxAv *toxav_new( Tox *messenger, void *userdata, uint16_t video_width, uint16_t video_height)
ToxAv *toxav_new( Tox* messenger, uint16_t video_width, uint16_t video_height)
{
ToxAv *av = calloc ( sizeof(ToxAv), 1);
@ -101,8 +100,6 @@ ToxAv *toxav_new( Tox *messenger, void *userdata, uint16_t video_width, uint16_t
av->cs = codec_init_session(AUDIO_BITRATE, AUDIO_FRAME_DURATION, AUDIO_SAMPLE_RATE, AUDIO_CHANNELS, video_width,
video_height, VIDEO_BITRATE);
av->agent_handler = userdata;
return av;
}
@ -136,9 +133,9 @@ void toxav_kill ( ToxAv *av )
* @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, void* userdata )
{
msi_register_callback((MSICallback)callback, (MSICallbackID) id);
msi_register_callback((MSICallback)callback, (MSICallbackID) id, userdata);
}
/**
@ -569,68 +566,16 @@ int toxav_get_peer_id ( 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 )
{
return av->agent_handler;
}
/**
* @brief Is video encoding supported
* @brief Is certain capability supported
*
* @param av Handler
* @return int
* @retval 1 Yes.
* @retval 0 No.
*/
inline__ int toxav_video_encoding ( ToxAv* av )
inline__ int toxav_capability_supported ( ToxAv* av, ToxAvCapabilities capability )
{
return av->cs->supported_actions & v_encoding;
}
/**
* @brief Is video decoding supported
*
* @param av Handler
* @return int
* @retval 1 Yes.
* @retval 0 No.
*/
inline__ int toxav_video_decoding ( ToxAv* av )
{
return av->cs->supported_actions & v_decoding;
}
/**
* @brief Is audio encoding supported
*
* @param av Handler
* @return int
* @retval 1 Yes.
* @retval 0 No.
*/
inline__ int toxav_audio_encoding ( ToxAv* av )
{
return av->cs->supported_actions & a_encoding;
}
/**
* @brief Is audio decoding supported
*
* @param av Handler
* @return int
* @retval 1 Yes.
* @retval 0 No.
*/
inline__ int toxav_audio_decoding ( ToxAv* av )
{
return av->cs->supported_actions & a_decoding;
return av->cs->capabilities & (Capabilities) capability;
}
/**

View File

@ -86,7 +86,6 @@ typedef enum {
/**
* @brief Error indicators.
*
*/
typedef enum {
ErrorNone = 0,
@ -104,6 +103,17 @@ typedef enum {
} ToxAvError;
/**
* @brief Locally supported capabilities.
*/
typedef enum {
None,
AudioEncoding = 1 << 0,
AudioDecoding = 1 << 1,
VideoEncoding = 1 << 2,
VideoDecoding = 1 << 3
} ToxAvCapabilities;
/**
* @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.
@ -115,7 +125,7 @@ typedef enum {
* @return ToxAv*
* @retval NULL On error.
*/
ToxAv *toxav_new(Tox *messenger, void *userdata, uint16_t video_width, uint16_t video_height);
ToxAv *toxav_new(Tox *messenger, uint16_t video_width, uint16_t video_height);
/**
* @brief Remove A/V session.
@ -132,7 +142,7 @@ void toxav_kill(ToxAv *av);
* @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, void *userdata);
/**
* @brief Call user. Use its friend_id.
@ -292,52 +302,14 @@ int toxav_get_peer_transmission_type ( ToxAv *av, int peer );
int toxav_get_peer_id ( 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 );
/**
* @brief Is video encoding supported
* @brief Is certain capability supported
*
* @param av Handler
* @return int
* @retval 1 Yes.
* @retval 0 No.
*/
int toxav_video_encoding ( ToxAv* av );
/**
* @brief Is video decoding supported
*
* @param av Handler
* @return int
* @retval 1 Yes.
* @retval 0 No.
*/
int toxav_video_decoding ( ToxAv* av );
/**
* @brief Is audio encoding supported
*
* @param av Handler
* @return int
* @retval 1 Yes.
* @retval 0 No.
*/
int toxav_audio_encoding ( ToxAv* av );
/**
* @brief Is audio decoding supported
*
* @param av Handler
* @return int
* @retval 1 Yes.
* @retval 0 No.
*/
int toxav_audio_decoding ( ToxAv* av );
int toxav_capability_supported ( ToxAv* av, ToxAvCapabilities capability );
/**
* @brief Get messenger handle