From 6c126e34e677da42849b9002ad376117bff5852e Mon Sep 17 00:00:00 2001 From: mannol Date: Tue, 30 Jun 2015 01:41:38 +0200 Subject: [PATCH] Implement handling capability change on rtp level --- auto_tests/toxav_basic_test.c | 77 +++++++++++++++++++++++++++++++++++ other/apidsl/toxav.in.h | 11 +++-- toxav/rtp.c | 2 + toxav/toxav.c | 22 ++++++++-- toxav/toxav.h | 5 ++- 5 files changed, 107 insertions(+), 10 deletions(-) diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c index 305257fb..f859856d 100644 --- a/auto_tests/toxav_basic_test.c +++ b/auto_tests/toxav_basic_test.c @@ -35,6 +35,7 @@ #define TEST_CANCEL 1 #define TEST_MUTE_UNMUTE 1 #define TEST_STOP_RESUME_PAYLOAD 1 +#define TEST_PAUSE_RESUME_SEND 1 typedef struct { @@ -82,6 +83,7 @@ void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, (void) ustride; (void) vstride; (void) user_data; + printf("Received video payload\n"); } void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, int16_t const *pcm, @@ -97,6 +99,7 @@ void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, (void) channels; (void) sampling_rate; (void) user_data; + printf("Received audio payload\n"); } void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) { @@ -475,6 +478,80 @@ START_TEST(test_AV_flows) iterate_tox(bootstrap, Alice, Bob); ck_assert(!(BobCC.state & TOXAV_FRIEND_CALL_STATE_SENDING_A)); + + { + TOXAV_ERR_CALL_CONTROL rc; + toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_CANCEL, &rc); + + if (rc != TOXAV_ERR_CALL_CONTROL_OK) { + printf("toxav_call_control failed: %d\n", rc); + ck_assert(0); + } + } + + iterate_tox(bootstrap, Alice, Bob); + ck_assert(BobCC.state == TOXAV_FRIEND_CALL_STATE_FINISHED); + + printf("Success!\n"); + } + + if (TEST_PAUSE_RESUME_SEND) { /* Stop and resume audio/video payload and test send options */ + printf("\nTrying stop/resume functionality...\n"); + + memset(&AliceCC, 0, sizeof(CallControl)); + memset(&BobCC, 0, sizeof(CallControl)); + + /* Assume sending audio and video */ + { + TOXAV_ERR_CALL rc; + toxav_call(AliceAV, 0, 48, 0, &rc); + + if (rc != TOXAV_ERR_CALL_OK) { + printf("toxav_call failed: %d\n", rc); + ck_assert(0); + } + } + + while (!BobCC.incoming) + iterate_tox(bootstrap, Alice, Bob); + + { + TOXAV_ERR_ANSWER rc; + toxav_answer(BobAV, 0, 48, 0, &rc); + + if (rc != TOXAV_ERR_ANSWER_OK) { + printf("toxav_answer failed: %d\n", rc); + ck_assert(0); + } + } + + int16_t PCM[5670]; + + iterate_tox(bootstrap, Alice, Bob); + ck_assert(toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_PAUSE, NULL)); + iterate_tox(bootstrap, Alice, Bob); + ck_assert(!toxav_audio_send_frame(AliceAV, 0, PCM, 960, 1, 48000, NULL)); + ck_assert(!toxav_audio_send_frame(BobAV, 0, PCM, 960, 1, 48000, NULL)); + ck_assert(toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_RESUME, NULL)); + iterate_tox(bootstrap, Alice, Bob); + ck_assert(toxav_audio_send_frame(AliceAV, 0, PCM, 960, 1, 48000, NULL)); + ck_assert(toxav_audio_send_frame(BobAV, 0, PCM, 960, 1, 48000, NULL)); + iterate_tox(bootstrap, Alice, Bob); + + { + TOXAV_ERR_CALL_CONTROL rc; + toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_CANCEL, &rc); + + if (rc != TOXAV_ERR_CALL_CONTROL_OK) { + printf("toxav_call_control failed: %d\n", rc); + ck_assert(0); + } + } + + iterate_tox(bootstrap, Alice, Bob); + ck_assert(BobCC.state == TOXAV_FRIEND_CALL_STATE_FINISHED); + + printf("Success!\n"); } toxav_kill(BobAV); diff --git a/other/apidsl/toxav.in.h b/other/apidsl/toxav.in.h index 4a96defc..8d1d8f6e 100644 --- a/other/apidsl/toxav.in.h +++ b/other/apidsl/toxav.in.h @@ -216,7 +216,8 @@ void iterate(); * * It is the client's responsibility to stop ringing after a certain timeout, * if such behaviour is desired. If the client does not stop ringing, the - * library will not stop until the friend is disconnected. + * library will not stop until the friend is disconnected. Audio and video + * receiving are both enabled by default. * * @param friend_number The friend number of the friend that should be called. * @param audio_bit_rate Audio bit rate in Kb/sec. Set this to 0 to disable @@ -262,7 +263,8 @@ event call { * Accept an incoming call. * * If answering fails for any reason, the call will still be pending and it is - * possible to try and answer it later. + * possible to try and answer it later. Audio and video receiving are both + * enabled by default. * * @param friend_number The friend number of the friend that is calling. * @param audio_bit_rate Audio bit rate in Kb/sec. Set this to 0 to disable @@ -519,9 +521,10 @@ error for send_frame { */ INVALID, /** - * Bit rate for this payload type was not set up. + * Either friend turned off audio or video receiving or we turned off sending + * for the said payload. */ - BIT_RATE_NOT_SET, + PAYLOAD_TYPE_DISABLED, /** * Failed to push frame through rtp interface. */ diff --git a/toxav/rtp.c b/toxav/rtp.c index 7b3a5ed0..148c4238 100644 --- a/toxav/rtp.c +++ b/toxav/rtp.c @@ -221,6 +221,7 @@ int rtp_start_receiving(RTPSession* session) return -1; } + LOGGER_DEBUG("Started receiving on session: %p", session); return 0; } int rtp_stop_receiving(RTPSession* session) @@ -231,6 +232,7 @@ int rtp_stop_receiving(RTPSession* session) m_callback_rtp_packet(session->m, session->friend_number, session->prefix, NULL, NULL); m_callback_rtp_packet(session->m, session->friend_number, session->rtcp_session->prefix, NULL, NULL); /* RTCP */ + LOGGER_DEBUG("Stopped receiving on session: %p", session); return 0; } int rtp_send_data ( RTPSession *session, const uint8_t *data, uint16_t length, bool dummy ) diff --git a/toxav/toxav.c b/toxav/toxav.c index 8a39259a..58e08376 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c @@ -770,9 +770,11 @@ bool toxav_audio_send_frame(ToxAV* av, uint32_t friend_number, const int16_t* pc goto END; } - if (call->audio_bit_rate == 0) { + if (call->audio_bit_rate == 0 || + !(call->msi_call->self_capabilities & msi_CapSAudio) || + !(call->msi_call->peer_capabilities & msi_CapRAudio)) { pthread_mutex_unlock(av->mutex); - rc = TOXAV_ERR_SEND_FRAME_BIT_RATE_NOT_SET; + rc = TOXAV_ERR_SEND_FRAME_PAYLOAD_TYPE_DISABLED; goto END; } @@ -878,9 +880,11 @@ bool toxav_video_send_frame(ToxAV* av, uint32_t friend_number, uint16_t width, u goto END; } - if (call->video_bit_rate == 0) { + if (call->video_bit_rate == 0 || + !(call->msi_call->self_capabilities & msi_CapSVideo) || + !(call->msi_call->peer_capabilities & msi_CapRVideo)) { pthread_mutex_unlock(av->mutex); - rc = TOXAV_ERR_SEND_FRAME_BIT_RATE_NOT_SET; + rc = TOXAV_ERR_SEND_FRAME_PAYLOAD_TYPE_DISABLED; goto END; } @@ -1143,6 +1147,16 @@ int callback_capabilites(void* toxav_inst, MSICall* call) ToxAV* toxav = toxav_inst; pthread_mutex_lock(toxav->mutex); + if (call->peer_capabilities & msi_CapSAudio) + rtp_start_receiving(((ToxAVCall*)call->av_call)->audio.first); + else + rtp_stop_receiving(((ToxAVCall*)call->av_call)->audio.first); + + if (call->peer_capabilities & msi_CapSVideo) + rtp_start_receiving(((ToxAVCall*)call->av_call)->video.first); + else + rtp_stop_receiving(((ToxAVCall*)call->av_call)->video.first); + invoke_call_state(toxav, call->friend_number, call->peer_capabilities); pthread_mutex_unlock(toxav->mutex); diff --git a/toxav/toxav.h b/toxav/toxav.h index 0a25fc96..d5641d74 100644 --- a/toxav/toxav.h +++ b/toxav/toxav.h @@ -543,9 +543,10 @@ typedef enum TOXAV_ERR_SEND_FRAME { */ TOXAV_ERR_SEND_FRAME_INVALID, /** - * Bit rate for this payload type was not set up. + * Either friend turned off audio or video receiving or we turned off sending + * for the said payload. */ - TOXAV_ERR_SEND_FRAME_BIT_RATE_NOT_SET, + TOXAV_ERR_SEND_FRAME_PAYLOAD_TYPE_DISABLED, /** * Failed to push frame through rtp interface. */