summaryrefslogtreecommitdiff
path: root/toxav/toxav.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/toxav.c
parent6356eb4e4fe407fa7870f2a685d0d08b5c2ec5bb (diff)
Add braces to all if statements.
Diffstat (limited to 'toxav/toxav.c')
-rw-r--r--toxav/toxav.c118
1 files changed, 76 insertions, 42 deletions
diff --git a/toxav/toxav.c b/toxav/toxav.c
index 4ef5d2b3..d7b367f7 100644
--- a/toxav/toxav.c
+++ b/toxav/toxav.c
@@ -179,8 +179,9 @@ ToxAV *toxav_new(Tox *tox, TOXAV_ERR_NEW *error)
179 179
180END: 180END:
181 181
182 if (error) 182 if (error) {
183 *error = rc; 183 *error = rc;
184 }
184 185
185 if (rc != TOXAV_ERR_NEW_OK) { 186 if (rc != TOXAV_ERR_NEW_OK) {
186 free(av); 187 free(av);
@@ -191,8 +192,9 @@ END:
191} 192}
192void toxav_kill(ToxAV *av) 193void toxav_kill(ToxAV *av)
193{ 194{
194 if (av == NULL) 195 if (av == NULL) {
195 return; 196 return;
197 }
196 198
197 pthread_mutex_lock(av->mutex); 199 pthread_mutex_lock(av->mutex);
198 200
@@ -249,12 +251,14 @@ void toxav_iterate(ToxAV *av)
249 vc_iterate(i->video.second); 251 vc_iterate(i->video.second);
250 252
251 if (i->msi_call->self_capabilities & msi_CapRAudio && 253 if (i->msi_call->self_capabilities & msi_CapRAudio &&
252 i->msi_call->peer_capabilities & msi_CapSAudio) 254 i->msi_call->peer_capabilities & msi_CapSAudio) {
253 rc = MIN(i->audio.second->lp_frame_duration, rc); 255 rc = MIN(i->audio.second->lp_frame_duration, rc);
256 }
254 257
255 if (i->msi_call->self_capabilities & msi_CapRVideo && 258 if (i->msi_call->self_capabilities & msi_CapRVideo &&
256 i->msi_call->peer_capabilities & msi_CapSVideo) 259 i->msi_call->peer_capabilities & msi_CapSVideo) {
257 rc = MIN(i->video.second->lcfd, (uint32_t) rc); 260 rc = MIN(i->video.second->lcfd, (uint32_t) rc);
261 }
258 262
259 uint32_t fid = i->friend_number; 263 uint32_t fid = i->friend_number;
260 264
@@ -262,8 +266,9 @@ void toxav_iterate(ToxAV *av)
262 pthread_mutex_lock(av->mutex); 266 pthread_mutex_lock(av->mutex);
263 267
264 /* In case this call is popped from container stop iteration */ 268 /* In case this call is popped from container stop iteration */
265 if (call_get(av, fid) != i) 269 if (call_get(av, fid) != i) {
266 break; 270 break;
271 }
267 } 272 }
268 } 273 }
269 274
@@ -293,8 +298,9 @@ bool toxav_call(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, uint
293 298
294 ToxAVCall *call = call_new(av, friend_number, &rc); 299 ToxAVCall *call = call_new(av, friend_number, &rc);
295 300
296 if (call == NULL) 301 if (call == NULL) {
297 goto END; 302 goto END;
303 }
298 304
299 call->audio_bit_rate = audio_bit_rate; 305 call->audio_bit_rate = audio_bit_rate;
300 call->video_bit_rate = video_bit_rate; 306 call->video_bit_rate = video_bit_rate;
@@ -315,8 +321,9 @@ bool toxav_call(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, uint
315END: 321END:
316 pthread_mutex_unlock(av->mutex); 322 pthread_mutex_unlock(av->mutex);
317 323
318 if (error) 324 if (error) {
319 *error = rc; 325 *error = rc;
326 }
320 327
321 return rc == TOXAV_ERR_CALL_OK; 328 return rc == TOXAV_ERR_CALL_OK;
322} 329}
@@ -366,14 +373,16 @@ bool toxav_answer(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, ui
366 call->previous_self_capabilities |= audio_bit_rate > 0 ? msi_CapSAudio : 0; 373 call->previous_self_capabilities |= audio_bit_rate > 0 ? msi_CapSAudio : 0;
367 call->previous_self_capabilities |= video_bit_rate > 0 ? msi_CapSVideo : 0; 374 call->previous_self_capabilities |= video_bit_rate > 0 ? msi_CapSVideo : 0;
368 375
369 if (msi_answer(call->msi_call, call->previous_self_capabilities) != 0) 376 if (msi_answer(call->msi_call, call->previous_self_capabilities) != 0) {
370 rc = TOXAV_ERR_ANSWER_SYNC; 377 rc = TOXAV_ERR_ANSWER_SYNC;
378 }
371 379
372END: 380END:
373 pthread_mutex_unlock(av->mutex); 381 pthread_mutex_unlock(av->mutex);
374 382
375 if (error) 383 if (error) {
376 *error = rc; 384 *error = rc;
385 }
377 386
378 return rc == TOXAV_ERR_ANSWER_OK; 387 return rc == TOXAV_ERR_ANSWER_OK;
379} 388}
@@ -528,8 +537,9 @@ bool toxav_call_control(ToxAV *av, uint32_t friend_number, TOXAV_CALL_CONTROL co
528END: 537END:
529 pthread_mutex_unlock(av->mutex); 538 pthread_mutex_unlock(av->mutex);
530 539
531 if (error) 540 if (error) {
532 *error = rc; 541 *error = rc;
542 }
533 543
534 return rc == TOXAV_ERR_CALL_CONTROL_OK; 544 return rc == TOXAV_ERR_CALL_CONTROL_OK;
535} 545}
@@ -594,8 +604,9 @@ bool toxav_bit_rate_set(ToxAV *av, uint32_t friend_number, int32_t audio_bit_rat
594 rc = TOXAV_ERR_BIT_RATE_SET_SYNC; 604 rc = TOXAV_ERR_BIT_RATE_SET_SYNC;
595 goto END; 605 goto END;
596 } 606 }
597 } else 607 } else {
598 LOGGER_DEBUG(av->m->log, "Set new audio bit rate %d", audio_bit_rate); 608 LOGGER_DEBUG(av->m->log, "Set new audio bit rate %d", audio_bit_rate);
609 }
599 610
600 call->audio_bit_rate = audio_bit_rate; 611 call->audio_bit_rate = audio_bit_rate;
601 pthread_mutex_unlock(call->mutex); 612 pthread_mutex_unlock(call->mutex);
@@ -633,8 +644,9 @@ bool toxav_bit_rate_set(ToxAV *av, uint32_t friend_number, int32_t audio_bit_rat
633 rc = TOXAV_ERR_BIT_RATE_SET_SYNC; 644 rc = TOXAV_ERR_BIT_RATE_SET_SYNC;
634 goto END; 645 goto END;
635 } 646 }
636 } else 647 } else {
637 LOGGER_DEBUG(av->m->log, "Set new video bit rate %d", video_bit_rate); 648 LOGGER_DEBUG(av->m->log, "Set new video bit rate %d", video_bit_rate);
649 }
638 650
639 call->video_bit_rate = video_bit_rate; 651 call->video_bit_rate = video_bit_rate;
640 pthread_mutex_unlock(call->mutex); 652 pthread_mutex_unlock(call->mutex);
@@ -644,8 +656,9 @@ bool toxav_bit_rate_set(ToxAV *av, uint32_t friend_number, int32_t audio_bit_rat
644 pthread_mutex_unlock(av->mutex); 656 pthread_mutex_unlock(av->mutex);
645END: 657END:
646 658
647 if (error) 659 if (error) {
648 *error = rc; 660 *error = rc;
661 }
649 662
650 return rc == TOXAV_ERR_BIT_RATE_SET_OK; 663 return rc == TOXAV_ERR_BIT_RATE_SET_OK;
651} 664}
@@ -735,8 +748,9 @@ bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pc
735 748
736END: 749END:
737 750
738 if (error) 751 if (error) {
739 *error = rc; 752 *error = rc;
753 }
740 754
741 return rc == TOXAV_ERR_SEND_FRAME_OK; 755 return rc == TOXAV_ERR_SEND_FRAME_OK;
742} 756}
@@ -834,8 +848,9 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u
834 848
835END: 849END:
836 850
837 if (error) 851 if (error) {
838 *error = rc; 852 *error = rc;
853 }
839 854
840 return rc == TOXAV_ERR_SEND_FRAME_OK; 855 return rc == TOXAV_ERR_SEND_FRAME_OK;
841} 856}
@@ -874,8 +889,9 @@ void callback_bwc(BWController *bwc, uint32_t friend_number, float loss, void *u
874 889
875 LOGGER_DEBUG(call->av->m->log, "Reported loss of %f%%", loss * 100); 890 LOGGER_DEBUG(call->av->m->log, "Reported loss of %f%%", loss * 100);
876 891
877 if (loss < .01f) 892 if (loss < .01f) {
878 return; 893 return;
894 }
879 895
880 pthread_mutex_lock(call->av->mutex); 896 pthread_mutex_lock(call->av->mutex);
881 897
@@ -885,14 +901,15 @@ void callback_bwc(BWController *bwc, uint32_t friend_number, float loss, void *u
885 return; 901 return;
886 } 902 }
887 903
888 if (call->video_bit_rate) 904 if (call->video_bit_rate) {
889 (*call->av->bcb.first) (call->av, friend_number, call->audio_bit_rate, 905 (*call->av->bcb.first) (call->av, friend_number, call->audio_bit_rate,
890 call->video_bit_rate - (call->video_bit_rate * loss), 906 call->video_bit_rate - (call->video_bit_rate * loss),
891 call->av->bcb.second); 907 call->av->bcb.second);
892 else if (call->audio_bit_rate) 908 } else if (call->audio_bit_rate) {
893 (*call->av->bcb.first) (call->av, friend_number, 909 (*call->av->bcb.first) (call->av, friend_number,
894 call->audio_bit_rate - (call->audio_bit_rate * loss), 910 call->audio_bit_rate - (call->audio_bit_rate * loss),
895 0, call->av->bcb.second); 911 0, call->av->bcb.second);
912 }
896 913
897 pthread_mutex_unlock(call->av->mutex); 914 pthread_mutex_unlock(call->av->mutex);
898} 915}
@@ -912,10 +929,10 @@ int callback_invite(void *toxav_inst, MSICall *call)
912 call->av_call = av_call; 929 call->av_call = av_call;
913 av_call->msi_call = call; 930 av_call->msi_call = call;
914 931
915 if (toxav->ccb.first) 932 if (toxav->ccb.first) {
916 toxav->ccb.first(toxav, call->friend_number, call->peer_capabilities & msi_CapSAudio, 933 toxav->ccb.first(toxav, call->friend_number, call->peer_capabilities & msi_CapSAudio,
917 call->peer_capabilities & msi_CapSVideo, toxav->ccb.second); 934 call->peer_capabilities & msi_CapSVideo, toxav->ccb.second);
918 else { 935 } else {
919 /* No handler to capture the call request, send failure */ 936 /* No handler to capture the call request, send failure */
920 pthread_mutex_unlock(toxav->mutex); 937 pthread_mutex_unlock(toxav->mutex);
921 return -1; 938 return -1;
@@ -987,15 +1004,17 @@ int callback_capabilites(void *toxav_inst, MSICall *call)
987 ToxAV *toxav = toxav_inst; 1004 ToxAV *toxav = toxav_inst;
988 pthread_mutex_lock(toxav->mutex); 1005 pthread_mutex_lock(toxav->mutex);
989 1006
990 if (call->peer_capabilities & msi_CapSAudio) 1007 if (call->peer_capabilities & msi_CapSAudio) {
991 rtp_allow_receiving(((ToxAVCall *)call->av_call)->audio.first); 1008 rtp_allow_receiving(((ToxAVCall *)call->av_call)->audio.first);
992 else 1009 } else {
993 rtp_stop_receiving(((ToxAVCall *)call->av_call)->audio.first); 1010 rtp_stop_receiving(((ToxAVCall *)call->av_call)->audio.first);
1011 }
994 1012
995 if (call->peer_capabilities & msi_CapSVideo) 1013 if (call->peer_capabilities & msi_CapSVideo) {
996 rtp_allow_receiving(((ToxAVCall *)call->av_call)->video.first); 1014 rtp_allow_receiving(((ToxAVCall *)call->av_call)->video.first);
997 else 1015 } else {
998 rtp_stop_receiving(((ToxAVCall *)call->av_call)->video.first); 1016 rtp_stop_receiving(((ToxAVCall *)call->av_call)->video.first);
1017 }
999 1018
1000 invoke_call_state_callback(toxav, call->friend_number, call->peer_capabilities); 1019 invoke_call_state_callback(toxav, call->friend_number, call->peer_capabilities);
1001 1020
@@ -1017,10 +1036,11 @@ bool video_bit_rate_invalid(uint32_t bit_rate)
1017} 1036}
1018bool invoke_call_state_callback(ToxAV *av, uint32_t friend_number, uint32_t state) 1037bool invoke_call_state_callback(ToxAV *av, uint32_t friend_number, uint32_t state)
1019{ 1038{
1020 if (av->scb.first) 1039 if (av->scb.first) {
1021 av->scb.first(av, friend_number, state, av->scb.second); 1040 av->scb.first(av, friend_number, state, av->scb.second);
1022 else 1041 } else {
1023 return false; 1042 return false;
1043 }
1024 1044
1025 return true; 1045 return true;
1026} 1046}
@@ -1083,8 +1103,9 @@ ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, TOXAV_ERR_CALL *error)
1083 /* Set fields in between to null */ 1103 /* Set fields in between to null */
1084 uint32_t i = av->calls_tail + 1; 1104 uint32_t i = av->calls_tail + 1;
1085 1105
1086 for (; i < friend_number; i ++) 1106 for (; i < friend_number; i ++) {
1087 av->calls[i] = NULL; 1107 av->calls[i] = NULL;
1108 }
1088 1109
1089 call->prev = av->calls[av->calls_tail]; 1110 call->prev = av->calls[av->calls_tail];
1090 av->calls[av->calls_tail]->next = call; 1111 av->calls[av->calls_tail]->next = call;
@@ -1101,23 +1122,26 @@ ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, TOXAV_ERR_CALL *error)
1101 1122
1102END: 1123END:
1103 1124
1104 if (error) 1125 if (error) {
1105 *error = rc; 1126 *error = rc;
1127 }
1106 1128
1107 return call; 1129 return call;
1108} 1130}
1109ToxAVCall *call_get(ToxAV *av, uint32_t friend_number) 1131ToxAVCall *call_get(ToxAV *av, uint32_t friend_number)
1110{ 1132{
1111 /* Assumes mutex locked */ 1133 /* Assumes mutex locked */
1112 if (av->calls == NULL || av->calls_tail < friend_number) 1134 if (av->calls == NULL || av->calls_tail < friend_number) {
1113 return NULL; 1135 return NULL;
1136 }
1114 1137
1115 return av->calls[friend_number]; 1138 return av->calls[friend_number];
1116} 1139}
1117ToxAVCall *call_remove(ToxAVCall *call) 1140ToxAVCall *call_remove(ToxAVCall *call)
1118{ 1141{
1119 if (call == NULL) 1142 if (call == NULL) {
1120 return NULL; 1143 return NULL;
1144 }
1121 1145
1122 uint32_t friend_number = call->friend_number; 1146 uint32_t friend_number = call->friend_number;
1123 ToxAV *av = call->av; 1147 ToxAV *av = call->av;
@@ -1134,17 +1158,21 @@ ToxAVCall *call_remove(ToxAVCall *call)
1134 1158
1135 free(call); 1159 free(call);
1136 1160
1137 if (prev) 1161 if (prev) {
1138 prev->next = next; 1162 prev->next = next;
1139 else if (next) 1163 } else if (next) {
1140 av->calls_head = next->friend_number; 1164 av->calls_head = next->friend_number;
1141 else goto CLEAR; 1165 } else {
1166 goto CLEAR;
1167 }
1142 1168
1143 if (next) 1169 if (next) {
1144 next->prev = prev; 1170 next->prev = prev;
1145 else if (prev) 1171 } else if (prev) {
1146 av->calls_tail = prev->friend_number; 1172 av->calls_tail = prev->friend_number;
1147 else goto CLEAR; 1173 } else {
1174 goto CLEAR;
1175 }
1148 1176
1149 av->calls[friend_number] = NULL; 1177 av->calls[friend_number] = NULL;
1150 return next; 1178 return next;
@@ -1160,28 +1188,33 @@ bool call_prepare_transmission(ToxAVCall *call)
1160{ 1188{
1161 /* Assumes mutex locked */ 1189 /* Assumes mutex locked */
1162 1190
1163 if (call == NULL) 1191 if (call == NULL) {
1164 return false; 1192 return false;
1193 }
1165 1194
1166 ToxAV *av = call->av; 1195 ToxAV *av = call->av;
1167 1196
1168 if (!av->acb.first && !av->vcb.first) 1197 if (!av->acb.first && !av->vcb.first) {
1169 /* It makes no sense to have CSession without callbacks */ 1198 /* It makes no sense to have CSession without callbacks */
1170 return false; 1199 return false;
1200 }
1171 1201
1172 if (call->active) { 1202 if (call->active) {
1173 LOGGER_WARNING(av->m->log, "Call already active!\n"); 1203 LOGGER_WARNING(av->m->log, "Call already active!\n");
1174 return true; 1204 return true;
1175 } 1205 }
1176 1206
1177 if (create_recursive_mutex(call->mutex_audio) != 0) 1207 if (create_recursive_mutex(call->mutex_audio) != 0) {
1178 return false; 1208 return false;
1209 }
1179 1210
1180 if (create_recursive_mutex(call->mutex_video) != 0) 1211 if (create_recursive_mutex(call->mutex_video) != 0) {
1181 goto FAILURE_3; 1212 goto FAILURE_3;
1213 }
1182 1214
1183 if (create_recursive_mutex(call->mutex) != 0) 1215 if (create_recursive_mutex(call->mutex) != 0) {
1184 goto FAILURE_2; 1216 goto FAILURE_2;
1217 }
1185 1218
1186 /* Prepare bwc */ 1219 /* Prepare bwc */
1187 call->bwc = bwc_new(av->m, call->friend_number, callback_bwc, call); 1220 call->bwc = bwc_new(av->m, call->friend_number, callback_bwc, call);
@@ -1241,8 +1274,9 @@ FAILURE_3:
1241} 1274}
1242void call_kill_transmission(ToxAVCall *call) 1275void call_kill_transmission(ToxAVCall *call)
1243{ 1276{
1244 if (call == NULL || call->active == 0) 1277 if (call == NULL || call->active == 0) {
1245 return; 1278 return;
1279 }
1246 1280
1247 call->active = 0; 1281 call->active = 0;
1248 1282