summaryrefslogtreecommitdiff
path: root/toxav
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-01-28 21:30:39 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-01-30 23:35:50 +0000
commit92ffad1a72bc8c422426d52ac408bd71242dd047 (patch)
treef592f353068dd2043525dd2cc04d6124a4ed4bc4 /toxav
parent623e9ac331df7323660e21c8a2226523a5ee713b (diff)
Use nullptr as NULL pointer constant instead of NULL or 0.
This changes only code, no string literals or comments.
Diffstat (limited to 'toxav')
-rw-r--r--toxav/BUILD.bazel1
-rw-r--r--toxav/audio.c30
-rw-r--r--toxav/bwcontroller.c2
-rw-r--r--toxav/groupav.c34
-rw-r--r--toxav/msi.c50
-rw-r--r--toxav/ring_buffer.c10
-rw-r--r--toxav/rtp.c16
-rw-r--r--toxav/toxav.c98
-rw-r--r--toxav/video.c12
9 files changed, 128 insertions, 125 deletions
diff --git a/toxav/BUILD.bazel b/toxav/BUILD.bazel
index 38bdaeba..e9649c36 100644
--- a/toxav/BUILD.bazel
+++ b/toxav/BUILD.bazel
@@ -15,6 +15,7 @@ cc_library(
15 name = "ring_buffer", 15 name = "ring_buffer",
16 srcs = ["ring_buffer.c"], 16 srcs = ["ring_buffer.c"],
17 hdrs = ["ring_buffer.h"], 17 hdrs = ["ring_buffer.h"],
18 deps = ["//c-toxcore/toxcore:ccompat"],
18) 19)
19 20
20cc_library( 21cc_library(
diff --git a/toxav/audio.c b/toxav/audio.c
index f2453e8e..b97560fd 100644
--- a/toxav/audio.c
+++ b/toxav/audio.c
@@ -47,13 +47,13 @@ ACSession *ac_new(Logger *log, ToxAV *av, uint32_t friend_number, toxav_audio_re
47 47
48 if (!ac) { 48 if (!ac) {
49 LOGGER_WARNING(log, "Allocation failed! Application might misbehave!"); 49 LOGGER_WARNING(log, "Allocation failed! Application might misbehave!");
50 return NULL; 50 return nullptr;
51 } 51 }
52 52
53 if (create_recursive_mutex(ac->queue_mutex) != 0) { 53 if (create_recursive_mutex(ac->queue_mutex) != 0) {
54 LOGGER_WARNING(log, "Failed to create recursive mutex!"); 54 LOGGER_WARNING(log, "Failed to create recursive mutex!");
55 free(ac); 55 free(ac);
56 return NULL; 56 return nullptr;
57 } 57 }
58 58
59 int status; 59 int status;
@@ -75,7 +75,7 @@ ACSession *ac_new(Logger *log, ToxAV *av, uint32_t friend_number, toxav_audio_re
75 /* Initialize encoders with default values */ 75 /* Initialize encoders with default values */
76 ac->encoder = create_audio_encoder(log, AUDIO_START_BITRATE, AUDIO_START_SAMPLE_RATE, AUDIO_START_CHANNEL_COUNT); 76 ac->encoder = create_audio_encoder(log, AUDIO_START_BITRATE, AUDIO_START_SAMPLE_RATE, AUDIO_START_CHANNEL_COUNT);
77 77
78 if (ac->encoder == NULL) { 78 if (ac->encoder == nullptr) {
79 goto DECODER_CLEANUP; 79 goto DECODER_CLEANUP;
80 } 80 }
81 81
@@ -106,7 +106,7 @@ DECODER_CLEANUP:
106BASE_CLEANUP: 106BASE_CLEANUP:
107 pthread_mutex_destroy(ac->queue_mutex); 107 pthread_mutex_destroy(ac->queue_mutex);
108 free(ac); 108 free(ac);
109 return NULL; 109 return nullptr;
110} 110}
111 111
112void ac_kill(ACSession *ac) 112void ac_kill(ACSession *ac)
@@ -147,7 +147,7 @@ void ac_iterate(ACSession *ac)
147 if (rc == 2) { 147 if (rc == 2) {
148 LOGGER_DEBUG(ac->log, "OPUS correction"); 148 LOGGER_DEBUG(ac->log, "OPUS correction");
149 int fs = (ac->lp_sampling_rate * ac->lp_frame_duration) / 1000; 149 int fs = (ac->lp_sampling_rate * ac->lp_frame_duration) / 1000;
150 rc = opus_decode(ac->decoder, NULL, 0, temp_audio_buffer, fs, 1); 150 rc = opus_decode(ac->decoder, nullptr, 0, temp_audio_buffer, fs, 1);
151 } else { 151 } else {
152 /* Get values from packet and decode. */ 152 /* Get values from packet and decode. */
153 /* NOTE: This didn't work very well */ 153 /* NOTE: This didn't work very well */
@@ -275,14 +275,14 @@ static struct JitterBuffer *jbuf_new(uint32_t capacity)
275 struct JitterBuffer *q = (struct JitterBuffer *)calloc(sizeof(struct JitterBuffer), 1); 275 struct JitterBuffer *q = (struct JitterBuffer *)calloc(sizeof(struct JitterBuffer), 1);
276 276
277 if (!q) { 277 if (!q) {
278 return NULL; 278 return nullptr;
279 } 279 }
280 280
281 q->queue = (struct RTPMessage **)calloc(sizeof(struct RTPMessage *), size); 281 q->queue = (struct RTPMessage **)calloc(sizeof(struct RTPMessage *), size);
282 282
283 if (!q->queue) { 283 if (!q->queue) {
284 free(q); 284 free(q);
285 return NULL; 285 return nullptr;
286 } 286 }
287 287
288 q->size = size; 288 q->size = size;
@@ -294,7 +294,7 @@ static void jbuf_clear(struct JitterBuffer *q)
294 for (; q->bottom != q->top; ++q->bottom) { 294 for (; q->bottom != q->top; ++q->bottom) {
295 if (q->queue[q->bottom % q->size]) { 295 if (q->queue[q->bottom % q->size]) {
296 free(q->queue[q->bottom % q->size]); 296 free(q->queue[q->bottom % q->size]);
297 q->queue[q->bottom % q->size] = NULL; 297 q->queue[q->bottom % q->size] = nullptr;
298 } 298 }
299 } 299 }
300} 300}
@@ -340,14 +340,14 @@ static struct RTPMessage *jbuf_read(struct JitterBuffer *q, int32_t *success)
340{ 340{
341 if (q->top == q->bottom) { 341 if (q->top == q->bottom) {
342 *success = 0; 342 *success = 0;
343 return NULL; 343 return nullptr;
344 } 344 }
345 345
346 unsigned int num = q->bottom % q->size; 346 unsigned int num = q->bottom % q->size;
347 347
348 if (q->queue[num]) { 348 if (q->queue[num]) {
349 struct RTPMessage *ret = q->queue[num]; 349 struct RTPMessage *ret = q->queue[num];
350 q->queue[num] = NULL; 350 q->queue[num] = nullptr;
351 ++q->bottom; 351 ++q->bottom;
352 *success = 1; 352 *success = 1;
353 return ret; 353 return ret;
@@ -356,11 +356,11 @@ static struct RTPMessage *jbuf_read(struct JitterBuffer *q, int32_t *success)
356 if ((uint32_t)(q->top - q->bottom) > q->capacity) { 356 if ((uint32_t)(q->top - q->bottom) > q->capacity) {
357 ++q->bottom; 357 ++q->bottom;
358 *success = 2; 358 *success = 2;
359 return NULL; 359 return nullptr;
360 } 360 }
361 361
362 *success = 0; 362 *success = 0;
363 return NULL; 363 return nullptr;
364} 364}
365OpusEncoder *create_audio_encoder(Logger *log, int32_t bit_rate, int32_t sampling_rate, int32_t channel_count) 365OpusEncoder *create_audio_encoder(Logger *log, int32_t bit_rate, int32_t sampling_rate, int32_t channel_count)
366{ 366{
@@ -374,7 +374,7 @@ OpusEncoder *create_audio_encoder(Logger *log, int32_t bit_rate, int32_t samplin
374 374
375 if (status != OPUS_OK) { 375 if (status != OPUS_OK) {
376 LOGGER_ERROR(log, "Error while starting audio encoder: %s", opus_strerror(status)); 376 LOGGER_ERROR(log, "Error while starting audio encoder: %s", opus_strerror(status));
377 return NULL; 377 return nullptr;
378 } 378 }
379 379
380 380
@@ -452,7 +452,7 @@ OpusEncoder *create_audio_encoder(Logger *log, int32_t bit_rate, int32_t samplin
452 452
453FAILURE: 453FAILURE:
454 opus_encoder_destroy(rc); 454 opus_encoder_destroy(rc);
455 return NULL; 455 return nullptr;
456} 456}
457 457
458bool reconfigure_audio_encoder(Logger *log, OpusEncoder **e, int32_t new_br, int32_t new_sr, uint8_t new_ch, 458bool reconfigure_audio_encoder(Logger *log, OpusEncoder **e, int32_t new_br, int32_t new_sr, uint8_t new_ch,
@@ -462,7 +462,7 @@ bool reconfigure_audio_encoder(Logger *log, OpusEncoder **e, int32_t new_br, int
462 if (*old_sr != new_sr || *old_ch != new_ch) { 462 if (*old_sr != new_sr || *old_ch != new_ch) {
463 OpusEncoder *new_encoder = create_audio_encoder(log, new_br, new_sr, new_ch); 463 OpusEncoder *new_encoder = create_audio_encoder(log, new_br, new_sr, new_ch);
464 464
465 if (new_encoder == NULL) { 465 if (new_encoder == nullptr) {
466 return false; 466 return false;
467 } 467 }
468 468
diff --git a/toxav/bwcontroller.c b/toxav/bwcontroller.c
index eeeab129..9d1ad9ce 100644
--- a/toxav/bwcontroller.c
+++ b/toxav/bwcontroller.c
@@ -97,7 +97,7 @@ void bwc_kill(BWController *bwc)
97 return; 97 return;
98 } 98 }
99 99
100 m_callback_rtp_packet(bwc->m, bwc->friend_number, BWC_PACKET_ID, NULL, NULL); 100 m_callback_rtp_packet(bwc->m, bwc->friend_number, BWC_PACKET_ID, nullptr, nullptr);
101 101
102 rb_kill(bwc->rcvpkt.rb); 102 rb_kill(bwc->rcvpkt.rb);
103 free(bwc); 103 free(bwc);
diff --git a/toxav/groupav.c b/toxav/groupav.c
index 418a42aa..c19c1b3c 100644
--- a/toxav/groupav.c
+++ b/toxav/groupav.c
@@ -55,12 +55,12 @@ static Group_JitterBuffer *create_queue(unsigned int capacity)
55 Group_JitterBuffer *q; 55 Group_JitterBuffer *q;
56 56
57 if (!(q = (Group_JitterBuffer *)calloc(sizeof(Group_JitterBuffer), 1))) { 57 if (!(q = (Group_JitterBuffer *)calloc(sizeof(Group_JitterBuffer), 1))) {
58 return NULL; 58 return nullptr;
59 } 59 }
60 60
61 if (!(q->queue = (Group_Audio_Packet **)calloc(sizeof(Group_Audio_Packet *), size))) { 61 if (!(q->queue = (Group_Audio_Packet **)calloc(sizeof(Group_Audio_Packet *), size))) {
62 free(q); 62 free(q);
63 return NULL; 63 return nullptr;
64 } 64 }
65 65
66 q->size = size; 66 q->size = size;
@@ -73,7 +73,7 @@ static void clear_queue(Group_JitterBuffer *q)
73 for (; q->bottom != q->top; ++q->bottom) { 73 for (; q->bottom != q->top; ++q->bottom) {
74 if (q->queue[q->bottom % q->size]) { 74 if (q->queue[q->bottom % q->size]) {
75 free(q->queue[q->bottom % q->size]); 75 free(q->queue[q->bottom % q->size]);
76 q->queue[q->bottom % q->size] = NULL; 76 q->queue[q->bottom % q->size] = nullptr;
77 } 77 }
78 } 78 }
79} 79}
@@ -132,14 +132,14 @@ static Group_Audio_Packet *dequeue(Group_JitterBuffer *q, int *success)
132{ 132{
133 if (q->top == q->bottom) { 133 if (q->top == q->bottom) {
134 *success = 0; 134 *success = 0;
135 return NULL; 135 return nullptr;
136 } 136 }
137 137
138 unsigned int num = q->bottom % q->size; 138 unsigned int num = q->bottom % q->size;
139 139
140 if (q->queue[num]) { 140 if (q->queue[num]) {
141 Group_Audio_Packet *ret = q->queue[num]; 141 Group_Audio_Packet *ret = q->queue[num];
142 q->queue[num] = NULL; 142 q->queue[num] = nullptr;
143 ++q->bottom; 143 ++q->bottom;
144 *success = 1; 144 *success = 1;
145 return ret; 145 return ret;
@@ -148,11 +148,11 @@ static Group_Audio_Packet *dequeue(Group_JitterBuffer *q, int *success)
148 if ((uint32_t)(q->top - q->bottom) > q->capacity) { 148 if ((uint32_t)(q->top - q->bottom) > q->capacity) {
149 ++q->bottom; 149 ++q->bottom;
150 *success = 2; 150 *success = 2;
151 return NULL; 151 return nullptr;
152 } 152 }
153 153
154 *success = 0; 154 *success = 0;
155 return NULL; 155 return nullptr;
156} 156}
157 157
158typedef struct { 158typedef struct {
@@ -190,7 +190,7 @@ static int recreate_encoder(Group_AV *group_av)
190{ 190{
191 if (group_av->audio_encoder) { 191 if (group_av->audio_encoder) {
192 opus_encoder_destroy(group_av->audio_encoder); 192 opus_encoder_destroy(group_av->audio_encoder);
193 group_av->audio_encoder = NULL; 193 group_av->audio_encoder = nullptr;
194 } 194 }
195 195
196 int rc = OPUS_OK; 196 int rc = OPUS_OK;
@@ -199,7 +199,7 @@ static int recreate_encoder(Group_AV *group_av)
199 199
200 if (rc != OPUS_OK) { 200 if (rc != OPUS_OK) {
201 LOGGER_ERROR(group_av->log, "Error while starting audio encoder: %s", opus_strerror(rc)); 201 LOGGER_ERROR(group_av->log, "Error while starting audio encoder: %s", opus_strerror(rc));
202 group_av->audio_encoder = NULL; 202 group_av->audio_encoder = nullptr;
203 return -1; 203 return -1;
204 } 204 }
205 205
@@ -208,7 +208,7 @@ static int recreate_encoder(Group_AV *group_av)
208 if (rc != OPUS_OK) { 208 if (rc != OPUS_OK) {
209 LOGGER_ERROR(group_av->log, "Error while setting encoder ctl: %s", opus_strerror(rc)); 209 LOGGER_ERROR(group_av->log, "Error while setting encoder ctl: %s", opus_strerror(rc));
210 opus_encoder_destroy(group_av->audio_encoder); 210 opus_encoder_destroy(group_av->audio_encoder);
211 group_av->audio_encoder = NULL; 211 group_av->audio_encoder = nullptr;
212 return -1; 212 return -1;
213 } 213 }
214 214
@@ -217,7 +217,7 @@ static int recreate_encoder(Group_AV *group_av)
217 if (rc != OPUS_OK) { 217 if (rc != OPUS_OK) {
218 LOGGER_ERROR(group_av->log, "Error while setting encoder ctl: %s", opus_strerror(rc)); 218 LOGGER_ERROR(group_av->log, "Error while setting encoder ctl: %s", opus_strerror(rc));
219 opus_encoder_destroy(group_av->audio_encoder); 219 opus_encoder_destroy(group_av->audio_encoder);
220 group_av->audio_encoder = NULL; 220 group_av->audio_encoder = nullptr;
221 return -1; 221 return -1;
222 } 222 }
223 223
@@ -229,13 +229,13 @@ static Group_AV *new_group_av(Logger *log, Group_Chats *g_c, void (*audio_callba
229 unsigned int, uint8_t, unsigned int, void *), void *userdata) 229 unsigned int, uint8_t, unsigned int, void *), void *userdata)
230{ 230{
231 if (!g_c) { 231 if (!g_c) {
232 return NULL; 232 return nullptr;
233 } 233 }
234 234
235 Group_AV *group_av = (Group_AV *)calloc(1, sizeof(Group_AV)); 235 Group_AV *group_av = (Group_AV *)calloc(1, sizeof(Group_AV));
236 236
237 if (!group_av) { 237 if (!group_av) {
238 return NULL; 238 return nullptr;
239 } 239 }
240 240
241 group_av->log = log; 241 group_av->log = log;
@@ -296,7 +296,7 @@ static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, int g
296 return -1; 296 return -1;
297 } 297 }
298 298
299 int16_t *out_audio = NULL; 299 int16_t *out_audio = nullptr;
300 int out_audio_samples = 0; 300 int out_audio_samples = 0;
301 301
302 unsigned int sample_rate = 48000; 302 unsigned int sample_rate = 48000;
@@ -317,7 +317,7 @@ static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, int g
317 if (channels != peer_av->decoder_channels) { 317 if (channels != peer_av->decoder_channels) {
318 if (peer_av->audio_decoder) { 318 if (peer_av->audio_decoder) {
319 opus_decoder_destroy(peer_av->audio_decoder); 319 opus_decoder_destroy(peer_av->audio_decoder);
320 peer_av->audio_decoder = NULL; 320 peer_av->audio_decoder = nullptr;
321 } 321 }
322 322
323 int rc; 323 int rc;
@@ -366,7 +366,7 @@ static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, int g
366 return -1; 366 return -1;
367 } 367 }
368 368
369 out_audio_samples = opus_decode(peer_av->audio_decoder, NULL, 0, out_audio, peer_av->last_packet_samples, 1); 369 out_audio_samples = opus_decode(peer_av->audio_decoder, nullptr, 0, out_audio, peer_av->last_packet_samples, 1);
370 370
371 if (out_audio_samples <= 0) { 371 if (out_audio_samples <= 0) {
372 free(out_audio); 372 free(out_audio);
@@ -436,7 +436,7 @@ static int groupchat_enable_av(Logger *log, Group_Chats *g_c, int groupnumber, v
436 436
437 Group_AV *group_av = new_group_av(log, g_c, audio_callback, userdata); 437 Group_AV *group_av = new_group_av(log, g_c, audio_callback, userdata);
438 438
439 if (group_av == NULL) { 439 if (group_av == nullptr) {
440 return -1; 440 return -1;
441 } 441 }
442 442
diff --git a/toxav/msi.c b/toxav/msi.c
index 882dad04..94b7b537 100644
--- a/toxav/msi.c
+++ b/toxav/msi.c
@@ -104,21 +104,21 @@ void msi_register_callback(MSISession *session, msi_action_cb *callback, MSICall
104} 104}
105MSISession *msi_new(Messenger *m) 105MSISession *msi_new(Messenger *m)
106{ 106{
107 if (m == NULL) { 107 if (m == nullptr) {
108 return NULL; 108 return nullptr;
109 } 109 }
110 110
111 MSISession *retu = (MSISession *)calloc(sizeof(MSISession), 1); 111 MSISession *retu = (MSISession *)calloc(sizeof(MSISession), 1);
112 112
113 if (retu == NULL) { 113 if (retu == nullptr) {
114 LOGGER_ERROR(m->log, "Allocation failed! Program might misbehave!"); 114 LOGGER_ERROR(m->log, "Allocation failed! Program might misbehave!");
115 return NULL; 115 return nullptr;
116 } 116 }
117 117
118 if (create_recursive_mutex(retu->mutex) != 0) { 118 if (create_recursive_mutex(retu->mutex) != 0) {
119 LOGGER_ERROR(m->log, "Failed to init mutex! Program might misbehave"); 119 LOGGER_ERROR(m->log, "Failed to init mutex! Program might misbehave");
120 free(retu); 120 free(retu);
121 return NULL; 121 return nullptr;
122 } 122 }
123 123
124 retu->messenger = m; 124 retu->messenger = m;
@@ -133,12 +133,12 @@ MSISession *msi_new(Messenger *m)
133} 133}
134int msi_kill(MSISession *session, Logger *log) 134int msi_kill(MSISession *session, Logger *log)
135{ 135{
136 if (session == NULL) { 136 if (session == nullptr) {
137 LOGGER_ERROR(log, "Tried to terminate non-existing session"); 137 LOGGER_ERROR(log, "Tried to terminate non-existing session");
138 return -1; 138 return -1;
139 } 139 }
140 140
141 m_callback_msi_packet((struct Messenger *) session->messenger, NULL, NULL); 141 m_callback_msi_packet((struct Messenger *) session->messenger, nullptr, nullptr);
142 142
143 if (pthread_mutex_trylock(session->mutex) != 0) { 143 if (pthread_mutex_trylock(session->mutex) != 0) {
144 LOGGER_ERROR(session->messenger->log, "Failed to acquire lock on msi mutex"); 144 LOGGER_ERROR(session->messenger->log, "Failed to acquire lock on msi mutex");
@@ -179,7 +179,7 @@ int msi_invite(MSISession *session, MSICall **call, uint32_t friend_number, uint
179 return -1; 179 return -1;
180 } 180 }
181 181
182 if (get_call(session, friend_number) != NULL) { 182 if (get_call(session, friend_number) != nullptr) {
183 LOGGER_ERROR(session->messenger->log, "Already in a call"); 183 LOGGER_ERROR(session->messenger->log, "Already in a call");
184 pthread_mutex_unlock(session->mutex); 184 pthread_mutex_unlock(session->mutex);
185 return -1; 185 return -1;
@@ -187,7 +187,7 @@ int msi_invite(MSISession *session, MSICall **call, uint32_t friend_number, uint
187 187
188 (*call) = new_call(session, friend_number); 188 (*call) = new_call(session, friend_number);
189 189
190 if (*call == NULL) { 190 if (*call == nullptr) {
191 pthread_mutex_unlock(session->mutex); 191 pthread_mutex_unlock(session->mutex);
192 return -1; 192 return -1;
193 } 193 }
@@ -506,8 +506,8 @@ static MSICall *get_call(MSISession *session, uint32_t friend_number)
506{ 506{
507 assert(session); 507 assert(session);
508 508
509 if (session->calls == NULL || session->calls_tail < friend_number) { 509 if (session->calls == nullptr || session->calls_tail < friend_number) {
510 return NULL; 510 return nullptr;
511 } 511 }
512 512
513 return session->calls[friend_number]; 513 return session->calls[friend_number];
@@ -518,28 +518,28 @@ MSICall *new_call(MSISession *session, uint32_t friend_number)
518 518
519 MSICall *rc = (MSICall *)calloc(sizeof(MSICall), 1); 519 MSICall *rc = (MSICall *)calloc(sizeof(MSICall), 1);
520 520
521 if (rc == NULL) { 521 if (rc == nullptr) {
522 return NULL; 522 return nullptr;
523 } 523 }
524 524
525 rc->session = session; 525 rc->session = session;
526 rc->friend_number = friend_number; 526 rc->friend_number = friend_number;
527 527
528 if (session->calls == NULL) { /* Creating */ 528 if (session->calls == nullptr) { /* Creating */
529 session->calls = (MSICall **)calloc(sizeof(MSICall *), friend_number + 1); 529 session->calls = (MSICall **)calloc(sizeof(MSICall *), friend_number + 1);
530 530
531 if (session->calls == NULL) { 531 if (session->calls == nullptr) {
532 free(rc); 532 free(rc);
533 return NULL; 533 return nullptr;
534 } 534 }
535 535
536 session->calls_tail = session->calls_head = friend_number; 536 session->calls_tail = session->calls_head = friend_number;
537 } else if (session->calls_tail < friend_number) { /* Appending */ 537 } else if (session->calls_tail < friend_number) { /* Appending */
538 MSICall **tmp = (MSICall **)realloc(session->calls, sizeof(MSICall *) * (friend_number + 1)); 538 MSICall **tmp = (MSICall **)realloc(session->calls, sizeof(MSICall *) * (friend_number + 1));
539 539
540 if (tmp == NULL) { 540 if (tmp == nullptr) {
541 free(rc); 541 free(rc);
542 return NULL; 542 return nullptr;
543 } 543 }
544 544
545 session->calls = tmp; 545 session->calls = tmp;
@@ -548,7 +548,7 @@ MSICall *new_call(MSISession *session, uint32_t friend_number)
548 uint32_t i = session->calls_tail + 1; 548 uint32_t i = session->calls_tail + 1;
549 549
550 for (; i < friend_number; i ++) { 550 for (; i < friend_number; i ++) {
551 session->calls[i] = NULL; 551 session->calls[i] = nullptr;
552 } 552 }
553 553
554 rc->prev = session->calls[session->calls_tail]; 554 rc->prev = session->calls[session->calls_tail];
@@ -567,7 +567,7 @@ MSICall *new_call(MSISession *session, uint32_t friend_number)
567void kill_call(MSICall *call) 567void kill_call(MSICall *call)
568{ 568{
569 /* Assume that session mutex is locked */ 569 /* Assume that session mutex is locked */
570 if (call == NULL) { 570 if (call == nullptr) {
571 return; 571 return;
572 } 572 }
573 573
@@ -594,7 +594,7 @@ void kill_call(MSICall *call)
594 goto CLEAR_CONTAINER; 594 goto CLEAR_CONTAINER;
595 } 595 }
596 596
597 session->calls[call->friend_number] = NULL; 597 session->calls[call->friend_number] = nullptr;
598 free(call); 598 free(call);
599 return; 599 return;
600 600
@@ -602,7 +602,7 @@ CLEAR_CONTAINER:
602 session->calls_head = session->calls_tail = 0; 602 session->calls_head = session->calls_tail = 0;
603 free(session->calls); 603 free(session->calls);
604 free(call); 604 free(call);
605 session->calls = NULL; 605 session->calls = nullptr;
606} 606}
607void on_peer_status(Messenger *m, uint32_t friend_number, uint8_t status, void *data) 607void on_peer_status(Messenger *m, uint32_t friend_number, uint8_t status, void *data)
608{ 608{
@@ -616,7 +616,7 @@ void on_peer_status(Messenger *m, uint32_t friend_number, uint8_t status, void *
616 pthread_mutex_lock(session->mutex); 616 pthread_mutex_lock(session->mutex);
617 MSICall *call = get_call(session, friend_number); 617 MSICall *call = get_call(session, friend_number);
618 618
619 if (call == NULL) { 619 if (call == nullptr) {
620 pthread_mutex_unlock(session->mutex); 620 pthread_mutex_unlock(session->mutex);
621 return; 621 return;
622 } 622 }
@@ -810,7 +810,7 @@ void handle_msi_packet(Messenger *m, uint32_t friend_number, const uint8_t *data
810 pthread_mutex_lock(session->mutex); 810 pthread_mutex_lock(session->mutex);
811 MSICall *call = get_call(session, friend_number); 811 MSICall *call = get_call(session, friend_number);
812 812
813 if (call == NULL) { 813 if (call == nullptr) {
814 if (msg.request.value != requ_init) { 814 if (msg.request.value != requ_init) {
815 send_error(m, friend_number, msi_EStrayMessage); 815 send_error(m, friend_number, msi_EStrayMessage);
816 pthread_mutex_unlock(session->mutex); 816 pthread_mutex_unlock(session->mutex);
@@ -819,7 +819,7 @@ void handle_msi_packet(Messenger *m, uint32_t friend_number, const uint8_t *data
819 819
820 call = new_call(session, friend_number); 820 call = new_call(session, friend_number);
821 821
822 if (call == NULL) { 822 if (call == nullptr) {
823 send_error(m, friend_number, msi_ESystem); 823 send_error(m, friend_number, msi_ESystem);
824 pthread_mutex_unlock(session->mutex); 824 pthread_mutex_unlock(session->mutex);
825 return; 825 return;
diff --git a/toxav/ring_buffer.c b/toxav/ring_buffer.c
index c60c21f2..d3f013c6 100644
--- a/toxav/ring_buffer.c
+++ b/toxav/ring_buffer.c
@@ -21,6 +21,8 @@
21 */ 21 */
22#include "ring_buffer.h" 22#include "ring_buffer.h"
23 23
24#include "../toxcore/ccompat.h"
25
24#include <stdlib.h> 26#include <stdlib.h>
25 27
26struct RingBuffer { 28struct RingBuffer {
@@ -46,7 +48,7 @@ bool rb_empty(const RingBuffer *b)
46 */ 48 */
47void *rb_write(RingBuffer *b, void *p) 49void *rb_write(RingBuffer *b, void *p)
48{ 50{
49 void *rc = NULL; 51 void *rc = nullptr;
50 52
51 if ((b->end + 1) % b->size == b->start) { /* full */ 53 if ((b->end + 1) % b->size == b->start) { /* full */
52 rc = b->data[b->start]; 54 rc = b->data[b->start];
@@ -65,7 +67,7 @@ void *rb_write(RingBuffer *b, void *p)
65bool rb_read(RingBuffer *b, void **p) 67bool rb_read(RingBuffer *b, void **p)
66{ 68{
67 if (b->end == b->start) { /* Empty */ 69 if (b->end == b->start) { /* Empty */
68 *p = NULL; 70 *p = nullptr;
69 return false; 71 return false;
70 } 72 }
71 73
@@ -79,14 +81,14 @@ RingBuffer *rb_new(int size)
79 RingBuffer *buf = (RingBuffer *)calloc(sizeof(RingBuffer), 1); 81 RingBuffer *buf = (RingBuffer *)calloc(sizeof(RingBuffer), 1);
80 82
81 if (!buf) { 83 if (!buf) {
82 return NULL; 84 return nullptr;
83 } 85 }
84 86
85 buf->size = size + 1; /* include empty elem */ 87 buf->size = size + 1; /* include empty elem */
86 88
87 if (!(buf->data = (void **)calloc(buf->size, sizeof(void *)))) { 89 if (!(buf->data = (void **)calloc(buf->size, sizeof(void *)))) {
88 free(buf); 90 free(buf);
89 return NULL; 91 return nullptr;
90 } 92 }
91 93
92 return buf; 94 return buf;
diff --git a/toxav/rtp.c b/toxav/rtp.c
index 1e07516c..01d4258a 100644
--- a/toxav/rtp.c
+++ b/toxav/rtp.c
@@ -49,7 +49,7 @@ RTPSession *rtp_new(int payload_type, Messenger *m, uint32_t friendnumber,
49 49
50 if (!retu) { 50 if (!retu) {
51 LOGGER_WARNING(m->log, "Alloc failed! Program might misbehave!"); 51 LOGGER_WARNING(m->log, "Alloc failed! Program might misbehave!");
52 return NULL; 52 return nullptr;
53 } 53 }
54 54
55 retu->ssrc = random_u32(); 55 retu->ssrc = random_u32();
@@ -67,7 +67,7 @@ RTPSession *rtp_new(int payload_type, Messenger *m, uint32_t friendnumber,
67 if (-1 == rtp_allow_receiving(retu)) { 67 if (-1 == rtp_allow_receiving(retu)) {
68 LOGGER_WARNING(m->log, "Failed to start rtp receiving mode"); 68 LOGGER_WARNING(m->log, "Failed to start rtp receiving mode");
69 free(retu); 69 free(retu);
70 return NULL; 70 return nullptr;
71 } 71 }
72 72
73 return retu; 73 return retu;
@@ -85,7 +85,7 @@ void rtp_kill(RTPSession *session)
85} 85}
86int rtp_allow_receiving(RTPSession *session) 86int rtp_allow_receiving(RTPSession *session)
87{ 87{
88 if (session == NULL) { 88 if (session == nullptr) {
89 return -1; 89 return -1;
90 } 90 }
91 91
@@ -100,11 +100,11 @@ int rtp_allow_receiving(RTPSession *session)
100} 100}
101int rtp_stop_receiving(RTPSession *session) 101int rtp_stop_receiving(RTPSession *session)
102{ 102{
103 if (session == NULL) { 103 if (session == nullptr) {
104 return -1; 104 return -1;
105 } 105 }
106 106
107 m_callback_rtp_packet(session->m, session->friend_number, session->payload_type, NULL, NULL); 107 m_callback_rtp_packet(session->m, session->friend_number, session->payload_type, nullptr, nullptr);
108 108
109 LOGGER_DEBUG(session->m->log, "Stopped receiving on session: %p", session); 109 LOGGER_DEBUG(session->m->log, "Stopped receiving on session: %p", session);
110 return 0; 110 return 0;
@@ -286,7 +286,7 @@ int handle_rtp_packet(Messenger *m, uint32_t friendnumber, const uint8_t *data,
286 free(session->mp); 286 free(session->mp);
287 } 287 }
288 288
289 session->mp = NULL; 289 session->mp = nullptr;
290 } 290 }
291 291
292 /* The message came in the allowed time; 292 /* The message came in the allowed time;
@@ -341,7 +341,7 @@ int handle_rtp_packet(Messenger *m, uint32_t friendnumber, const uint8_t *data,
341 free(session->mp); 341 free(session->mp);
342 } 342 }
343 343
344 session->mp = NULL; 344 session->mp = nullptr;
345 } 345 }
346 } else { 346 } else {
347 /* Second case */ 347 /* Second case */
@@ -368,7 +368,7 @@ int handle_rtp_packet(Messenger *m, uint32_t friendnumber, const uint8_t *data,
368 free(session->mp); 368 free(session->mp);
369 } 369 }
370 370
371 session->mp = NULL; 371 session->mp = nullptr;
372 goto NEW_MULTIPARTED; 372 goto NEW_MULTIPARTED;
373 } 373 }
374 } else { 374 } else {
diff --git a/toxav/toxav.c b/toxav/toxav.c
index c021747a..c48fc192 100644
--- a/toxav/toxav.c
+++ b/toxav/toxav.c
@@ -110,10 +110,10 @@ void call_kill_transmission(ToxAVCall *call);
110ToxAV *toxav_new(Tox *tox, TOXAV_ERR_NEW *error) 110ToxAV *toxav_new(Tox *tox, TOXAV_ERR_NEW *error)
111{ 111{
112 TOXAV_ERR_NEW rc = TOXAV_ERR_NEW_OK; 112 TOXAV_ERR_NEW rc = TOXAV_ERR_NEW_OK;
113 ToxAV *av = NULL; 113 ToxAV *av = nullptr;
114 Messenger *m = (Messenger *)tox; 114 Messenger *m = (Messenger *)tox;
115 115
116 if (tox == NULL) { 116 if (tox == nullptr) {
117 rc = TOXAV_ERR_NEW_NULL; 117 rc = TOXAV_ERR_NEW_NULL;
118 goto END; 118 goto END;
119 } 119 }
@@ -125,7 +125,7 @@ ToxAV *toxav_new(Tox *tox, TOXAV_ERR_NEW *error)
125 125
126 av = (ToxAV *)calloc(sizeof(ToxAV), 1); 126 av = (ToxAV *)calloc(sizeof(ToxAV), 1);
127 127
128 if (av == NULL) { 128 if (av == nullptr) {
129 LOGGER_WARNING(m->log, "Allocation failed!"); 129 LOGGER_WARNING(m->log, "Allocation failed!");
130 rc = TOXAV_ERR_NEW_MALLOC; 130 rc = TOXAV_ERR_NEW_MALLOC;
131 goto END; 131 goto END;
@@ -140,7 +140,7 @@ ToxAV *toxav_new(Tox *tox, TOXAV_ERR_NEW *error)
140 av->m = m; 140 av->m = m;
141 av->msi = msi_new(av->m); 141 av->msi = msi_new(av->m);
142 142
143 if (av->msi == NULL) { 143 if (av->msi == nullptr) {
144 pthread_mutex_destroy(av->mutex); 144 pthread_mutex_destroy(av->mutex);
145 rc = TOXAV_ERR_NEW_MALLOC; 145 rc = TOXAV_ERR_NEW_MALLOC;
146 goto END; 146 goto END;
@@ -164,14 +164,14 @@ END:
164 164
165 if (rc != TOXAV_ERR_NEW_OK) { 165 if (rc != TOXAV_ERR_NEW_OK) {
166 free(av); 166 free(av);
167 av = NULL; 167 av = nullptr;
168 } 168 }
169 169
170 return av; 170 return av;
171} 171}
172void toxav_kill(ToxAV *av) 172void toxav_kill(ToxAV *av)
173{ 173{
174 if (av == NULL) { 174 if (av == nullptr) {
175 return; 175 return;
176 } 176 }
177 177
@@ -189,7 +189,7 @@ void toxav_kill(ToxAV *av)
189 189
190 while (it) { 190 while (it) {
191 call_kill_transmission(it); 191 call_kill_transmission(it);
192 it->msi_call = NULL; /* msi_kill() frees the call's msi_call handle; which causes #278 */ 192 it->msi_call = nullptr; /* msi_kill() frees the call's msi_call handle; which causes #278 */
193 it = call_remove(it); /* This will eventually free av->calls */ 193 it = call_remove(it); /* This will eventually free av->calls */
194 } 194 }
195 } 195 }
@@ -212,7 +212,7 @@ void toxav_iterate(ToxAV *av)
212{ 212{
213 pthread_mutex_lock(av->mutex); 213 pthread_mutex_lock(av->mutex);
214 214
215 if (av->calls == NULL) { 215 if (av->calls == nullptr) {
216 pthread_mutex_unlock(av->mutex); 216 pthread_mutex_unlock(av->mutex);
217 return; 217 return;
218 } 218 }
@@ -279,7 +279,7 @@ bool toxav_call(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, uint
279 279
280 call = call_new(av, friend_number, &rc); 280 call = call_new(av, friend_number, &rc);
281 281
282 if (call == NULL) { 282 if (call == nullptr) {
283 goto END; 283 goto END;
284 } 284 }
285 285
@@ -337,7 +337,7 @@ bool toxav_answer(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, ui
337 337
338 call = call_get(av, friend_number); 338 call = call_get(av, friend_number);
339 339
340 if (call == NULL) { 340 if (call == nullptr) {
341 rc = TOXAV_ERR_ANSWER_FRIEND_NOT_CALLING; 341 rc = TOXAV_ERR_ANSWER_FRIEND_NOT_CALLING;
342 goto END; 342 goto END;
343 } 343 }
@@ -388,7 +388,7 @@ bool toxav_call_control(ToxAV *av, uint32_t friend_number, TOXAV_CALL_CONTROL co
388 388
389 call = call_get(av, friend_number); 389 call = call_get(av, friend_number);
390 390
391 if (call == NULL || (!call->active && control != TOXAV_CALL_CONTROL_CANCEL)) { 391 if (call == nullptr || (!call->active && control != TOXAV_CALL_CONTROL_CANCEL)) {
392 rc = TOXAV_ERR_CALL_CONTROL_FRIEND_NOT_IN_CALL; 392 rc = TOXAV_ERR_CALL_CONTROL_FRIEND_NOT_IN_CALL;
393 goto END; 393 goto END;
394 } 394 }
@@ -443,7 +443,7 @@ bool toxav_call_control(ToxAV *av, uint32_t friend_number, TOXAV_CALL_CONTROL co
443 goto END; 443 goto END;
444 } 444 }
445 445
446 call->msi_call = NULL; 446 call->msi_call = nullptr;
447 pthread_mutex_unlock(call->mutex); 447 pthread_mutex_unlock(call->mutex);
448 448
449 /* No mather the case, terminate the call */ 449 /* No mather the case, terminate the call */
@@ -545,7 +545,7 @@ bool toxav_audio_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t audio_
545 pthread_mutex_lock(av->mutex); 545 pthread_mutex_lock(av->mutex);
546 call = call_get(av, friend_number); 546 call = call_get(av, friend_number);
547 547
548 if (call == NULL || !call->active || call->msi_call->state != msi_CallActive) { 548 if (call == nullptr || !call->active || call->msi_call->state != msi_CallActive) {
549 pthread_mutex_unlock(av->mutex); 549 pthread_mutex_unlock(av->mutex);
550 rc = TOXAV_ERR_BIT_RATE_SET_FRIEND_NOT_IN_CALL; 550 rc = TOXAV_ERR_BIT_RATE_SET_FRIEND_NOT_IN_CALL;
551 goto END; 551 goto END;
@@ -617,7 +617,7 @@ bool toxav_video_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t video_
617 pthread_mutex_lock(av->mutex); 617 pthread_mutex_lock(av->mutex);
618 call = call_get(av, friend_number); 618 call = call_get(av, friend_number);
619 619
620 if (call == NULL || !call->active || call->msi_call->state != msi_CallActive) { 620 if (call == nullptr || !call->active || call->msi_call->state != msi_CallActive) {
621 pthread_mutex_unlock(av->mutex); 621 pthread_mutex_unlock(av->mutex);
622 rc = TOXAV_ERR_BIT_RATE_SET_FRIEND_NOT_IN_CALL; 622 rc = TOXAV_ERR_BIT_RATE_SET_FRIEND_NOT_IN_CALL;
623 goto END; 623 goto END;
@@ -702,7 +702,7 @@ bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pc
702 702
703 call = call_get(av, friend_number); 703 call = call_get(av, friend_number);
704 704
705 if (call == NULL || !call->active || call->msi_call->state != msi_CallActive) { 705 if (call == nullptr || !call->active || call->msi_call->state != msi_CallActive) {
706 pthread_mutex_unlock(av->mutex); 706 pthread_mutex_unlock(av->mutex);
707 rc = TOXAV_ERR_SEND_FRAME_FRIEND_NOT_IN_CALL; 707 rc = TOXAV_ERR_SEND_FRAME_FRIEND_NOT_IN_CALL;
708 goto END; 708 goto END;
@@ -719,7 +719,7 @@ bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pc
719 pthread_mutex_lock(call->mutex_audio); 719 pthread_mutex_lock(call->mutex_audio);
720 pthread_mutex_unlock(av->mutex); 720 pthread_mutex_unlock(av->mutex);
721 721
722 if (pcm == NULL) { 722 if (pcm == nullptr) {
723 pthread_mutex_unlock(call->mutex_audio); 723 pthread_mutex_unlock(call->mutex_audio);
724 rc = TOXAV_ERR_SEND_FRAME_NULL; 724 rc = TOXAV_ERR_SEND_FRAME_NULL;
725 goto END; 725 goto END;
@@ -787,7 +787,7 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u
787 787
788 call = call_get(av, friend_number); 788 call = call_get(av, friend_number);
789 789
790 if (call == NULL || !call->active || call->msi_call->state != msi_CallActive) { 790 if (call == nullptr || !call->active || call->msi_call->state != msi_CallActive) {
791 pthread_mutex_unlock(av->mutex); 791 pthread_mutex_unlock(av->mutex);
792 rc = TOXAV_ERR_SEND_FRAME_FRIEND_NOT_IN_CALL; 792 rc = TOXAV_ERR_SEND_FRAME_FRIEND_NOT_IN_CALL;
793 goto END; 793 goto END;
@@ -804,7 +804,7 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u
804 pthread_mutex_lock(call->mutex_video); 804 pthread_mutex_lock(call->mutex_video);
805 pthread_mutex_unlock(av->mutex); 805 pthread_mutex_unlock(av->mutex);
806 806
807 if (y == NULL || u == NULL || v == NULL) { 807 if (y == nullptr || u == nullptr || v == nullptr) {
808 pthread_mutex_unlock(call->mutex_video); 808 pthread_mutex_unlock(call->mutex_video);
809 rc = TOXAV_ERR_SEND_FRAME_NULL; 809 rc = TOXAV_ERR_SEND_FRAME_NULL;
810 goto END; 810 goto END;
@@ -844,7 +844,7 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u
844 ++call->video.second->frame_counter; 844 ++call->video.second->frame_counter;
845 845
846 { /* Send frames */ 846 { /* Send frames */
847 vpx_codec_iter_t iter = NULL; 847 vpx_codec_iter_t iter = nullptr;
848 const vpx_codec_cx_pkt_t *pkt; 848 const vpx_codec_cx_pkt_t *pkt;
849 849
850 while ((pkt = vpx_codec_get_cx_data(call->video.second->encoder, &iter))) { 850 while ((pkt = vpx_codec_get_cx_data(call->video.second->encoder, &iter))) {
@@ -948,9 +948,9 @@ int callback_invite(void *toxav_inst, MSICall *call)
948 ToxAV *toxav = (ToxAV *)toxav_inst; 948 ToxAV *toxav = (ToxAV *)toxav_inst;
949 pthread_mutex_lock(toxav->mutex); 949 pthread_mutex_lock(toxav->mutex);
950 950
951 ToxAVCall *av_call = call_new(toxav, call->friend_number, NULL); 951 ToxAVCall *av_call = call_new(toxav, call->friend_number, nullptr);
952 952
953 if (av_call == NULL) { 953 if (av_call == nullptr) {
954 LOGGER_WARNING(toxav->m->log, "Failed to initialize call..."); 954 LOGGER_WARNING(toxav->m->log, "Failed to initialize call...");
955 pthread_mutex_unlock(toxav->mutex); 955 pthread_mutex_unlock(toxav->mutex);
956 return -1; 956 return -1;
@@ -978,7 +978,7 @@ int callback_start(void *toxav_inst, MSICall *call)
978 978
979 ToxAVCall *av_call = call_get(toxav, call->friend_number); 979 ToxAVCall *av_call = call_get(toxav, call->friend_number);
980 980
981 if (av_call == NULL) { 981 if (av_call == nullptr) {
982 /* Should this ever happen? */ 982 /* Should this ever happen? */
983 pthread_mutex_unlock(toxav->mutex); 983 pthread_mutex_unlock(toxav->mutex);
984 return -1; 984 return -1;
@@ -1083,7 +1083,7 @@ ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, TOXAV_ERR_CALL *error)
1083{ 1083{
1084 /* Assumes mutex locked */ 1084 /* Assumes mutex locked */
1085 TOXAV_ERR_CALL rc = TOXAV_ERR_CALL_OK; 1085 TOXAV_ERR_CALL rc = TOXAV_ERR_CALL_OK;
1086 ToxAVCall *call = NULL; 1086 ToxAVCall *call = nullptr;
1087 1087
1088 if (m_friend_exists(av->m, friend_number) == 0) { 1088 if (m_friend_exists(av->m, friend_number) == 0) {
1089 rc = TOXAV_ERR_CALL_FRIEND_NOT_FOUND; 1089 rc = TOXAV_ERR_CALL_FRIEND_NOT_FOUND;
@@ -1095,7 +1095,7 @@ ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, TOXAV_ERR_CALL *error)
1095 goto END; 1095 goto END;
1096 } 1096 }
1097 1097
1098 if (call_get(av, friend_number) != NULL) { 1098 if (call_get(av, friend_number) != nullptr) {
1099 rc = TOXAV_ERR_CALL_FRIEND_ALREADY_IN_CALL; 1099 rc = TOXAV_ERR_CALL_FRIEND_ALREADY_IN_CALL;
1100 goto END; 1100 goto END;
1101 } 1101 }
@@ -1103,7 +1103,7 @@ ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, TOXAV_ERR_CALL *error)
1103 1103
1104 call = (ToxAVCall *)calloc(sizeof(ToxAVCall), 1); 1104 call = (ToxAVCall *)calloc(sizeof(ToxAVCall), 1);
1105 1105
1106 if (call == NULL) { 1106 if (call == nullptr) {
1107 rc = TOXAV_ERR_CALL_MALLOC; 1107 rc = TOXAV_ERR_CALL_MALLOC;
1108 goto END; 1108 goto END;
1109 } 1109 }
@@ -1111,12 +1111,12 @@ ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, TOXAV_ERR_CALL *error)
1111 call->av = av; 1111 call->av = av;
1112 call->friend_number = friend_number; 1112 call->friend_number = friend_number;
1113 1113
1114 if (av->calls == NULL) { /* Creating */ 1114 if (av->calls == nullptr) { /* Creating */
1115 av->calls = (ToxAVCall **)calloc(sizeof(ToxAVCall *), friend_number + 1); 1115 av->calls = (ToxAVCall **)calloc(sizeof(ToxAVCall *), friend_number + 1);
1116 1116
1117 if (av->calls == NULL) { 1117 if (av->calls == nullptr) {
1118 free(call); 1118 free(call);
1119 call = NULL; 1119 call = nullptr;
1120 rc = TOXAV_ERR_CALL_MALLOC; 1120 rc = TOXAV_ERR_CALL_MALLOC;
1121 goto END; 1121 goto END;
1122 } 1122 }
@@ -1125,9 +1125,9 @@ ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, TOXAV_ERR_CALL *error)
1125 } else if (av->calls_tail < friend_number) { /* Appending */ 1125 } else if (av->calls_tail < friend_number) { /* Appending */
1126 ToxAVCall **tmp = (ToxAVCall **)realloc(av->calls, sizeof(ToxAVCall *) * (friend_number + 1)); 1126 ToxAVCall **tmp = (ToxAVCall **)realloc(av->calls, sizeof(ToxAVCall *) * (friend_number + 1));
1127 1127
1128 if (tmp == NULL) { 1128 if (tmp == nullptr) {
1129 free(call); 1129 free(call);
1130 call = NULL; 1130 call = nullptr;
1131 rc = TOXAV_ERR_CALL_MALLOC; 1131 rc = TOXAV_ERR_CALL_MALLOC;
1132 goto END; 1132 goto END;
1133 } 1133 }
@@ -1138,7 +1138,7 @@ ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, TOXAV_ERR_CALL *error)
1138 uint32_t i = av->calls_tail + 1; 1138 uint32_t i = av->calls_tail + 1;
1139 1139
1140 for (; i < friend_number; i ++) { 1140 for (; i < friend_number; i ++) {
1141 av->calls[i] = NULL; 1141 av->calls[i] = nullptr;
1142 } 1142 }
1143 1143
1144 call->prev = av->calls[av->calls_tail]; 1144 call->prev = av->calls[av->calls_tail];
@@ -1164,16 +1164,16 @@ END:
1164ToxAVCall *call_get(ToxAV *av, uint32_t friend_number) 1164ToxAVCall *call_get(ToxAV *av, uint32_t friend_number)
1165{ 1165{
1166 /* Assumes mutex locked */ 1166 /* Assumes mutex locked */
1167 if (av->calls == NULL || av->calls_tail < friend_number) { 1167 if (av->calls == nullptr || av->calls_tail < friend_number) {
1168 return NULL; 1168 return nullptr;
1169 } 1169 }
1170 1170
1171 return av->calls[friend_number]; 1171 return av->calls[friend_number];
1172} 1172}
1173ToxAVCall *call_remove(ToxAVCall *call) 1173ToxAVCall *call_remove(ToxAVCall *call)
1174{ 1174{
1175 if (call == NULL) { 1175 if (call == nullptr) {
1176 return NULL; 1176 return nullptr;
1177 } 1177 }
1178 1178
1179 uint32_t friend_number = call->friend_number; 1179 uint32_t friend_number = call->friend_number;
@@ -1186,7 +1186,7 @@ ToxAVCall *call_remove(ToxAVCall *call)
1186 * removed from the msi call. 1186 * removed from the msi call.
1187 */ 1187 */
1188 if (call->msi_call) { 1188 if (call->msi_call) {
1189 call->msi_call->av_call = NULL; 1189 call->msi_call->av_call = nullptr;
1190 } 1190 }
1191 1191
1192 free(call); 1192 free(call);
@@ -1207,21 +1207,21 @@ ToxAVCall *call_remove(ToxAVCall *call)
1207 goto CLEAR; 1207 goto CLEAR;
1208 } 1208 }
1209 1209
1210 av->calls[friend_number] = NULL; 1210 av->calls[friend_number] = nullptr;
1211 return next; 1211 return next;
1212 1212
1213CLEAR: 1213CLEAR:
1214 av->calls_head = av->calls_tail = 0; 1214 av->calls_head = av->calls_tail = 0;
1215 free(av->calls); 1215 free(av->calls);
1216 av->calls = NULL; 1216 av->calls = nullptr;
1217 1217
1218 return NULL; 1218 return nullptr;
1219} 1219}
1220bool call_prepare_transmission(ToxAVCall *call) 1220bool call_prepare_transmission(ToxAVCall *call)
1221{ 1221{
1222 /* Assumes mutex locked */ 1222 /* Assumes mutex locked */
1223 1223
1224 if (call == NULL) { 1224 if (call == nullptr) {
1225 return false; 1225 return false;
1226 } 1226 }
1227 1227
@@ -1292,12 +1292,12 @@ FAILURE:
1292 bwc_kill(call->bwc); 1292 bwc_kill(call->bwc);
1293 rtp_kill(call->audio.first); 1293 rtp_kill(call->audio.first);
1294 ac_kill(call->audio.second); 1294 ac_kill(call->audio.second);
1295 call->audio.first = NULL; 1295 call->audio.first = nullptr;
1296 call->audio.second = NULL; 1296 call->audio.second = nullptr;
1297 rtp_kill(call->video.first); 1297 rtp_kill(call->video.first);
1298 vc_kill(call->video.second); 1298 vc_kill(call->video.second);
1299 call->video.first = NULL; 1299 call->video.first = nullptr;
1300 call->video.second = NULL; 1300 call->video.second = nullptr;
1301 pthread_mutex_destroy(call->mutex); 1301 pthread_mutex_destroy(call->mutex);
1302FAILURE_2: 1302FAILURE_2:
1303 pthread_mutex_destroy(call->mutex_video); 1303 pthread_mutex_destroy(call->mutex_video);
@@ -1307,7 +1307,7 @@ FAILURE_3:
1307} 1307}
1308void call_kill_transmission(ToxAVCall *call) 1308void call_kill_transmission(ToxAVCall *call)
1309{ 1309{
1310 if (call == NULL || call->active == 0) { 1310 if (call == nullptr || call->active == 0) {
1311 return; 1311 return;
1312 } 1312 }
1313 1313
@@ -1324,13 +1324,13 @@ void call_kill_transmission(ToxAVCall *call)
1324 1324
1325 rtp_kill(call->audio.first); 1325 rtp_kill(call->audio.first);
1326 ac_kill(call->audio.second); 1326 ac_kill(call->audio.second);
1327 call->audio.first = NULL; 1327 call->audio.first = nullptr;
1328 call->audio.second = NULL; 1328 call->audio.second = nullptr;
1329 1329
1330 rtp_kill(call->video.first); 1330 rtp_kill(call->video.first);
1331 vc_kill(call->video.second); 1331 vc_kill(call->video.second);
1332 call->video.first = NULL; 1332 call->video.first = nullptr;
1333 call->video.second = NULL; 1333 call->video.second = nullptr;
1334 1334
1335 pthread_mutex_destroy(call->mutex_audio); 1335 pthread_mutex_destroy(call->mutex_audio);
1336 pthread_mutex_destroy(call->mutex_video); 1336 pthread_mutex_destroy(call->mutex_video);
diff --git a/toxav/video.c b/toxav/video.c
index c84e89f7..eee542a2 100644
--- a/toxav/video.c
+++ b/toxav/video.c
@@ -43,20 +43,20 @@ VCSession *vc_new(Logger *log, ToxAV *av, uint32_t friend_number, toxav_video_re
43 43
44 if (!vc) { 44 if (!vc) {
45 LOGGER_WARNING(log, "Allocation failed! Application might misbehave!"); 45 LOGGER_WARNING(log, "Allocation failed! Application might misbehave!");
46 return NULL; 46 return nullptr;
47 } 47 }
48 48
49 if (create_recursive_mutex(vc->queue_mutex) != 0) { 49 if (create_recursive_mutex(vc->queue_mutex) != 0) {
50 LOGGER_WARNING(log, "Failed to create recursive mutex!"); 50 LOGGER_WARNING(log, "Failed to create recursive mutex!");
51 free(vc); 51 free(vc);
52 return NULL; 52 return nullptr;
53 } 53 }
54 54
55 if (!(vc->vbuf_raw = rb_new(VIDEO_DECODE_BUFFER_SIZE))) { 55 if (!(vc->vbuf_raw = rb_new(VIDEO_DECODE_BUFFER_SIZE))) {
56 goto BASE_CLEANUP; 56 goto BASE_CLEANUP;
57 } 57 }
58 58
59 rc = vpx_codec_dec_init(vc->decoder, VIDEO_CODEC_DECODER_INTERFACE, NULL, 0); 59 rc = vpx_codec_dec_init(vc->decoder, VIDEO_CODEC_DECODER_INTERFACE, nullptr, 0);
60 60
61 if (rc != VPX_CODEC_OK) { 61 if (rc != VPX_CODEC_OK) {
62 LOGGER_ERROR(log, "Init video_decoder failed: %s", vpx_codec_err_to_string(rc)); 62 LOGGER_ERROR(log, "Init video_decoder failed: %s", vpx_codec_err_to_string(rc));
@@ -118,7 +118,7 @@ BASE_CLEANUP:
118 pthread_mutex_destroy(vc->queue_mutex); 118 pthread_mutex_destroy(vc->queue_mutex);
119 rb_kill((RingBuffer *)vc->vbuf_raw); 119 rb_kill((RingBuffer *)vc->vbuf_raw);
120 free(vc); 120 free(vc);
121 return NULL; 121 return nullptr;
122} 122}
123void vc_kill(VCSession *vc) 123void vc_kill(VCSession *vc)
124{ 124{
@@ -157,13 +157,13 @@ void vc_iterate(VCSession *vc)
157 if (rb_read((RingBuffer *)vc->vbuf_raw, (void **)&p)) { 157 if (rb_read((RingBuffer *)vc->vbuf_raw, (void **)&p)) {
158 pthread_mutex_unlock(vc->queue_mutex); 158 pthread_mutex_unlock(vc->queue_mutex);
159 159
160 rc = vpx_codec_decode(vc->decoder, p->data, p->len, NULL, MAX_DECODE_TIME_US); 160 rc = vpx_codec_decode(vc->decoder, p->data, p->len, nullptr, MAX_DECODE_TIME_US);
161 free(p); 161 free(p);
162 162
163 if (rc != VPX_CODEC_OK) { 163 if (rc != VPX_CODEC_OK) {
164 LOGGER_ERROR(vc->log, "Error decoding video: %s", vpx_codec_err_to_string(rc)); 164 LOGGER_ERROR(vc->log, "Error decoding video: %s", vpx_codec_err_to_string(rc));
165 } else { 165 } else {
166 vpx_codec_iter_t iter = NULL; 166 vpx_codec_iter_t iter = nullptr;
167 vpx_image_t *dest = vpx_codec_get_frame(vc->decoder, &iter); 167 vpx_image_t *dest = vpx_codec_get_frame(vc->decoder, &iter);
168 168
169 /* Play decoded images */ 169 /* Play decoded images */