mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Added payload turning off by setting bit rate to 0
This commit is contained in:
parent
9aba4ec273
commit
08bc4eb0e0
@ -34,6 +34,7 @@
|
||||
#define TEST_REJECT 1
|
||||
#define TEST_CANCEL 1
|
||||
#define TEST_MUTE_UNMUTE 1
|
||||
#define TEST_STOP_RESUME_PAYLOAD 1
|
||||
|
||||
|
||||
typedef struct {
|
||||
@ -424,6 +425,58 @@ START_TEST(test_AV_flows)
|
||||
printf("Success!\n");
|
||||
}
|
||||
|
||||
if (TEST_STOP_RESUME_PAYLOAD) { /* Stop and resume audio/video payload */
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
|
||||
printf("Call started as audio only\n");
|
||||
printf("Turning on video for Alice...\n");
|
||||
ck_assert(toxav_video_bit_rate_set(AliceAV, 0, 1000, false, NULL));
|
||||
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
ck_assert(BobCC.state & TOXAV_CALL_STATE_SENDING_V);
|
||||
|
||||
printf("Turning off video for Alice...\n");
|
||||
ck_assert(toxav_video_bit_rate_set(AliceAV, 0, 0, false, NULL));
|
||||
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
ck_assert(!(BobCC.state & TOXAV_CALL_STATE_SENDING_V));
|
||||
|
||||
printf("Turning off audio for Alice...\n");
|
||||
ck_assert(toxav_audio_bit_rate_set(AliceAV, 0, 0, false, NULL));
|
||||
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
ck_assert(!(BobCC.state & TOXAV_CALL_STATE_SENDING_A));
|
||||
}
|
||||
|
||||
toxav_kill(BobAV);
|
||||
toxav_kill(AliceAV);
|
||||
tox_kill(Bob);
|
||||
|
@ -518,6 +518,10 @@ error for send_frame {
|
||||
* small or too large, or the audio sampling rate may be unsupported.
|
||||
*/
|
||||
INVALID,
|
||||
/**
|
||||
* Bit rate for this payload type was not set up.
|
||||
*/
|
||||
BIT_RATE_NOT_SET,
|
||||
/**
|
||||
* Failed to push frame through rtp interface.
|
||||
*/
|
||||
|
@ -596,6 +596,8 @@ void toxav_callback_audio_bit_rate_status(ToxAV* av, toxav_audio_bit_rate_status
|
||||
|
||||
bool toxav_audio_bit_rate_set(ToxAV* av, uint32_t friend_number, uint32_t audio_bit_rate, bool force, TOXAV_ERR_SET_BIT_RATE* error)
|
||||
{
|
||||
LOGGER_DEBUG("Setting new audio bitrate to: %d", audio_bit_rate);
|
||||
|
||||
TOXAV_ERR_SET_BIT_RATE rc = TOXAV_ERR_SET_BIT_RATE_OK;
|
||||
ToxAVCall* call;
|
||||
|
||||
@ -604,7 +606,7 @@ bool toxav_audio_bit_rate_set(ToxAV* av, uint32_t friend_number, uint32_t audio_
|
||||
goto END;
|
||||
}
|
||||
|
||||
if (audio_bit_rate_invalid(audio_bit_rate)) {
|
||||
if (audio_bit_rate && audio_bit_rate_invalid(audio_bit_rate)) {
|
||||
rc = TOXAV_ERR_SET_BIT_RATE_INVALID;
|
||||
goto END;
|
||||
}
|
||||
@ -622,18 +624,39 @@ bool toxav_audio_bit_rate_set(ToxAV* av, uint32_t friend_number, uint32_t audio_
|
||||
goto END;
|
||||
}
|
||||
|
||||
/* Video sending is turned off; notify peer */
|
||||
if (audio_bit_rate == 0) {
|
||||
call->audio_bit_rate = 0;
|
||||
|
||||
msi_change_capabilities(call->msi_call, call->msi_call->
|
||||
self_capabilities ^ msi_CapSAudio);
|
||||
pthread_mutex_unlock(av->mutex);
|
||||
goto END;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(call->mutex);
|
||||
|
||||
if (audio_bit_rate > call->audio_bit_rate && !force)
|
||||
ba_set(&call->aba, audio_bit_rate);
|
||||
else {
|
||||
/* Cancel any previous non forceful bitrate change request */
|
||||
memset(&call->aba, 0, sizeof(call->aba));
|
||||
if (call->audio_bit_rate == 0) {
|
||||
/* The audio has been turned off before this */
|
||||
call->audio_bit_rate = audio_bit_rate;
|
||||
|
||||
msi_change_capabilities(call->msi_call, call->
|
||||
msi_call->self_capabilities | msi_CapSAudio);
|
||||
|
||||
if (!force && av->abcb.first)
|
||||
av->abcb.first (av, call->friend_number, true, audio_bit_rate, av->abcb.second);
|
||||
} else {
|
||||
/* The audio was active before this */
|
||||
if (audio_bit_rate > call->audio_bit_rate && !force)
|
||||
ba_set(&call->aba, audio_bit_rate);
|
||||
else {
|
||||
/* Cancel any previous non forceful bitrate change request */
|
||||
memset(&call->aba, 0, sizeof(call->aba));
|
||||
call->audio_bit_rate = audio_bit_rate;
|
||||
|
||||
if (!force && av->abcb.first)
|
||||
av->abcb.first (av, call->friend_number, true, audio_bit_rate, av->abcb.second);
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(call->mutex);
|
||||
@ -656,6 +679,8 @@ void toxav_callback_video_bit_rate_status(ToxAV* av, toxav_video_bit_rate_status
|
||||
|
||||
bool toxav_video_bit_rate_set(ToxAV* av, uint32_t friend_number, uint32_t video_bit_rate, bool force, TOXAV_ERR_SET_BIT_RATE* error)
|
||||
{
|
||||
LOGGER_DEBUG("Setting new video bitrate to: %d", video_bit_rate);
|
||||
|
||||
TOXAV_ERR_SET_BIT_RATE rc = TOXAV_ERR_SET_BIT_RATE_OK;
|
||||
ToxAVCall* call;
|
||||
|
||||
@ -664,7 +689,7 @@ bool toxav_video_bit_rate_set(ToxAV* av, uint32_t friend_number, uint32_t video_
|
||||
goto END;
|
||||
}
|
||||
|
||||
if (video_bit_rate_invalid(video_bit_rate)) {
|
||||
if (video_bit_rate && video_bit_rate_invalid(video_bit_rate)) {
|
||||
rc = TOXAV_ERR_SET_BIT_RATE_INVALID;
|
||||
goto END;
|
||||
}
|
||||
@ -682,17 +707,39 @@ bool toxav_video_bit_rate_set(ToxAV* av, uint32_t friend_number, uint32_t video_
|
||||
goto END;
|
||||
}
|
||||
|
||||
/* Video sending is turned off; notify peer */
|
||||
if (video_bit_rate == 0) {
|
||||
call->video_bit_rate = 0;
|
||||
|
||||
msi_change_capabilities(call->msi_call, call->msi_call->
|
||||
self_capabilities ^ msi_CapSVideo);
|
||||
pthread_mutex_unlock(av->mutex);
|
||||
goto END;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(call->mutex);
|
||||
|
||||
if (video_bit_rate > call->video_bit_rate && !force)
|
||||
ba_set(&call->vba, video_bit_rate);
|
||||
else {
|
||||
/* Cancel any previous non forceful bitrate change request */
|
||||
memset(&call->vba, 0, sizeof(call->vba));
|
||||
if (call->video_bit_rate == 0) {
|
||||
/* The video has been turned off before this */
|
||||
call->video_bit_rate = video_bit_rate;
|
||||
|
||||
msi_change_capabilities(call->msi_call, call->
|
||||
msi_call->self_capabilities | msi_CapSVideo);
|
||||
|
||||
if (!force && av->vbcb.first)
|
||||
av->vbcb.first (av, call->friend_number, true, video_bit_rate, av->vbcb.second);
|
||||
} else {
|
||||
/* The video was active before this */
|
||||
if (video_bit_rate > call->video_bit_rate && !force)
|
||||
ba_set(&call->vba, video_bit_rate);
|
||||
else {
|
||||
/* Cancel any previous non forceful bitrate change request */
|
||||
memset(&call->vba, 0, sizeof(call->vba));
|
||||
call->video_bit_rate = video_bit_rate;
|
||||
|
||||
if (!force && av->vbcb.first)
|
||||
av->vbcb.first (av, call->friend_number, true, video_bit_rate, av->vbcb.second);
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(call->mutex);
|
||||
@ -723,6 +770,12 @@ bool toxav_audio_send_frame(ToxAV* av, uint32_t friend_number, const int16_t* pc
|
||||
goto END;
|
||||
}
|
||||
|
||||
if (call->audio_bit_rate == 0) {
|
||||
pthread_mutex_unlock(av->mutex);
|
||||
rc = TOXAV_ERR_SEND_FRAME_BIT_RATE_NOT_SET;
|
||||
goto END;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(call->mutex_audio);
|
||||
pthread_mutex_unlock(av->mutex);
|
||||
|
||||
@ -825,6 +878,12 @@ bool toxav_video_send_frame(ToxAV* av, uint32_t friend_number, uint16_t width, u
|
||||
goto END;
|
||||
}
|
||||
|
||||
if (call->video_bit_rate == 0) {
|
||||
pthread_mutex_unlock(av->mutex);
|
||||
rc = TOXAV_ERR_SEND_FRAME_BIT_RATE_NOT_SET;
|
||||
goto END;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(call->mutex_video);
|
||||
pthread_mutex_unlock(av->mutex);
|
||||
|
||||
|
@ -540,6 +540,10 @@ typedef enum TOXAV_ERR_SEND_FRAME {
|
||||
* small or too large, or the audio sampling rate may be unsupported.
|
||||
*/
|
||||
TOXAV_ERR_SEND_FRAME_INVALID,
|
||||
/**
|
||||
* Bit rate for this payload type was not set up.
|
||||
*/
|
||||
TOXAV_ERR_SEND_FRAME_BIT_RATE_NOT_SET,
|
||||
/**
|
||||
* Failed to push frame through rtp interface.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user