From 6c1ac97da9dd9e64cf53cb9137944f0d595698fc Mon Sep 17 00:00:00 2001 From: mannol Date: Sat, 2 Aug 2014 01:09:33 +0200 Subject: Added userdata pointer to audio/video callbacks --- auto_tests/toxav_basic_test.c | 8 ++++---- auto_tests/toxav_many_test.c | 8 ++++---- toxav/toxav.c | 17 +++++++++++------ toxav/toxav.h | 4 ++-- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c index 7edb96bc..6db9f8fa 100644 --- a/auto_tests/toxav_basic_test.c +++ b/auto_tests/toxav_basic_test.c @@ -163,11 +163,11 @@ void callback_requ_timeout ( void *av, int32_t call_index, void *_arg ) cast->Alice.status = TimedOut; } -static void callback_audio(ToxAv *av, int32_t call_index, int16_t *data, int length) +static void callback_audio(ToxAv *av, int32_t call_index, int16_t *data, int length, void* userdata) { } -static void callback_video(ToxAv *av, int32_t call_index, vpx_image_t *img) +static void callback_video(ToxAv *av, int32_t call_index, vpx_image_t *img, void* userdata) { } @@ -187,8 +187,8 @@ void register_callbacks(ToxAv *av, void *data) toxav_register_callstate_callback(av, callback_call_type_change, av_OnMediaChange, data); - toxav_register_audio_recv_callback(av, callback_audio); - toxav_register_video_recv_callback(av, callback_video); + toxav_register_audio_recv_callback(av, callback_audio, NULL); + toxav_register_video_recv_callback(av, callback_video, NULL); } diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c index 299e701d..d98824be 100644 --- a/auto_tests/toxav_many_test.c +++ b/auto_tests/toxav_many_test.c @@ -120,11 +120,11 @@ void callback_requ_timeout ( void *av, int32_t call_index, void *_arg ) //ck_assert_msg(0, "No answer!"); } -static void callback_audio(ToxAv *av, int32_t call_index, int16_t *data, int length) +static void callback_audio(ToxAv *av, int32_t call_index, int16_t *data, int length, void* userdata) { } -static void callback_video(ToxAv *av, int32_t call_index, vpx_image_t *img) +static void callback_video(ToxAv *av, int32_t call_index, vpx_image_t *img, void* userdata) { } @@ -143,8 +143,8 @@ void register_callbacks(ToxAv *av, void *data) toxav_register_callstate_callback(av, callback_requ_timeout, av_OnRequestTimeout, data); - toxav_register_audio_recv_callback(av, callback_audio); - toxav_register_video_recv_callback(av, callback_video); + toxav_register_audio_recv_callback(av, callback_audio, NULL); + toxav_register_video_recv_callback(av, callback_video, NULL); } /*************************************************************************************************/ diff --git a/toxav/toxav.c b/toxav/toxav.c index 3a95e445..b215b3e9 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c @@ -104,8 +104,11 @@ struct _ToxAv { MSISession *msi_session; /** Main msi session */ CallSpecific *calls; /** Per-call params */ - void (*audio_callback)(ToxAv *, int32_t, int16_t *, int); - void (*video_callback)(ToxAv *, int32_t, vpx_image_t *); + void (*audio_callback)(ToxAv *, int32_t, int16_t *, int, void*); + void (*video_callback)(ToxAv *, int32_t, vpx_image_t *, void*); + + void *audio_callback_userdata; + void *video_callback_userdata; uint32_t max_calls; @@ -269,9 +272,10 @@ void toxav_register_callstate_callback ( ToxAv *av, ToxAVCallback callback, ToxA * @param callback The callback * @return void */ -void toxav_register_audio_recv_callback (ToxAv *av, void (*callback)(ToxAv *, int32_t, int16_t *, int)) +void toxav_register_audio_recv_callback (ToxAv *av, void (*callback)(ToxAv *, int32_t, int16_t *, int, void*), void* user_data) { av->audio_callback = callback; + av->audio_callback_userdata = user_data; } /** @@ -280,9 +284,10 @@ void toxav_register_audio_recv_callback (ToxAv *av, void (*callback)(ToxAv *, in * @param callback The callback * @return void */ -void toxav_register_video_recv_callback (ToxAv *av, void (*callback)(ToxAv *, int32_t, vpx_image_t *)) +void toxav_register_video_recv_callback (ToxAv *av, void (*callback)(ToxAv *, int32_t, vpx_image_t *, void*), void* user_data) { av->video_callback = callback; + av->video_callback_userdata = user_data; } /** @@ -933,7 +938,7 @@ static void decode_video(ToxAv *av, DECODE_PACKET *p) img = vpx_codec_get_frame(&call->cs->v_decoder, &iter); if (img && av->video_callback) { - av->video_callback(av, p->call_index, img); + av->video_callback(av, p->call_index, img, av->video_callback_userdata); } else { LOGGER_WARNING("Video packet dropped due to missing callback or no image!"); } @@ -961,7 +966,7 @@ static void decode_audio(ToxAv *av, DECODE_PACKET *p) } if ( av->audio_callback ) - av->audio_callback(av, call_index, dest, dec_size); + av->audio_callback(av, call_index, dest, dec_size, av->audio_callback_userdata); else LOGGER_WARNING("Audio packet dropped due to missing callback!"); } diff --git a/toxav/toxav.h b/toxav/toxav.h index 4dddc9b5..0dcd2836 100644 --- a/toxav/toxav.h +++ b/toxav/toxav.h @@ -173,7 +173,7 @@ void toxav_register_callstate_callback (ToxAv *av, ToxAVCallback callback, ToxAv * @param callback The callback * @return void */ -void toxav_register_audio_recv_callback (ToxAv *av, void (*callback)(ToxAv *, int32_t, int16_t *, int)); +void toxav_register_audio_recv_callback (ToxAv *av, void (*callback)(ToxAv *, int32_t, int16_t *, int, void*), void* user_data); /** * @brief Register callback for recieving video data @@ -182,7 +182,7 @@ void toxav_register_audio_recv_callback (ToxAv *av, void (*callback)(ToxAv *, in * @param callback The callback * @return void */ -void toxav_register_video_recv_callback (ToxAv *av, void (*callback)(ToxAv *, int32_t, vpx_image_t *)); +void toxav_register_video_recv_callback (ToxAv *av, void (*callback)(ToxAv *, int32_t, vpx_image_t *, void*), void* user_data); /** * @brief Call user. Use its friend_id. -- cgit v1.2.3