diff options
author | irungentoo <irungentoo@tox.im> | 2014-03-10 19:49:29 -0400 |
---|---|---|
committer | irungentoo <irungentoo@tox.im> | 2014-03-10 19:49:29 -0400 |
commit | 6858d6387d76dd7e61cba147b8c492a33d91c9d5 (patch) | |
tree | 53d702f0a7d4517d41cf78a19f8f9cf8dea91317 | |
parent | 7b87975dec3eaa555ec10747db37cd3f992fa279 (diff) | |
parent | d1fbbae5e91bec322cd358b6e4d3d1f3f3c67669 (diff) |
Merge pull request #795 from mannol1/master
Added custom callback data and capability identifier
-rw-r--r-- | toxav/media.c | 12 | ||||
-rw-r--r-- | toxav/media.h | 8 | ||||
-rwxr-xr-x | toxav/msi.c | 39 | ||||
-rwxr-xr-x | toxav/msi.h | 2 | ||||
-rwxr-xr-x | toxav/phone.c | 36 | ||||
-rwxr-xr-x | toxav/rtp.c | 2 | ||||
-rwxr-xr-x | toxav/toxav.c | 67 | ||||
-rwxr-xr-x | toxav/toxav.h | 58 |
8 files changed, 69 insertions, 155 deletions
diff --git a/toxav/media.c b/toxav/media.c index 59ca49b7..f6c33309 100644 --- a/toxav/media.c +++ b/toxav/media.c | |||
@@ -273,12 +273,12 @@ CodecState *codec_init_session ( uint32_t audio_bitrate, | |||
273 | video_height = 240; */ | 273 | video_height = 240; */ |
274 | } | 274 | } |
275 | else { | 275 | else { |
276 | retu->supported_actions |= ( 0 == init_video_encoder(retu, video_width, video_height, video_bitrate) ) ? v_encoding : 0; | 276 | retu->capabilities |= ( 0 == init_video_encoder(retu, video_width, video_height, video_bitrate) ) ? v_encoding : 0; |
277 | retu->supported_actions |= ( 0 == init_video_decoder(retu) ) ? v_decoding : 0; | 277 | retu->capabilities |= ( 0 == init_video_decoder(retu) ) ? v_decoding : 0; |
278 | } | 278 | } |
279 | 279 | ||
280 | retu->supported_actions |= ( 0 == init_audio_encoder(retu, audio_channels) ) ? a_encoding : 0; | 280 | retu->capabilities |= ( 0 == init_audio_encoder(retu, audio_channels) ) ? a_encoding : 0; |
281 | retu->supported_actions |= ( 0 == init_audio_decoder(retu, audio_channels) ) ? a_decoding : 0; | 281 | retu->capabilities |= ( 0 == init_audio_decoder(retu, audio_channels) ) ? a_decoding : 0; |
282 | 282 | ||
283 | return retu; | 283 | return retu; |
284 | } | 284 | } |
@@ -295,9 +295,9 @@ void codec_terminate_session ( CodecState *cs ) | |||
295 | /* TODO: Terminate video | 295 | /* TODO: Terminate video |
296 | * Do what??? | 296 | * Do what??? |
297 | */ | 297 | */ |
298 | if ( cs->supported_actions & v_decoding ) | 298 | if ( cs->capabilities & v_decoding ) |
299 | vpx_codec_destroy(&cs->v_decoder); | 299 | vpx_codec_destroy(&cs->v_decoder); |
300 | 300 | ||
301 | if ( cs->supported_actions & v_encoding ) | 301 | if ( cs->capabilities & v_encoding ) |
302 | vpx_codec_destroy(&cs->v_encoder); | 302 | vpx_codec_destroy(&cs->v_encoder); |
303 | } | 303 | } |
diff --git a/toxav/media.h b/toxav/media.h index 323d22fd..e4cb915f 100644 --- a/toxav/media.h +++ b/toxav/media.h | |||
@@ -38,14 +38,14 @@ | |||
38 | /* Audio encoding/decoding */ | 38 | /* Audio encoding/decoding */ |
39 | #include <opus/opus.h> | 39 | #include <opus/opus.h> |
40 | 40 | ||
41 | enum _actions | 41 | typedef enum _Capabilities |
42 | { | 42 | { |
43 | no_actions, | 43 | none, |
44 | a_encoding = 1 << 0, | 44 | a_encoding = 1 << 0, |
45 | a_decoding = 1 << 1, | 45 | a_decoding = 1 << 1, |
46 | v_encoding = 1 << 2, | 46 | v_encoding = 1 << 2, |
47 | v_decoding = 1 << 3 | 47 | v_decoding = 1 << 3 |
48 | }; | 48 | } Capabilities; |
49 | 49 | ||
50 | typedef struct _CodecState { | 50 | typedef struct _CodecState { |
51 | 51 | ||
@@ -64,7 +64,7 @@ typedef struct _CodecState { | |||
64 | /* audio decoding */ | 64 | /* audio decoding */ |
65 | OpusDecoder *audio_decoder; | 65 | OpusDecoder *audio_decoder; |
66 | 66 | ||
67 | uint64_t supported_actions; /* Encoding decoding etc */ | 67 | uint64_t capabilities; /* supports*/ |
68 | 68 | ||
69 | } CodecState; | 69 | } CodecState; |
70 | 70 | ||
diff --git a/toxav/msi.c b/toxav/msi.c index a38ab730..17c0b5c3 100755 --- a/toxav/msi.c +++ b/toxav/msi.c | |||
@@ -112,8 +112,12 @@ typedef struct _MSIMessage { | |||
112 | } MSIMessage; | 112 | } MSIMessage; |
113 | 113 | ||
114 | 114 | ||
115 | static struct _Callbacks { | ||
116 | MSICallback function; | ||
117 | void* data; | ||
118 | } callbacks[10] = {0}; | ||
115 | 119 | ||
116 | static MSICallback callbacks[10] = {0}; | 120 | /*static MSICallback callbacks[10] = {0};*/ |
117 | 121 | ||
118 | 122 | ||
119 | /* define strings for the identifiers */ | 123 | /* define strings for the identifiers */ |
@@ -675,7 +679,7 @@ int handle_error ( MSISession *session, MSICallError errid, uint32_t to ) | |||
675 | session->last_error_id = errid; | 679 | session->last_error_id = errid; |
676 | session->last_error_str = stringify_error ( errid ); | 680 | session->last_error_str = stringify_error ( errid ); |
677 | 681 | ||
678 | if ( callbacks[MSI_OnError] ) event.rise ( callbacks[MSI_OnError], session->agent_handler ); | 682 | if ( callbacks[MSI_OnError].function ) event.rise ( callbacks[MSI_OnError].function, callbacks[MSI_OnError].data ); |
679 | 683 | ||
680 | return 0; | 684 | return 0; |
681 | } | 685 | } |
@@ -732,8 +736,8 @@ void *handle_timeout ( void *arg ) | |||
732 | 736 | ||
733 | } | 737 | } |
734 | 738 | ||
735 | if ( callbacks[MSI_OnRequestTimeout] ) callbacks[MSI_OnRequestTimeout] ( _session->agent_handler ); | 739 | if ( callbacks[MSI_OnRequestTimeout].function ) callbacks[MSI_OnRequestTimeout].function ( callbacks[MSI_OnRequestTimeout].data ); |
736 | if ( callbacks[MSI_OnEnding] ) callbacks[MSI_OnEnding ] ( _session->agent_handler ); | 740 | if ( callbacks[MSI_OnEnding].function ) callbacks[MSI_OnEnding ].function ( callbacks[MSI_OnEnding].data ); |
737 | 741 | ||
738 | return NULL; | 742 | return NULL; |
739 | } | 743 | } |
@@ -869,7 +873,7 @@ int handle_recv_invite ( MSISession *session, MSIMessage *msg ) | |||
869 | send_message ( session, _msg_ringing, msg->friend_id ); | 873 | send_message ( session, _msg_ringing, msg->friend_id ); |
870 | free_message ( _msg_ringing ); | 874 | free_message ( _msg_ringing ); |
871 | 875 | ||
872 | if ( callbacks[MSI_OnInvite] ) event.rise ( callbacks[MSI_OnInvite], session->agent_handler ); | 876 | if ( callbacks[MSI_OnInvite].function ) event.rise ( callbacks[MSI_OnInvite].function, callbacks[MSI_OnInvite].data ); |
873 | 877 | ||
874 | return 1; | 878 | return 1; |
875 | } | 879 | } |
@@ -893,7 +897,7 @@ int handle_recv_start ( MSISession *session, MSIMessage *msg ) | |||
893 | 897 | ||
894 | flush_peer_type ( session, msg, 0 ); | 898 | flush_peer_type ( session, msg, 0 ); |
895 | 899 | ||
896 | if ( callbacks[MSI_OnStart] ) event.rise ( callbacks[MSI_OnStart], session->agent_handler ); | 900 | if ( callbacks[MSI_OnStart].function ) event.rise ( callbacks[MSI_OnStart].function, callbacks[MSI_OnStart].data ); |
897 | 901 | ||
898 | return 1; | 902 | return 1; |
899 | } | 903 | } |
@@ -910,7 +914,7 @@ int handle_recv_reject ( MSISession *session, MSIMessage *msg ) | |||
910 | free_message ( _msg_end ); | 914 | free_message ( _msg_end ); |
911 | 915 | ||
912 | event.timer_release ( session->call->request_timer_id ); | 916 | event.timer_release ( session->call->request_timer_id ); |
913 | if ( callbacks[MSI_OnReject] ) event.rise ( callbacks[MSI_OnReject], session->agent_handler ); | 917 | if ( callbacks[MSI_OnReject].function ) event.rise ( callbacks[MSI_OnReject].function, callbacks[MSI_OnReject].data ); |
914 | session->call->request_timer_id = event.timer_alloc ( handle_timeout, session, m_deftout ); | 918 | session->call->request_timer_id = event.timer_alloc ( handle_timeout, session, m_deftout ); |
915 | 919 | ||
916 | return 1; | 920 | return 1; |
@@ -925,7 +929,7 @@ int handle_recv_cancel ( MSISession *session, MSIMessage *msg ) | |||
925 | 929 | ||
926 | terminate_call ( session ); | 930 | terminate_call ( session ); |
927 | 931 | ||
928 | if ( callbacks[MSI_OnCancel] ) event.rise ( callbacks[MSI_OnCancel], session->agent_handler ); | 932 | if ( callbacks[MSI_OnCancel].function ) event.rise ( callbacks[MSI_OnCancel].function, callbacks[MSI_OnCancel].data ); |
929 | 933 | ||
930 | return 1; | 934 | return 1; |
931 | } | 935 | } |
@@ -943,7 +947,7 @@ int handle_recv_end ( MSISession *session, MSIMessage *msg ) | |||
943 | 947 | ||
944 | terminate_call ( session ); | 948 | terminate_call ( session ); |
945 | 949 | ||
946 | if ( callbacks[MSI_OnEnd] ) event.rise ( callbacks[MSI_OnEnd], session->agent_handler ); | 950 | if ( callbacks[MSI_OnEnd].function ) event.rise ( callbacks[MSI_OnEnd].function, callbacks[MSI_OnEnd].data ); |
947 | 951 | ||
948 | return 1; | 952 | return 1; |
949 | } | 953 | } |
@@ -957,7 +961,7 @@ int handle_recv_ringing ( MSISession *session, MSIMessage *msg ) | |||
957 | return 0; | 961 | return 0; |
958 | 962 | ||
959 | session->call->ringing_timer_id = event.timer_alloc ( handle_timeout, session, session->call->ringing_tout_ms ); | 963 | session->call->ringing_timer_id = event.timer_alloc ( handle_timeout, session, session->call->ringing_tout_ms ); |
960 | if ( callbacks[MSI_OnRinging] ) event.rise ( callbacks[MSI_OnRinging], session->agent_handler ); | 964 | if ( callbacks[MSI_OnRinging].function ) event.rise ( callbacks[MSI_OnRinging].function, callbacks[MSI_OnRinging].data ); |
961 | 965 | ||
962 | return 1; | 966 | return 1; |
963 | } | 967 | } |
@@ -996,7 +1000,7 @@ int handle_recv_starting ( MSISession *session, MSIMessage *msg ) | |||
996 | 1000 | ||
997 | flush_peer_type ( session, msg, 0 ); | 1001 | flush_peer_type ( session, msg, 0 ); |
998 | 1002 | ||
999 | if ( callbacks[MSI_OnStarting] ) event.rise ( callbacks[MSI_OnStarting], session->agent_handler ); | 1003 | if ( callbacks[MSI_OnStarting].function ) event.rise ( callbacks[MSI_OnStarting].function, callbacks[MSI_OnStarting].data ); |
1000 | event.timer_release ( session->call->ringing_timer_id ); | 1004 | event.timer_release ( session->call->ringing_timer_id ); |
1001 | 1005 | ||
1002 | return 1; | 1006 | return 1; |
@@ -1008,15 +1012,11 @@ int handle_recv_ending ( MSISession *session, MSIMessage *msg ) | |||
1008 | if ( has_call_error ( session, msg ) == 0 ) | 1012 | if ( has_call_error ( session, msg ) == 0 ) |
1009 | return 0; | 1013 | return 0; |
1010 | 1014 | ||
1011 | /* Do the callback before ending | ||
1012 | if ( callbacks[MSI_OnEnding] ) event.rise ( callbacks[MSI_OnEnding], session->agent_handler ); | ||
1013 | */ | ||
1014 | |||
1015 | /* Stop timer */ | 1015 | /* Stop timer */ |
1016 | event.timer_release ( session->call->request_timer_id ); | 1016 | event.timer_release ( session->call->request_timer_id ); |
1017 | 1017 | ||
1018 | /* Call callback */ | 1018 | /* Call callback */ |
1019 | if ( callbacks[MSI_OnEnding] ) callbacks[MSI_OnEnding](session->agent_handler); | 1019 | if ( callbacks[MSI_OnEnding].function ) callbacks[MSI_OnEnding].function (callbacks[MSI_OnEnding].data); |
1020 | 1020 | ||
1021 | /* Terminate call */ | 1021 | /* Terminate call */ |
1022 | terminate_call ( session ); | 1022 | terminate_call ( session ); |
@@ -1036,7 +1036,7 @@ int handle_recv_error ( MSISession *session, MSIMessage *msg ) | |||
1036 | 1036 | ||
1037 | terminate_call ( session ); | 1037 | terminate_call ( session ); |
1038 | 1038 | ||
1039 | if ( callbacks[MSI_OnEnding] ) event.rise ( callbacks[MSI_OnEnding], session->agent_handler ); | 1039 | if ( callbacks[MSI_OnEnding].function ) event.rise ( callbacks[MSI_OnEnding].function, callbacks[MSI_OnEnding].data ); |
1040 | 1040 | ||
1041 | return 1; | 1041 | return 1; |
1042 | } | 1042 | } |
@@ -1185,9 +1185,10 @@ void msi_handle_packet ( Messenger *messenger, int source, uint8_t *data, uint16 | |||
1185 | * @param id The id. | 1185 | * @param id The id. |
1186 | * @return void | 1186 | * @return void |
1187 | */ | 1187 | */ |
1188 | void msi_register_callback ( MSICallback callback, MSICallbackID id ) | 1188 | void msi_register_callback ( MSICallback callback, MSICallbackID id, void* userdata ) |
1189 | { | 1189 | { |
1190 | callbacks[id] = callback; | 1190 | callbacks[id].function = callback; |
1191 | callbacks[id].data = userdata; | ||
1191 | } | 1192 | } |
1192 | 1193 | ||
1193 | 1194 | ||
diff --git a/toxav/msi.h b/toxav/msi.h index 83de0117..e7752ef9 100755 --- a/toxav/msi.h +++ b/toxav/msi.h | |||
@@ -143,7 +143,7 @@ typedef enum { | |||
143 | * @param id The id. | 143 | * @param id The id. |
144 | * @return void | 144 | * @return void |
145 | */ | 145 | */ |
146 | void msi_register_callback(MSICallback callback, MSICallbackID id); | 146 | void msi_register_callback(MSICallback callback, MSICallbackID id, void* userdata); |
147 | 147 | ||
148 | 148 | ||
149 | /** | 149 | /** |
diff --git a/toxav/phone.c b/toxav/phone.c index 95b49231..2d7b4c90 100755 --- a/toxav/phone.c +++ b/toxav/phone.c | |||
@@ -126,7 +126,7 @@ typedef struct av_session_s { | |||
126 | AVCodec *webcam_decoder; | 126 | AVCodec *webcam_decoder; |
127 | #endif | 127 | #endif |
128 | } av_session_t; | 128 | } av_session_t; |
129 | 129 | av_session_t *_phone; | |
130 | 130 | ||
131 | void av_allocate_friend(av_session_t *_phone, int _id, int _active) | 131 | void av_allocate_friend(av_session_t *_phone, int _id, int _active) |
132 | { | 132 | { |
@@ -858,7 +858,7 @@ int phone_startmedia_loop ( ToxAv *arg ) | |||
858 | 858 | ||
859 | /* Only checks for last peer */ | 859 | /* Only checks for last peer */ |
860 | if ( toxav_get_peer_transmission_type(arg, 0) == TypeVideo && | 860 | if ( toxav_get_peer_transmission_type(arg, 0) == TypeVideo && |
861 | 0 > event.rise(encode_video_thread, toxav_get_agent_handler(arg)) ) { | 861 | 0 > event.rise(encode_video_thread, _phone) ) { |
862 | INFO("Error while starting encode_video_thread()"); | 862 | INFO("Error while starting encode_video_thread()"); |
863 | return -1; | 863 | return -1; |
864 | } | 864 | } |
@@ -873,7 +873,7 @@ int phone_startmedia_loop ( ToxAv *arg ) | |||
873 | 873 | ||
874 | /* Only checks for last peer */ | 874 | /* Only checks for last peer */ |
875 | if ( toxav_get_peer_transmission_type(arg, 0) == TypeVideo && | 875 | if ( toxav_get_peer_transmission_type(arg, 0) == TypeVideo && |
876 | 0 > event.rise(decode_video_thread, toxav_get_agent_handler(arg)) ) { | 876 | 0 > event.rise(decode_video_thread, _phone) ) { |
877 | INFO("Error while starting decode_video_thread()"); | 877 | INFO("Error while starting decode_video_thread()"); |
878 | return -1; | 878 | return -1; |
879 | } | 879 | } |
@@ -886,7 +886,7 @@ int phone_startmedia_loop ( ToxAv *arg ) | |||
886 | 886 | ||
887 | /* One threaded audio */ | 887 | /* One threaded audio */ |
888 | 888 | ||
889 | if ( 0 > event.rise(one_threaded_audio, toxav_get_agent_handler(arg)) ) { | 889 | if ( 0 > event.rise(one_threaded_audio, _phone) ) { |
890 | INFO ("Shit-head"); | 890 | INFO ("Shit-head"); |
891 | return -1; | 891 | return -1; |
892 | } | 892 | } |
@@ -945,8 +945,6 @@ void *callback_recv_starting ( void *_arg ) | |||
945 | } | 945 | } |
946 | void *callback_recv_ending ( void *_arg ) | 946 | void *callback_recv_ending ( void *_arg ) |
947 | { | 947 | { |
948 | av_session_t *_phone = toxav_get_agent_handler(_arg); | ||
949 | |||
950 | _phone->running_encaud = 0; | 948 | _phone->running_encaud = 0; |
951 | _phone->running_decaud = 0; | 949 | _phone->running_decaud = 0; |
952 | _phone->running_encvid = 0; | 950 | _phone->running_encvid = 0; |
@@ -995,8 +993,6 @@ void *callback_call_rejected ( void *_arg ) | |||
995 | } | 993 | } |
996 | void *callback_call_ended ( void *_arg ) | 994 | void *callback_call_ended ( void *_arg ) |
997 | { | 995 | { |
998 | av_session_t *_phone = toxav_get_agent_handler(_arg); | ||
999 | |||
1000 | _phone->running_encaud = 0; | 996 | _phone->running_encaud = 0; |
1001 | _phone->running_decaud = 0; | 997 | _phone->running_decaud = 0; |
1002 | _phone->running_encvid = 0; | 998 | _phone->running_encvid = 0; |
@@ -1137,22 +1133,22 @@ failed_init_ffmpeg: ; | |||
1137 | fraddr_to_str( _byte_address, _retu->_my_public_id ); | 1133 | fraddr_to_str( _byte_address, _retu->_my_public_id ); |
1138 | 1134 | ||
1139 | 1135 | ||
1140 | _retu->av = toxav_new(_retu->_messenger, _retu, width, height); | 1136 | _retu->av = toxav_new(_retu->_messenger, width, height); |
1141 | 1137 | ||
1142 | /* ------------------ */ | 1138 | /* ------------------ */ |
1143 | 1139 | ||
1144 | toxav_register_callstate_callback(callback_call_started, av_OnStart); | 1140 | toxav_register_callstate_callback(callback_call_started, av_OnStart, _retu->av); |
1145 | toxav_register_callstate_callback(callback_call_canceled, av_OnCancel); | 1141 | toxav_register_callstate_callback(callback_call_canceled, av_OnCancel, _retu->av); |
1146 | toxav_register_callstate_callback(callback_call_rejected, av_OnReject); | 1142 | toxav_register_callstate_callback(callback_call_rejected, av_OnReject, _retu->av); |
1147 | toxav_register_callstate_callback(callback_call_ended, av_OnEnd); | 1143 | toxav_register_callstate_callback(callback_call_ended, av_OnEnd, _retu->av); |
1148 | toxav_register_callstate_callback(callback_recv_invite, av_OnInvite); | 1144 | toxav_register_callstate_callback(callback_recv_invite, av_OnInvite, _retu->av); |
1149 | 1145 | ||
1150 | toxav_register_callstate_callback(callback_recv_ringing, av_OnRinging); | 1146 | toxav_register_callstate_callback(callback_recv_ringing, av_OnRinging, _retu->av); |
1151 | toxav_register_callstate_callback(callback_recv_starting, av_OnStarting); | 1147 | toxav_register_callstate_callback(callback_recv_starting, av_OnStarting, _retu->av); |
1152 | toxav_register_callstate_callback(callback_recv_ending, av_OnEnding); | 1148 | toxav_register_callstate_callback(callback_recv_ending, av_OnEnding, _retu->av); |
1153 | 1149 | ||
1154 | toxav_register_callstate_callback(callback_recv_error, av_OnError); | 1150 | toxav_register_callstate_callback(callback_recv_error, av_OnError, _retu->av); |
1155 | toxav_register_callstate_callback(callback_requ_timeout, av_OnRequestTimeout); | 1151 | toxav_register_callstate_callback(callback_requ_timeout, av_OnRequestTimeout, _retu->av); |
1156 | 1152 | ||
1157 | /* ------------------ */ | 1153 | /* ------------------ */ |
1158 | 1154 | ||
@@ -1426,7 +1422,7 @@ int main ( int argc, char *argv [] ) | |||
1426 | return 1; | 1422 | return 1; |
1427 | } | 1423 | } |
1428 | 1424 | ||
1429 | av_session_t *_phone = av_init_session(); | 1425 | _phone = av_init_session(); |
1430 | 1426 | ||
1431 | assert ( _phone ); | 1427 | assert ( _phone ); |
1432 | 1428 | ||
diff --git a/toxav/rtp.c b/toxav/rtp.c index 9b8cd652..ef5d0928 100755 --- a/toxav/rtp.c +++ b/toxav/rtp.c | |||
@@ -751,7 +751,7 @@ int rtp_send_msg ( RTPSession *session, Messenger *messenger, const uint8_t *dat | |||
751 | 751 | ||
752 | /*if ( full_length != sendpacket ( messenger->net, *((IP_Port*) &session->dest), _send_data, full_length) ) {*/ | 752 | /*if ( full_length != sendpacket ( messenger->net, *((IP_Port*) &session->dest), _send_data, full_length) ) {*/ |
753 | if ( full_length != send_custom_user_packet(messenger, session->dest, _send_data, full_length) ) { | 753 | if ( full_length != send_custom_user_packet(messenger, session->dest, _send_data, full_length) ) { |
754 | printf("Rtp error: %s\n", strerror(errno)); | 754 | fprintf(stderr, "Rtp error: %s\n", strerror(errno)); |
755 | return -1; | 755 | return -1; |
756 | } | 756 | } |
757 | 757 | ||
diff --git a/toxav/toxav.c b/toxav/toxav.c index 698fac3b..3cae8dc4 100755 --- a/toxav/toxav.c +++ b/toxav/toxav.c | |||
@@ -67,7 +67,6 @@ typedef struct _ToxAv { | |||
67 | struct jitter_buffer *j_buf; | 67 | struct jitter_buffer *j_buf; |
68 | CodecState *cs; | 68 | CodecState *cs; |
69 | 69 | ||
70 | void *agent_handler; | ||
71 | } ToxAv; | 70 | } ToxAv; |
72 | 71 | ||
73 | /** | 72 | /** |
@@ -81,7 +80,7 @@ typedef struct _ToxAv { | |||
81 | * @return ToxAv* | 80 | * @return ToxAv* |
82 | * @retval NULL On error. | 81 | * @retval NULL On error. |
83 | */ | 82 | */ |
84 | ToxAv *toxav_new( Tox *messenger, void *userdata, uint16_t video_width, uint16_t video_height) | 83 | ToxAv *toxav_new( Tox* messenger, uint16_t video_width, uint16_t video_height) |
85 | { | 84 | { |
86 | ToxAv *av = calloc ( sizeof(ToxAv), 1); | 85 | ToxAv *av = calloc ( sizeof(ToxAv), 1); |
87 | 86 | ||
@@ -101,8 +100,6 @@ ToxAv *toxav_new( Tox *messenger, void *userdata, uint16_t video_width, uint16_t | |||
101 | av->cs = codec_init_session(AUDIO_BITRATE, AUDIO_FRAME_DURATION, AUDIO_SAMPLE_RATE, AUDIO_CHANNELS, video_width, | 100 | av->cs = codec_init_session(AUDIO_BITRATE, AUDIO_FRAME_DURATION, AUDIO_SAMPLE_RATE, AUDIO_CHANNELS, video_width, |
102 | video_height, VIDEO_BITRATE); | 101 | video_height, VIDEO_BITRATE); |
103 | 102 | ||
104 | av->agent_handler = userdata; | ||
105 | |||
106 | return av; | 103 | return av; |
107 | } | 104 | } |
108 | 105 | ||
@@ -136,9 +133,9 @@ void toxav_kill ( ToxAv *av ) | |||
136 | * @param id One of the ToxAvCallbackID values | 133 | * @param id One of the ToxAvCallbackID values |
137 | * @return void | 134 | * @return void |
138 | */ | 135 | */ |
139 | void toxav_register_callstate_callback ( ToxAVCallback callback, ToxAvCallbackID id ) | 136 | void toxav_register_callstate_callback ( ToxAVCallback callback, ToxAvCallbackID id, void* userdata ) |
140 | { | 137 | { |
141 | msi_register_callback((MSICallback)callback, (MSICallbackID) id); | 138 | msi_register_callback((MSICallback)callback, (MSICallbackID) id, userdata); |
142 | } | 139 | } |
143 | 140 | ||
144 | /** | 141 | /** |
@@ -569,68 +566,16 @@ int toxav_get_peer_id ( ToxAv* av, int peer ) | |||
569 | } | 566 | } |
570 | 567 | ||
571 | /** | 568 | /** |
572 | * @brief Get reference to an object that is handling av session. | 569 | * @brief Is certain capability supported |
573 | * | ||
574 | * @param av Handler. | ||
575 | * @return void* | ||
576 | */ | ||
577 | void *toxav_get_agent_handler ( ToxAv *av ) | ||
578 | { | ||
579 | return av->agent_handler; | ||
580 | } | ||
581 | |||
582 | /** | ||
583 | * @brief Is video encoding supported | ||
584 | * | ||
585 | * @param av Handler | ||
586 | * @return int | ||
587 | * @retval 1 Yes. | ||
588 | * @retval 0 No. | ||
589 | */ | ||
590 | inline__ int toxav_video_encoding ( ToxAv* av ) | ||
591 | { | ||
592 | return av->cs->supported_actions & v_encoding; | ||
593 | } | ||
594 | |||
595 | |||
596 | /** | ||
597 | * @brief Is video decoding supported | ||
598 | * | ||
599 | * @param av Handler | ||
600 | * @return int | ||
601 | * @retval 1 Yes. | ||
602 | * @retval 0 No. | ||
603 | */ | ||
604 | inline__ int toxav_video_decoding ( ToxAv* av ) | ||
605 | { | ||
606 | return av->cs->supported_actions & v_decoding; | ||
607 | } | ||
608 | |||
609 | /** | ||
610 | * @brief Is audio encoding supported | ||
611 | * | ||
612 | * @param av Handler | ||
613 | * @return int | ||
614 | * @retval 1 Yes. | ||
615 | * @retval 0 No. | ||
616 | */ | ||
617 | inline__ int toxav_audio_encoding ( ToxAv* av ) | ||
618 | { | ||
619 | return av->cs->supported_actions & a_encoding; | ||
620 | } | ||
621 | |||
622 | |||
623 | /** | ||
624 | * @brief Is audio decoding supported | ||
625 | * | 570 | * |
626 | * @param av Handler | 571 | * @param av Handler |
627 | * @return int | 572 | * @return int |
628 | * @retval 1 Yes. | 573 | * @retval 1 Yes. |
629 | * @retval 0 No. | 574 | * @retval 0 No. |
630 | */ | 575 | */ |
631 | inline__ int toxav_audio_decoding ( ToxAv* av ) | 576 | inline__ int toxav_capability_supported ( ToxAv* av, ToxAvCapabilities capability ) |
632 | { | 577 | { |
633 | return av->cs->supported_actions & a_decoding; | 578 | return av->cs->capabilities & (Capabilities) capability; |
634 | } | 579 | } |
635 | 580 | ||
636 | /** | 581 | /** |
diff --git a/toxav/toxav.h b/toxav/toxav.h index 3e66c230..7e76e4c9 100755 --- a/toxav/toxav.h +++ b/toxav/toxav.h | |||
@@ -86,7 +86,6 @@ typedef enum { | |||
86 | 86 | ||
87 | /** | 87 | /** |
88 | * @brief Error indicators. | 88 | * @brief Error indicators. |
89 | * | ||
90 | */ | 89 | */ |
91 | typedef enum { | 90 | typedef enum { |
92 | ErrorNone = 0, | 91 | ErrorNone = 0, |
@@ -105,6 +104,17 @@ typedef enum { | |||
105 | 104 | ||
106 | 105 | ||
107 | /** | 106 | /** |
107 | * @brief Locally supported capabilities. | ||
108 | */ | ||
109 | typedef enum { | ||
110 | None, | ||
111 | AudioEncoding = 1 << 0, | ||
112 | AudioDecoding = 1 << 1, | ||
113 | VideoEncoding = 1 << 2, | ||
114 | VideoDecoding = 1 << 3 | ||
115 | } ToxAvCapabilities; | ||
116 | |||
117 | /** | ||
108 | * @brief Start new A/V session. There can only be one session at the time. If you register more | 118 | * @brief Start new A/V session. There can only be one session at the time. If you register more |
109 | * it will result in undefined behaviour. | 119 | * it will result in undefined behaviour. |
110 | * | 120 | * |
@@ -115,7 +125,7 @@ typedef enum { | |||
115 | * @return ToxAv* | 125 | * @return ToxAv* |
116 | * @retval NULL On error. | 126 | * @retval NULL On error. |
117 | */ | 127 | */ |
118 | ToxAv *toxav_new(Tox *messenger, void *userdata, uint16_t video_width, uint16_t video_height); | 128 | ToxAv *toxav_new(Tox *messenger, uint16_t video_width, uint16_t video_height); |
119 | 129 | ||
120 | /** | 130 | /** |
121 | * @brief Remove A/V session. | 131 | * @brief Remove A/V session. |
@@ -132,7 +142,7 @@ void toxav_kill(ToxAv *av); | |||
132 | * @param id One of the ToxAvCallbackID values | 142 | * @param id One of the ToxAvCallbackID values |
133 | * @return void | 143 | * @return void |
134 | */ | 144 | */ |
135 | void toxav_register_callstate_callback (ToxAVCallback callback, ToxAvCallbackID id); | 145 | void toxav_register_callstate_callback (ToxAVCallback callback, ToxAvCallbackID id, void *userdata); |
136 | 146 | ||
137 | /** | 147 | /** |
138 | * @brief Call user. Use its friend_id. | 148 | * @brief Call user. Use its friend_id. |
@@ -292,52 +302,14 @@ int toxav_get_peer_transmission_type ( ToxAv *av, int peer ); | |||
292 | int toxav_get_peer_id ( ToxAv* av, int peer ); | 302 | int toxav_get_peer_id ( ToxAv* av, int peer ); |
293 | 303 | ||
294 | /** | 304 | /** |
295 | * @brief Get reference to an object that is handling av session. | 305 | * @brief Is certain capability supported |
296 | * | ||
297 | * @param av Handler. | ||
298 | * @return void* | ||
299 | */ | ||
300 | void *toxav_get_agent_handler ( ToxAv *av ); | ||
301 | |||
302 | /** | ||
303 | * @brief Is video encoding supported | ||
304 | * | ||
305 | * @param av Handler | ||
306 | * @return int | ||
307 | * @retval 1 Yes. | ||
308 | * @retval 0 No. | ||
309 | */ | ||
310 | int toxav_video_encoding ( ToxAv* av ); | ||
311 | |||
312 | /** | ||
313 | * @brief Is video decoding supported | ||
314 | * | ||
315 | * @param av Handler | ||
316 | * @return int | ||
317 | * @retval 1 Yes. | ||
318 | * @retval 0 No. | ||
319 | */ | ||
320 | int toxav_video_decoding ( ToxAv* av ); | ||
321 | |||
322 | /** | ||
323 | * @brief Is audio encoding supported | ||
324 | * | ||
325 | * @param av Handler | ||
326 | * @return int | ||
327 | * @retval 1 Yes. | ||
328 | * @retval 0 No. | ||
329 | */ | ||
330 | int toxav_audio_encoding ( ToxAv* av ); | ||
331 | |||
332 | /** | ||
333 | * @brief Is audio decoding supported | ||
334 | * | 306 | * |
335 | * @param av Handler | 307 | * @param av Handler |
336 | * @return int | 308 | * @return int |
337 | * @retval 1 Yes. | 309 | * @retval 1 Yes. |
338 | * @retval 0 No. | 310 | * @retval 0 No. |
339 | */ | 311 | */ |
340 | int toxav_audio_decoding ( ToxAv* av ); | 312 | int toxav_capability_supported ( ToxAv* av, ToxAvCapabilities capability ); |
341 | 313 | ||
342 | /** | 314 | /** |
343 | * @brief Get messenger handle | 315 | * @brief Get messenger handle |