diff options
Diffstat (limited to 'toxav')
-rw-r--r-- | toxav/av_test.c | 3 | ||||
-rw-r--r-- | toxav/codec.c | 19 | ||||
-rw-r--r-- | toxav/codec.h | 1 | ||||
-rw-r--r-- | toxav/toxav.c | 2 |
4 files changed, 19 insertions, 6 deletions
diff --git a/toxav/av_test.c b/toxav/av_test.c index 46fd97e1..9be648f6 100644 --- a/toxav/av_test.c +++ b/toxav/av_test.c | |||
@@ -156,7 +156,7 @@ void iterate(Tox* Bsn, ToxAV* AliceAV, ToxAV* BobAV) | |||
156 | toxav_iteration(AliceAV); | 156 | toxav_iteration(AliceAV); |
157 | toxav_iteration(BobAV); | 157 | toxav_iteration(BobAV); |
158 | 158 | ||
159 | c_sleep(20); | 159 | c_sleep(toxav_iteration_interval(AliceAV)); |
160 | } | 160 | } |
161 | 161 | ||
162 | int device_read_frame(ALCdevice* device, int32_t frame_dur, int16_t* PCM, size_t max_size) | 162 | int device_read_frame(ALCdevice* device, int32_t frame_dur, int16_t* PCM, size_t max_size) |
@@ -652,7 +652,6 @@ int main (int argc, char** argv) | |||
652 | } | 652 | } |
653 | 653 | ||
654 | iterate(Bsn, AliceAV, BobAV); | 654 | iterate(Bsn, AliceAV, BobAV); |
655 | // c_sleep(20); | ||
656 | } | 655 | } |
657 | 656 | ||
658 | { | 657 | { |
diff --git a/toxav/codec.c b/toxav/codec.c index 80975b70..c3cb2622 100644 --- a/toxav/codec.c +++ b/toxav/codec.c | |||
@@ -258,7 +258,7 @@ void cs_do(CSSession *cs) | |||
258 | if (cs->audio_decoder) { /* If receiving enabled */ | 258 | if (cs->audio_decoder) { /* If receiving enabled */ |
259 | RTPMessage *msg; | 259 | RTPMessage *msg; |
260 | 260 | ||
261 | uint16_t fsize = 16000; /* Max frame size for 48 kHz */ | 261 | uint16_t fsize = 10000; /* Should be enough for all normal frequences */ |
262 | int16_t tmp[fsize * 2]; | 262 | int16_t tmp[fsize * 2]; |
263 | 263 | ||
264 | while ((msg = jbuf_read(cs->j_buf, &success)) || success == 2) { | 264 | while ((msg = jbuf_read(cs->j_buf, &success)) || success == 2) { |
@@ -293,6 +293,7 @@ void cs_do(CSSession *cs) | |||
293 | LOGGER_WARNING("Decoding error: %s", opus_strerror(rc)); | 293 | LOGGER_WARNING("Decoding error: %s", opus_strerror(rc)); |
294 | } else if (cs->acb.first) { | 294 | } else if (cs->acb.first) { |
295 | /* Play */ | 295 | /* Play */ |
296 | LOGGER_DEBUG("Playing audio frame size: %d chans: %d srate: %d", rc, cs->last_pack_channels, cs->last_packet_sampling_rate); | ||
296 | cs->acb.first(cs->agent, cs->friend_id, tmp, rc, | 297 | cs->acb.first(cs->agent, cs->friend_id, tmp, rc, |
297 | cs->last_pack_channels, cs->last_packet_sampling_rate, cs->acb.second); | 298 | cs->last_pack_channels, cs->last_packet_sampling_rate, cs->acb.second); |
298 | } | 299 | } |
@@ -598,6 +599,7 @@ int cs_set_sending_audio_bitrate(CSSession *cs, int32_t rate) | |||
598 | return -1; | 599 | return -1; |
599 | } | 600 | } |
600 | 601 | ||
602 | LOGGER_DEBUG("Set new encoder bitrate to: %d", rate); | ||
601 | return 0; | 603 | return 0; |
602 | } | 604 | } |
603 | 605 | ||
@@ -607,6 +609,9 @@ int cs_set_sending_audio_sampling_rate(CSSession* cs, int32_t rate) | |||
607 | if (cs->audio_encoder == NULL) | 609 | if (cs->audio_encoder == NULL) |
608 | return -1; | 610 | return -1; |
609 | 611 | ||
612 | if (cs->encoder_sample_rate == rate) | ||
613 | return 0; | ||
614 | |||
610 | int rc = OPUS_OK; | 615 | int rc = OPUS_OK; |
611 | int bitrate = 0; | 616 | int bitrate = 0; |
612 | int channels = cs->encoder_channels; | 617 | int channels = cs->encoder_channels; |
@@ -619,6 +624,9 @@ int cs_set_sending_audio_sampling_rate(CSSession* cs, int32_t rate) | |||
619 | } | 624 | } |
620 | 625 | ||
621 | cs_disable_audio_sending(cs); | 626 | cs_disable_audio_sending(cs); |
627 | cs->encoder_sample_rate = rate; | ||
628 | |||
629 | LOGGER_DEBUG("Set new encoder sampling rate: %d", rate); | ||
622 | return cs_enable_audio_sending(cs, bitrate, channels); | 630 | return cs_enable_audio_sending(cs, bitrate, channels); |
623 | } | 631 | } |
624 | 632 | ||
@@ -642,6 +650,8 @@ int cs_set_sending_audio_channels(CSSession* cs, int32_t count) | |||
642 | } | 650 | } |
643 | 651 | ||
644 | cs_disable_audio_sending(cs); | 652 | cs_disable_audio_sending(cs); |
653 | |||
654 | LOGGER_DEBUG("Set new encoder channel count: %d", count); | ||
645 | return cs_enable_audio_sending(cs, bitrate, count); | 655 | return cs_enable_audio_sending(cs, bitrate, count); |
646 | } | 656 | } |
647 | 657 | ||
@@ -674,8 +684,12 @@ int cs_enable_audio_sending(CSSession* cs, uint32_t bitrate, int channels) | |||
674 | if (cs->audio_encoder) | 684 | if (cs->audio_encoder) |
675 | return 0; | 685 | return 0; |
676 | 686 | ||
687 | if (!cs->encoder_sample_rate) | ||
688 | cs->encoder_sample_rate = 48000; | ||
689 | cs->encoder_channels = channels; | ||
690 | |||
677 | int rc = OPUS_OK; | 691 | int rc = OPUS_OK; |
678 | cs->audio_encoder = opus_encoder_create(48000, channels, OPUS_APPLICATION_AUDIO, &rc); | 692 | cs->audio_encoder = opus_encoder_create(cs->encoder_sample_rate, channels, OPUS_APPLICATION_AUDIO, &rc); |
679 | 693 | ||
680 | if ( rc != OPUS_OK ) { | 694 | if ( rc != OPUS_OK ) { |
681 | LOGGER_ERROR("Error while starting audio encoder: %s", opus_strerror(rc)); | 695 | LOGGER_ERROR("Error while starting audio encoder: %s", opus_strerror(rc)); |
@@ -696,7 +710,6 @@ int cs_enable_audio_sending(CSSession* cs, uint32_t bitrate, int channels) | |||
696 | goto FAILURE; | 710 | goto FAILURE; |
697 | } | 711 | } |
698 | 712 | ||
699 | cs->encoder_channels = channels; | ||
700 | return 0; | 713 | return 0; |
701 | 714 | ||
702 | FAILURE: | 715 | FAILURE: |
diff --git a/toxav/codec.h b/toxav/codec.h index 6a673990..971a9e05 100644 --- a/toxav/codec.h +++ b/toxav/codec.h | |||
@@ -108,6 +108,7 @@ typedef struct CSSession_s { | |||
108 | /* audio encoding */ | 108 | /* audio encoding */ |
109 | OpusEncoder *audio_encoder; | 109 | OpusEncoder *audio_encoder; |
110 | int32_t encoder_channels; | 110 | int32_t encoder_channels; |
111 | int32_t encoder_sample_rate; | ||
111 | 112 | ||
112 | /* audio decoding */ | 113 | /* audio decoding */ |
113 | OpusDecoder *audio_decoder; | 114 | OpusDecoder *audio_decoder; |
diff --git a/toxav/toxav.c b/toxav/toxav.c index 7cf8cec4..850c2fc7 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c | |||
@@ -957,7 +957,7 @@ bool call_prepare_transmission(ToxAVCall* call) | |||
957 | call->rtps[audio_index]->cs = call->cs; | 957 | call->rtps[audio_index]->cs = call->cs; |
958 | 958 | ||
959 | /* Only enable sending if bitrate is defined */ | 959 | /* Only enable sending if bitrate is defined */ |
960 | if (call->s_audio_b > 0 && cs_enable_audio_sending(call->cs, call->s_audio_b, 2) != 0) { | 960 | if (call->s_audio_b > 0 && cs_enable_audio_sending(call->cs, call->s_audio_b * 1000, 2) != 0) { |
961 | LOGGER_WARNING("Failed to enable audio sending!"); | 961 | LOGGER_WARNING("Failed to enable audio sending!"); |
962 | goto FAILURE; | 962 | goto FAILURE; |
963 | } | 963 | } |