summaryrefslogtreecommitdiff
path: root/toxav/audio.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-08-31 19:12:19 +0100
committeriphydf <iphydf@users.noreply.github.com>2016-08-31 20:04:16 +0100
commit633da98ae69866efb195e00d9a3a22ace6bada66 (patch)
tree875535f3d2257c4ea5bb97a553b2f1beab4a1590 /toxav/audio.c
parent6356eb4e4fe407fa7870f2a685d0d08b5c2ec5bb (diff)
Add braces to all if statements.
Diffstat (limited to 'toxav/audio.c')
-rw-r--r--toxav/audio.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/toxav/audio.c b/toxav/audio.c
index 9fd8f6f1..eaa1f6d0 100644
--- a/toxav/audio.c
+++ b/toxav/audio.c
@@ -76,8 +76,9 @@ ACSession *ac_new(Logger *log, ToxAV *av, uint32_t friend_number, toxav_audio_re
76 /* Initialize encoders with default values */ 76 /* Initialize encoders with default values */
77 ac->encoder = create_audio_encoder(log, 48000, 48000, 2); 77 ac->encoder = create_audio_encoder(log, 48000, 48000, 2);
78 78
79 if (ac->encoder == NULL) 79 if (ac->encoder == NULL) {
80 goto DECODER_CLEANUP; 80 goto DECODER_CLEANUP;
81 }
81 82
82 ac->le_bit_rate = 48000; 83 ac->le_bit_rate = 48000;
83 ac->le_sample_rate = 48000; 84 ac->le_sample_rate = 48000;
@@ -110,8 +111,9 @@ BASE_CLEANUP:
110} 111}
111void ac_kill(ACSession *ac) 112void ac_kill(ACSession *ac)
112{ 113{
113 if (!ac) 114 if (!ac) {
114 return; 115 return;
116 }
115 117
116 opus_encoder_destroy(ac->encoder); 118 opus_encoder_destroy(ac->encoder);
117 opus_decoder_destroy(ac->decoder); 119 opus_decoder_destroy(ac->decoder);
@@ -124,8 +126,9 @@ void ac_kill(ACSession *ac)
124} 126}
125void ac_iterate(ACSession *ac) 127void ac_iterate(ACSession *ac)
126{ 128{
127 if (!ac) 129 if (!ac) {
128 return; 130 return;
131 }
129 132
130 /* TODO fix this and jitter buffering */ 133 /* TODO fix this and jitter buffering */
131 134
@@ -196,8 +199,9 @@ void ac_iterate(ACSession *ac)
196} 199}
197int ac_queue_message(void *acp, struct RTPMessage *msg) 200int ac_queue_message(void *acp, struct RTPMessage *msg)
198{ 201{
199 if (!acp || !msg) 202 if (!acp || !msg) {
200 return -1; 203 return -1;
204 }
201 205
202 ACSession *ac = acp; 206 ACSession *ac = acp;
203 207
@@ -231,8 +235,9 @@ int ac_reconfigure_encoder(ACSession *ac, int32_t bit_rate, int32_t sampling_rat
231 sampling_rate, channels, 235 sampling_rate, channels,
232 &ac->le_bit_rate, 236 &ac->le_bit_rate,
233 &ac->le_sample_rate, 237 &ac->le_sample_rate,
234 &ac->le_channel_count)) 238 &ac->le_channel_count)) {
235 return -1; 239 return -1;
240 }
236 241
237 return 0; 242 return 0;
238} 243}
@@ -257,7 +262,9 @@ static struct JitterBuffer *jbuf_new(uint32_t capacity)
257 262
258 struct JitterBuffer *q; 263 struct JitterBuffer *q;
259 264
260 if (!(q = calloc(sizeof(struct JitterBuffer), 1))) return NULL; 265 if (!(q = calloc(sizeof(struct JitterBuffer), 1))) {
266 return NULL;
267 }
261 268
262 if (!(q->queue = calloc(sizeof(struct RTPMessage *), size))) { 269 if (!(q->queue = calloc(sizeof(struct RTPMessage *), size))) {
263 free(q); 270 free(q);
@@ -279,7 +286,9 @@ static void jbuf_clear(struct JitterBuffer *q)
279} 286}
280static void jbuf_free(struct JitterBuffer *q) 287static void jbuf_free(struct JitterBuffer *q)
281{ 288{
282 if (!q) return; 289 if (!q) {
290 return;
291 }
283 292
284 jbuf_clear(q); 293 jbuf_clear(q);
285 free(q->queue); 294 free(q->queue);
@@ -301,13 +310,15 @@ static int jbuf_write(Logger *log, struct JitterBuffer *q, struct RTPMessage *m)
301 return 0; 310 return 0;
302 } 311 }
303 312
304 if (q->queue[num]) 313 if (q->queue[num]) {
305 return -1; 314 return -1;
315 }
306 316
307 q->queue[num] = m; 317 q->queue[num] = m;
308 318
309 if ((sequnum - q->bottom) >= (q->top - q->bottom)) 319 if ((sequnum - q->bottom) >= (q->top - q->bottom)) {
310 q->top = sequnum + 1; 320 q->top = sequnum + 1;
321 }
311 322
312 return 0; 323 return 0;
313} 324}
@@ -394,14 +405,15 @@ bool reconfigure_audio_encoder(Logger *log, OpusEncoder **e, int32_t new_br, int
394 if (*old_sr != new_sr || *old_ch != new_ch) { 405 if (*old_sr != new_sr || *old_ch != new_ch) {
395 OpusEncoder *new_encoder = create_audio_encoder(log, new_br, new_sr, new_ch); 406 OpusEncoder *new_encoder = create_audio_encoder(log, new_br, new_sr, new_ch);
396 407
397 if (new_encoder == NULL) 408 if (new_encoder == NULL) {
398 return false; 409 return false;
410 }
399 411
400 opus_encoder_destroy(*e); 412 opus_encoder_destroy(*e);
401 *e = new_encoder; 413 *e = new_encoder;
402 } else if (*old_br == new_br) 414 } else if (*old_br == new_br) {
403 return true; /* Nothing changed */ 415 return true; /* Nothing changed */
404 else { 416 } else {
405 int status = opus_encoder_ctl(*e, OPUS_SET_BITRATE(new_br)); 417 int status = opus_encoder_ctl(*e, OPUS_SET_BITRATE(new_br));
406 418
407 if (status != OPUS_OK) { 419 if (status != OPUS_OK) {
@@ -420,8 +432,9 @@ bool reconfigure_audio_encoder(Logger *log, OpusEncoder **e, int32_t new_br, int
420bool reconfigure_audio_decoder(ACSession *ac, int32_t sampling_rate, int8_t channels) 432bool reconfigure_audio_decoder(ACSession *ac, int32_t sampling_rate, int8_t channels)
421{ 433{
422 if (sampling_rate != ac->ld_sample_rate || channels != ac->ld_channel_count) { 434 if (sampling_rate != ac->ld_sample_rate || channels != ac->ld_channel_count) {
423 if (current_time_monotonic() - ac->ldrts < 500) 435 if (current_time_monotonic() - ac->ldrts < 500) {
424 return false; 436 return false;
437 }
425 438
426 int status; 439 int status;
427 OpusDecoder *new_dec = opus_decoder_create(sampling_rate, channels, &status); 440 OpusDecoder *new_dec = opus_decoder_create(sampling_rate, channels, &status);