summaryrefslogtreecommitdiff
path: root/toxav
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-08-31 20:40:20 +0100
committeriphydf <iphydf@users.noreply.github.com>2016-09-02 11:02:56 +0100
commita9fbdaf46b23db5c598bf33d6bc5c4555b06e674 (patch)
treee7894501bd010d9904fe0069fc1b8121d2da4040 /toxav
parent6f42eadc54e81be50b7a817c72b0cf4d7ec5feb4 (diff)
Do not use `else` after `return`.
http://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code
Diffstat (limited to 'toxav')
-rw-r--r--toxav/audio.c12
-rw-r--r--toxav/group.c1
-rw-r--r--toxav/msi.c9
-rw-r--r--toxav/rtp.c164
-rw-r--r--toxav/toxav.c2
5 files changed, 90 insertions, 98 deletions
diff --git a/toxav/audio.c b/toxav/audio.c
index eaa1f6d0..c0bfa608 100644
--- a/toxav/audio.c
+++ b/toxav/audio.c
@@ -413,13 +413,13 @@ bool reconfigure_audio_encoder(Logger *log, OpusEncoder **e, int32_t new_br, int
413 *e = new_encoder; 413 *e = new_encoder;
414 } else if (*old_br == new_br) { 414 } else if (*old_br == new_br) {
415 return true; /* Nothing changed */ 415 return true; /* Nothing changed */
416 } else { 416 }
417 int status = opus_encoder_ctl(*e, OPUS_SET_BITRATE(new_br));
418 417
419 if (status != OPUS_OK) { 418 int status = opus_encoder_ctl(*e, OPUS_SET_BITRATE(new_br));
420 LOGGER_ERROR(log, "Error while setting encoder ctl: %s", opus_strerror(status)); 419
421 return false; 420 if (status != OPUS_OK) {
422 } 421 LOGGER_ERROR(log, "Error while setting encoder ctl: %s", opus_strerror(status));
422 return false;
423 } 423 }
424 424
425 *old_br = new_br; 425 *old_br = new_br;
diff --git a/toxav/group.c b/toxav/group.c
index dea10af7..969250f8 100644
--- a/toxav/group.c
+++ b/toxav/group.c
@@ -370,7 +370,6 @@ static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, int g
370 if (out_audio_samples <= 0) { 370 if (out_audio_samples <= 0) {
371 return -1; 371 return -1;
372 } 372 }
373
374 } 373 }
375 374
376 if (out_audio) { 375 if (out_audio) {
diff --git a/toxav/msi.c b/toxav/msi.c
index 3becac7e..a62bdb35 100644
--- a/toxav/msi.c
+++ b/toxav/msi.c
@@ -46,7 +46,6 @@ typedef enum {
46 IDRequest = 1, 46 IDRequest = 1,
47 IDError, 47 IDError,
48 IDCapabilities, 48 IDCapabilities,
49
50} MSIHeaderID; 49} MSIHeaderID;
51 50
52 51
@@ -538,7 +537,6 @@ MSICall *new_call (MSISession *session, uint32_t friend_number)
538 } 537 }
539 538
540 session->calls_tail = session->calls_head = friend_number; 539 session->calls_tail = session->calls_head = friend_number;
541
542 } else if (session->calls_tail < friend_number) { /* Appending */ 540 } else if (session->calls_tail < friend_number) { /* Appending */
543 void *tmp = realloc(session->calls, sizeof(MSICall *) * (friend_number + 1)); 541 void *tmp = realloc(session->calls, sizeof(MSICall *) * (friend_number + 1));
544 542
@@ -560,7 +558,6 @@ MSICall *new_call (MSISession *session, uint32_t friend_number)
560 session->calls[session->calls_tail]->next = rc; 558 session->calls[session->calls_tail]->next = rc;
561 559
562 session->calls_tail = friend_number; 560 session->calls_tail = friend_number;
563
564 } else if (session->calls_head > friend_number) { /* Inserting at front */ 561 } else if (session->calls_head > friend_number) { /* Inserting at front */
565 rc->next = session->calls[session->calls_head]; 562 rc->next = session->calls[session->calls_head];
566 session->calls[session->calls_head]->prev = rc; 563 session->calls[session->calls_head]->prev = rc;
@@ -736,7 +733,6 @@ void handle_push (MSICall *call, const MSIMessage *msg)
736 if (invoke_callback(call, msi_OnStart) == -1) { 733 if (invoke_callback(call, msi_OnStart) == -1) {
737 goto FAILURE; 734 goto FAILURE;
738 } 735 }
739
740 } 736 }
741 break; 737 break;
742 738
@@ -767,7 +763,6 @@ void handle_pop (MSICall *call, const MSIMessage *msg)
767 LOGGER_WARNING(call->session->messenger->log, "Friend detected an error: %d", msg->error.value); 763 LOGGER_WARNING(call->session->messenger->log, "Friend detected an error: %d", msg->error.value);
768 call->error = msg->error.value; 764 call->error = msg->error.value;
769 invoke_callback(call, msi_OnError); 765 invoke_callback(call, msi_OnError);
770
771 } else { 766 } else {
772 switch (call->state) { 767 switch (call->state) {
773 case msi_CallInactive: { 768 case msi_CallInactive: {
@@ -812,10 +807,10 @@ void handle_msi_packet (Messenger *m, uint32_t friend_number, const uint8_t *dat
812 LOGGER_WARNING(m->log, "Error parsing message"); 807 LOGGER_WARNING(m->log, "Error parsing message");
813 send_error(m, friend_number, msi_EInvalidMessage); 808 send_error(m, friend_number, msi_EInvalidMessage);
814 return; 809 return;
815 } else {
816 LOGGER_DEBUG(m->log, "Successfully parsed message");
817 } 810 }
818 811
812 LOGGER_DEBUG(m->log, "Successfully parsed message");
813
819 pthread_mutex_lock(session->mutex); 814 pthread_mutex_lock(session->mutex);
820 MSICall *call = get_call(session, friend_number); 815 MSICall *call = get_call(session, friend_number);
821 816
diff --git a/toxav/rtp.c b/toxav/rtp.c
index 1556d23d..38e64dd7 100644
--- a/toxav/rtp.c
+++ b/toxav/rtp.c
@@ -268,12 +268,12 @@ int handle_rtp_packet (Messenger *m, uint32_t friendnumber, const uint8_t *data,
268 */ 268 */
269 if (chloss(session, header)) { 269 if (chloss(session, header)) {
270 return 0; 270 return 0;
271 } else {
272 /* Message is not late; pick up the latest parameters */
273 session->rsequnum = ntohs(header->sequnum);
274 session->rtimestamp = ntohl(header->timestamp);
275 } 271 }
276 272
273 /* Message is not late; pick up the latest parameters */
274 session->rsequnum = ntohs(header->sequnum);
275 session->rtimestamp = ntohl(header->timestamp);
276
277 bwc_add_recv(session->bwc, length); 277 bwc_add_recv(session->bwc, length);
278 278
279 /* Invoke processing of active multiparted message */ 279 /* Invoke processing of active multiparted message */
@@ -296,69 +296,43 @@ int handle_rtp_packet (Messenger *m, uint32_t friendnumber, const uint8_t *data,
296 } 296 }
297 297
298 return session->mcb (session->cs, new_message(length, data, length)); 298 return session->mcb (session->cs, new_message(length, data, length));
299 } else { 299 }
300 /* The message is sent in multiple parts */
301
302 if (session->mp) {
303 /* There are 2 possible situations in this case:
304 * 1) being that we got the part of already processing message.
305 * 2) being that we got the part of a new/old message.
306 *
307 * We handle them differently as we only allow a single multiparted
308 * processing message
309 */
310
311 if (session->mp->header.sequnum == ntohs(header->sequnum) &&
312 session->mp->header.timestamp == ntohl(header->timestamp)) {
313 /* First case */
314
315 /* Make sure we have enough allocated memory */
316 if (session->mp->header.tlen - session->mp->len < length - sizeof(struct RTPHeader) ||
317 session->mp->header.tlen <= ntohs(header->cpart)) {
318 /* There happened to be some corruption on the stream;
319 * continue wihtout this part
320 */
321 return 0;
322 }
323
324 memcpy(session->mp->data + ntohs(header->cpart), data + sizeof(struct RTPHeader),
325 length - sizeof(struct RTPHeader));
326 300
327 session->mp->len += length - sizeof(struct RTPHeader); 301 /* The message is sent in multiple parts */
328 302
329 bwc_add_recv(session->bwc, length); 303 if (session->mp) {
304 /* There are 2 possible situations in this case:
305 * 1) being that we got the part of already processing message.
306 * 2) being that we got the part of a new/old message.
307 *
308 * We handle them differently as we only allow a single multiparted
309 * processing message
310 */
330 311
331 if (session->mp->len == session->mp->header.tlen) { 312 if (session->mp->header.sequnum == ntohs(header->sequnum) &&
332 /* Received a full message; now push it for the further 313 session->mp->header.timestamp == ntohl(header->timestamp)) {
333 * processing. 314 /* First case */
334 */
335 if (session->mcb) {
336 session->mcb (session->cs, session->mp);
337 } else {
338 free(session->mp);
339 }
340 315
341 session->mp = NULL; 316 /* Make sure we have enough allocated memory */
342 } 317 if (session->mp->header.tlen - session->mp->len < length - sizeof(struct RTPHeader) ||
343 } else { 318 session->mp->header.tlen <= ntohs(header->cpart)) {
344 /* Second case */ 319 /* There happened to be some corruption on the stream;
320 * continue wihtout this part
321 */
322 return 0;
323 }
345 324
346 if (session->mp->header.timestamp > ntohl(header->timestamp)) { 325 memcpy(session->mp->data + ntohs(header->cpart), data + sizeof(struct RTPHeader),
347 /* The received message part is from the old message; 326 length - sizeof(struct RTPHeader));
348 * discard it.
349 */
350 return 0;
351 }
352 327
353 /* Measure missing parts of the old message */ 328 session->mp->len += length - sizeof(struct RTPHeader);
354 bwc_add_lost(session->bwc,
355 (session->mp->header.tlen - session->mp->len) +
356 329
357 /* Must account sizes of rtp headers too */ 330 bwc_add_recv(session->bwc, length);
358 ((session->mp->header.tlen - session->mp->len) /
359 MAX_CRYPTO_DATA_SIZE) * sizeof(struct RTPHeader) );
360 331
361 /* Push the previous message for processing */ 332 if (session->mp->len == session->mp->header.tlen) {
333 /* Received a full message; now push it for the further
334 * processing.
335 */
362 if (session->mcb) { 336 if (session->mcb) {
363 session->mcb (session->cs, session->mp); 337 session->mcb (session->cs, session->mp);
364 } else { 338 } else {
@@ -366,40 +340,66 @@ int handle_rtp_packet (Messenger *m, uint32_t friendnumber, const uint8_t *data,
366 } 340 }
367 341
368 session->mp = NULL; 342 session->mp = NULL;
369 goto NEW_MULTIPARTED;
370 } 343 }
371 } else { 344 } else {
372 /* In this case threat the message as if it was received in order 345 /* Second case */
373 */
374
375 /* This is also a point for new multiparted messages */
376NEW_MULTIPARTED:
377 346
378 /* Only allow messages which have arrived in order; 347 if (session->mp->header.timestamp > ntohl(header->timestamp)) {
379 * drop late messages 348 /* The received message part is from the old message;
380 */ 349 * discard it.
381 if (chloss(session, header)) { 350 */
382 return 0; 351 return 0;
383 } else {
384 /* Message is not late; pick up the latest parameters */
385 session->rsequnum = ntohs(header->sequnum);
386 session->rtimestamp = ntohl(header->timestamp);
387 } 352 }
388 353
389 bwc_add_recv(session->bwc, length); 354 /* Measure missing parts of the old message */
355 bwc_add_lost(session->bwc,
356 (session->mp->header.tlen - session->mp->len) +
357
358 /* Must account sizes of rtp headers too */
359 ((session->mp->header.tlen - session->mp->len) /
360 MAX_CRYPTO_DATA_SIZE) * sizeof(struct RTPHeader) );
390 361
391 /* Again, only store message if handler is present 362 /* Push the previous message for processing */
392 */
393 if (session->mcb) { 363 if (session->mcb) {
394 session->mp = new_message(ntohs(header->tlen) + sizeof(struct RTPHeader), data, length); 364 session->mcb (session->cs, session->mp);
365 } else {
366 free(session->mp);
367 }
395 368
396 /* Reposition data if necessary */ 369 session->mp = NULL;
397 if (ntohs(header->cpart)) { 370 goto NEW_MULTIPARTED;
398 ; 371 }
399 } 372 } else {
373 /* In this case threat the message as if it was received in order
374 */
375
376 /* This is also a point for new multiparted messages */
377NEW_MULTIPARTED:
378
379 /* Only allow messages which have arrived in order;
380 * drop late messages
381 */
382 if (chloss(session, header)) {
383 return 0;
384 }
385
386 /* Message is not late; pick up the latest parameters */
387 session->rsequnum = ntohs(header->sequnum);
388 session->rtimestamp = ntohl(header->timestamp);
400 389
401 memmove(session->mp->data + ntohs(header->cpart), session->mp->data, session->mp->len); 390 bwc_add_recv(session->bwc, length);
391
392 /* Again, only store message if handler is present
393 */
394 if (session->mcb) {
395 session->mp = new_message(ntohs(header->tlen) + sizeof(struct RTPHeader), data, length);
396
397 /* Reposition data if necessary */
398 if (ntohs(header->cpart)) {
399 ;
402 } 400 }
401
402 memmove(session->mp->data + ntohs(header->cpart), session->mp->data, session->mp->len);
403 } 403 }
404 } 404 }
405 405
diff --git a/toxav/toxav.c b/toxav/toxav.c
index 126e29a7..749519a2 100644
--- a/toxav/toxav.c
+++ b/toxav/toxav.c
@@ -1087,7 +1087,6 @@ ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, TOXAV_ERR_CALL *error)
1087 } 1087 }
1088 1088
1089 av->calls_tail = av->calls_head = friend_number; 1089 av->calls_tail = av->calls_head = friend_number;
1090
1091 } else if (av->calls_tail < friend_number) { /* Appending */ 1090 } else if (av->calls_tail < friend_number) { /* Appending */
1092 void *tmp = realloc(av->calls, sizeof(ToxAVCall *) * (friend_number + 1)); 1091 void *tmp = realloc(av->calls, sizeof(ToxAVCall *) * (friend_number + 1));
1093 1092
@@ -1111,7 +1110,6 @@ ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, TOXAV_ERR_CALL *error)
1111 av->calls[av->calls_tail]->next = call; 1110 av->calls[av->calls_tail]->next = call;
1112 1111
1113 av->calls_tail = friend_number; 1112 av->calls_tail = friend_number;
1114
1115 } else if (av->calls_head > friend_number) { /* Inserting at front */ 1113 } else if (av->calls_head > friend_number) { /* Inserting at front */
1116 call->next = av->calls[av->calls_head]; 1114 call->next = av->calls[av->calls_head];
1117 av->calls[av->calls_head]->prev = call; 1115 av->calls[av->calls_head]->prev = call;