summaryrefslogtreecommitdiff
path: root/toxav/codec.c
diff options
context:
space:
mode:
authormannol <eniz_vukovic@hotmail.com>2015-03-23 22:22:17 +0100
committermannol <eniz_vukovic@hotmail.com>2015-03-23 22:22:17 +0100
commit995bddbc26be5106cb33400311fbb669e314312a (patch)
tree0d40708057c585e6a5a2d5ef891b5a8ad70c635a /toxav/codec.c
parent62af82705a805648a4dba54a7f516681e5163923 (diff)
Audio works in test
Diffstat (limited to 'toxav/codec.c')
-rw-r--r--toxav/codec.c19
1 files changed, 16 insertions, 3 deletions
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
702FAILURE: 715FAILURE: