summaryrefslogtreecommitdiff
path: root/toxav/audio.c
diff options
context:
space:
mode:
authormannol <eniz_vukovic@hotmail.com>2015-04-29 01:01:25 +0200
committermannol <eniz_vukovic@hotmail.com>2015-04-29 01:01:25 +0200
commit9bba7a0434d0967d5dd76b8afc7783ea2edad0cf (patch)
tree6486c250acb38429a63a62e54cd1e4bcb0a029ee /toxav/audio.c
parente4a020333d76bc30172f54f2545677f01bdd54b6 (diff)
Done
Diffstat (limited to 'toxav/audio.c')
-rw-r--r--toxav/audio.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/toxav/audio.c b/toxav/audio.c
index 2f068c85..c592a7da 100644
--- a/toxav/audio.c
+++ b/toxav/audio.c
@@ -31,14 +31,14 @@ static void jbuf_clear(struct JitterBuffer *q);
31static void jbuf_free(struct JitterBuffer *q); 31static void jbuf_free(struct JitterBuffer *q);
32static int jbuf_write(struct JitterBuffer *q, RTPMessage *m); 32static int jbuf_write(struct JitterBuffer *q, RTPMessage *m);
33static RTPMessage *jbuf_read(struct JitterBuffer *q, int32_t *success); 33static RTPMessage *jbuf_read(struct JitterBuffer *q, int32_t *success);
34 34OpusEncoder* create_audio_encoder (int32_t bit_rate, int32_t sampling_rate, int32_t channel_count);
35OpusEncoder* create_audio_encoder (int32_t bitrate, int32_t sampling_rate, int32_t channel_count);
36bool reconfigure_audio_encoder(OpusEncoder** e, int32_t new_br, int32_t new_sr, uint8_t new_ch, 35bool reconfigure_audio_encoder(OpusEncoder** e, int32_t new_br, int32_t new_sr, uint8_t new_ch,
37 int32_t *old_br, int32_t *old_sr, int32_t *old_ch); 36 int32_t *old_br, int32_t *old_sr, int32_t *old_ch);
38bool reconfigure_audio_decoder(ACSession* ac, int32_t sampling_rate, int8_t channels); 37bool reconfigure_audio_decoder(ACSession* ac, int32_t sampling_rate, int8_t channels);
39 38
40 39
41ACSession* ac_new(ToxAV* av, uint32_t friend_id, toxav_receive_audio_frame_cb *cb, void *cb_data) 40
41ACSession* ac_new(ToxAV* av, uint32_t friend_number, toxav_receive_audio_frame_cb *cb, void *cb_data)
42{ 42{
43 ACSession *ac = calloc(sizeof(ACSession), 1); 43 ACSession *ac = calloc(sizeof(ACSession), 1);
44 44
@@ -78,11 +78,11 @@ ACSession* ac_new(ToxAV* av, uint32_t friend_id, toxav_receive_audio_frame_cb *c
78 goto DECODER_CLEANUP; 78 goto DECODER_CLEANUP;
79 } 79 }
80 80
81 ac->last_encoding_bitrate = 48000; 81 ac->last_encoding_bit_rate = 48000;
82 ac->last_encoding_sampling_rate = 48000; 82 ac->last_encoding_sampling_rate = 48000;
83 ac->last_encoding_channel_count = 2; 83 ac->last_encoding_channel_count = 2;
84 84
85 ac->last_test_encoding_bitrate = 48000; 85 ac->last_test_encoding_bit_rate = 48000;
86 ac->last_test_encoding_sampling_rate = 48000; 86 ac->last_test_encoding_sampling_rate = 48000;
87 ac->last_test_encoding_channel_count = 2; 87 ac->last_test_encoding_channel_count = 2;
88 88
@@ -97,7 +97,7 @@ ACSession* ac_new(ToxAV* av, uint32_t friend_id, toxav_receive_audio_frame_cb *c
97 ac->last_packet_channel_count = 1; 97 ac->last_packet_channel_count = 1;
98 98
99 ac->av = av; 99 ac->av = av;
100 ac->friend_id = friend_id; 100 ac->friend_number = friend_number;
101 ac->acb.first = cb; 101 ac->acb.first = cb;
102 ac->acb.second = cb_data; 102 ac->acb.second = cb_data;
103 103
@@ -181,7 +181,7 @@ void ac_do(ACSession* ac)
181 } else if (ac->acb.first) { 181 } else if (ac->acb.first) {
182 ac->last_packet_frame_duration = (rc * 1000) / ac->last_packet_sampling_rate; 182 ac->last_packet_frame_duration = (rc * 1000) / ac->last_packet_sampling_rate;
183 183
184 ac->acb.first(ac->av, ac->friend_id, tmp, rc * ac->last_packet_channel_count, 184 ac->acb.first(ac->av, ac->friend_number, tmp, rc * ac->last_packet_channel_count,
185 ac->last_packet_channel_count, ac->last_packet_sampling_rate, ac->acb.second); 185 ac->last_packet_channel_count, ac->last_packet_sampling_rate, ac->acb.second);
186 } 186 }
187 187
@@ -220,28 +220,27 @@ int ac_queue_message(void* acp, struct RTPMessage_s *msg)
220 220
221 return 0; 221 return 0;
222} 222}
223int ac_reconfigure_encoder(ACSession* ac, int32_t bitrate, int32_t sampling_rate, uint8_t channels) 223int ac_reconfigure_encoder(ACSession* ac, int32_t bit_rate, int32_t sampling_rate, uint8_t channels)
224{ 224{
225 if (!ac || !reconfigure_audio_encoder(&ac->encoder, bitrate, sampling_rate, channels, 225 if (!ac || !reconfigure_audio_encoder(&ac->encoder, bit_rate, sampling_rate, channels,
226 &ac->last_encoding_bitrate, &ac->last_encoding_sampling_rate, &ac->last_encoding_channel_count)) 226 &ac->last_encoding_bit_rate, &ac->last_encoding_sampling_rate, &ac->last_encoding_channel_count))
227 return -1; 227 return -1;
228 228
229 LOGGER_DEBUG ("Reconfigured audio encoder br: %d sr: %d cc:%d", bitrate, sampling_rate, channels); 229 LOGGER_DEBUG ("Reconfigured audio encoder br: %d sr: %d cc:%d", bit_rate, sampling_rate, channels);
230 return 0; 230 return 0;
231} 231}
232int ac_reconfigure_test_encoder(ACSession* ac, int32_t bitrate, int32_t sampling_rate, uint8_t channels) 232int ac_reconfigure_test_encoder(ACSession* ac, int32_t bit_rate, int32_t sampling_rate, uint8_t channels)
233{ 233{
234 if (!ac || !reconfigure_audio_encoder(&ac->test_encoder, bitrate, sampling_rate, channels, 234 if (!ac || !reconfigure_audio_encoder(&ac->test_encoder, bit_rate, sampling_rate, channels,
235 &ac->last_encoding_bitrate, &ac->last_encoding_sampling_rate, &ac->last_encoding_channel_count)) 235 &ac->last_encoding_bit_rate, &ac->last_encoding_sampling_rate, &ac->last_encoding_channel_count))
236 return -1; 236 return -1;
237 237
238 LOGGER_DEBUG ("Reconfigured test audio encoder br: %d sr: %d cc:%d", bitrate, sampling_rate, channels); 238 LOGGER_DEBUG ("Reconfigured test audio encoder br: %d sr: %d cc:%d", bit_rate, sampling_rate, channels);
239 return 0; 239 return 0;
240} 240}
241 241
242 242
243 243
244/* JITTER BUFFER WORK */
245struct JitterBuffer { 244struct JitterBuffer {
246 RTPMessage **queue; 245 RTPMessage **queue;
247 uint32_t size; 246 uint32_t size;
@@ -340,7 +339,7 @@ static RTPMessage *jbuf_read(struct JitterBuffer *q, int32_t *success)
340 *success = 0; 339 *success = 0;
341 return NULL; 340 return NULL;
342} 341}
343OpusEncoder* create_audio_encoder (int32_t bitrate, int32_t sampling_rate, int32_t channel_count) 342OpusEncoder* create_audio_encoder (int32_t bit_rate, int32_t sampling_rate, int32_t channel_count)
344{ 343{
345 int status = OPUS_OK; 344 int status = OPUS_OK;
346 OpusEncoder* rc = opus_encoder_create(sampling_rate, channel_count, OPUS_APPLICATION_AUDIO, &status); 345 OpusEncoder* rc = opus_encoder_create(sampling_rate, channel_count, OPUS_APPLICATION_AUDIO, &status);
@@ -350,7 +349,7 @@ OpusEncoder* create_audio_encoder (int32_t bitrate, int32_t sampling_rate, int32
350 return NULL; 349 return NULL;
351 } 350 }
352 351
353 status = opus_encoder_ctl(rc, OPUS_SET_BITRATE(bitrate)); 352 status = opus_encoder_ctl(rc, OPUS_SET_BITRATE(bit_rate));
354 353
355 if ( status != OPUS_OK ) { 354 if ( status != OPUS_OK ) {
356 LOGGER_ERROR("Error while setting encoder ctl: %s", opus_strerror(status)); 355 LOGGER_ERROR("Error while setting encoder ctl: %s", opus_strerror(status));