mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Implement handling capability change on rtp level
This commit is contained in:
parent
13148d7d7c
commit
6c126e34e6
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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 )
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue
Block a user