Skip to content

Commit 05abe08

Browse files
committed
cleanup: Some random cleanups, mostly related to mem.
1 parent 5cca245 commit 05abe08

23 files changed

+69
-58
lines changed

auto_tests/proxy_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* Tests that we can send messages to friends.
22
*/
33

4+
#include <pthread.h>
45
#include <stdbool.h>
56
#include <stdint.h>
6-
#include <string.h>
77

88
#include "auto_test_support.h"
99

toxav/audio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ void ac_iterate(ACSession *ac)
195195
free(temp_audio_buffer);
196196
}
197197

198-
int ac_queue_message(Mono_Time *mono_time, void *cs, struct RTPMessage *msg)
198+
int ac_queue_message(const Mono_Time *mono_time, void *cs, struct RTPMessage *msg)
199199
{
200200
ACSession *ac = (ACSession *)cs;
201201

toxav/audio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ ACSession *ac_new(Mono_Time *mono_time, const Logger *log, ToxAV *av, uint32_t f
6767
toxav_audio_receive_frame_cb *cb, void *cb_data);
6868
void ac_kill(ACSession *ac);
6969
void ac_iterate(ACSession *ac);
70-
int ac_queue_message(Mono_Time *mono_time, void *cs, struct RTPMessage *msg);
70+
int ac_queue_message(const Mono_Time *mono_time, void *cs, struct RTPMessage *msg);
7171
int ac_reconfigure_encoder(ACSession *ac, uint32_t bit_rate, uint32_t sampling_rate, uint8_t channels);
7272

7373
#endif /* C_TOXCORE_TOXAV_AUDIO_H */

toxav/rtp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ static struct RTPHeader rtp_default_header(const RTPSession *session, uint32_t l
823823
header.ma = 0;
824824
header.pt = session->payload_type % 128;
825825
header.sequnum = session->sequnum;
826-
Mono_Time *mt = toxav_get_av_mono_time(session->toxav);
826+
const Mono_Time *mt = toxav_get_av_mono_time(session->toxav);
827827
if (mt != nullptr) {
828828
header.timestamp = current_time_monotonic(mt);
829829
} else {

toxav/rtp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ struct RTPWorkBufferList {
147147

148148
#define DISMISS_FIRST_LOST_VIDEO_PACKET_COUNT 10
149149

150-
typedef int rtp_m_cb(Mono_Time *mono_time, void *cs, struct RTPMessage *msg);
150+
typedef int rtp_m_cb(const Mono_Time *mono_time, void *cs, struct RTPMessage *msg);
151151

152152
/**
153153
* RTP control session.

toxav/toxav.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "toxav.h"
66

77
#include <assert.h>
8-
#include <errno.h>
98
#include <limits.h>
109
#include <stdlib.h>
1110
#include <string.h>
@@ -21,7 +20,7 @@
2120
#include "../toxcore/network.h"
2221
#include "../toxcore/tox.h"
2322
#include "../toxcore/tox_private.h"
24-
#include "../toxcore/tox_struct.h"
23+
#include "../toxcore/tox_struct.h" // IWYU pragma: keep
2524
#include "../toxcore/util.h"
2625

2726
// TODO(zoff99): don't hardcode this, let the application choose it
@@ -342,7 +341,7 @@ uint32_t toxav_iteration_interval(const ToxAV *av)
342341
* @param frame_time the duration of the current frame in ms
343342
* @param start_time the timestamp when decoding of this frame started
344343
*/
345-
static void calc_interval(ToxAV *av, DecodeTimeStats *stats, int32_t frame_time, uint64_t start_time)
344+
static void calc_interval(const ToxAV *av, DecodeTimeStats *stats, int32_t frame_time, uint64_t start_time)
346345
{
347346
stats->interval = frame_time < stats->average ? 0 : (frame_time - stats->average);
348347
stats->total += current_time_monotonic(av->toxav_mono_time) - start_time;

toxav/video.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
#include <stdlib.h>
99
#include <string.h>
1010

11-
#include "msi.h"
1211
#include "ring_buffer.h"
1312
#include "rtp.h"
1413

1514
#include "../toxcore/ccompat.h"
1615
#include "../toxcore/logger.h"
1716
#include "../toxcore/mono_time.h"
18-
#include "../toxcore/network.h"
1917

2018
/**
2119
* Soft deadline the decoder should attempt to meet, in "us" (microseconds).
@@ -143,7 +141,7 @@ static void vc_init_encoder_cfg(const Logger *log, vpx_codec_enc_cfg_t *cfg, int
143141
#endif /* 0 */
144142
}
145143

146-
VCSession *vc_new(const Logger *log, Mono_Time *mono_time, ToxAV *av, uint32_t friend_number,
144+
VCSession *vc_new(const Logger *log, const Mono_Time *mono_time, ToxAV *av, uint32_t friend_number,
147145
toxav_video_receive_frame_cb *cb, void *cb_data)
148146
{
149147
VCSession *vc = (VCSession *)calloc(1, sizeof(VCSession));
@@ -346,7 +344,7 @@ void vc_iterate(VCSession *vc)
346344
}
347345
}
348346

349-
int vc_queue_message(Mono_Time *mono_time, void *cs, struct RTPMessage *msg)
347+
int vc_queue_message(const Mono_Time *mono_time, void *cs, struct RTPMessage *msg)
350348
{
351349
VCSession *vc = (VCSession *)cs;
352350

toxav/video.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ typedef struct VCSession {
4444
const Logger *log;
4545
} VCSession;
4646

47-
VCSession *vc_new(const Logger *log, Mono_Time *mono_time, ToxAV *av, uint32_t friend_number,
47+
VCSession *vc_new(const Logger *log, const Mono_Time *mono_time, ToxAV *av, uint32_t friend_number,
4848
toxav_video_receive_frame_cb *cb, void *cb_data);
4949
void vc_kill(VCSession *vc);
5050
void vc_iterate(VCSession *vc);
51-
int vc_queue_message(Mono_Time *mono_time, void *cs, struct RTPMessage *msg);
51+
int vc_queue_message(const Mono_Time *mono_time, void *cs, struct RTPMessage *msg);
5252
int vc_reconfigure_encoder(VCSession *vc, uint32_t bit_rate, uint16_t width, uint16_t height, int16_t kf_max_dist);
5353

5454
#endif /* C_TOXCORE_TOXAV_VIDEO_H */

toxcore/Messenger.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,15 @@ void getaddress(const Messenger *m, uint8_t *address)
137137
}
138138

139139
non_null()
140-
static bool send_online_packet(Messenger *m, int friendcon_id)
140+
static bool send_online_packet(const Messenger *m, int friendcon_id)
141141
{
142142
const uint8_t packet[1] = {PACKET_ID_ONLINE};
143143
return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, friendcon_id), packet,
144144
sizeof(packet), false) != -1;
145145
}
146146

147147
non_null()
148-
static bool send_offline_packet(Messenger *m, int friendcon_id)
148+
static bool send_offline_packet(const Messenger *m, int friendcon_id)
149149
{
150150
const uint8_t packet[1] = {PACKET_ID_OFFLINE};
151151
return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, friendcon_id), packet,

toxcore/group.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ static bool is_groupnumber_valid(const Group_Chats *g_c, uint32_t groupnumber)
248248

249249
/** @brief Set the size of the groupchat list to num.
250250
*
251-
* @retval false if realloc fails.
251+
* @retval false if mem_vrealloc fails.
252252
* @retval true if it succeeds.
253253
*/
254254
non_null()
@@ -1067,7 +1067,7 @@ static bool freeze_peer(Group_Chats *g_c, uint32_t groupnumber, int peer_index,
10671067
return false;
10681068
}
10691069

1070-
Group_Peer *temp = (Group_Peer *)mem_vrealloc(g_c->m->mem, g->frozen, g->numfrozen + 1, sizeof(Group_Peer));
1070+
Group_Peer *temp = (Group_Peer *)mem_vrealloc(g_c->mem, g->frozen, g->numfrozen + 1, sizeof(Group_Peer));
10711071

10721072
if (temp == nullptr) {
10731073
return false;
@@ -1085,7 +1085,7 @@ static bool freeze_peer(Group_Chats *g_c, uint32_t groupnumber, int peer_index,
10851085

10861086
++g->numfrozen;
10871087

1088-
delete_old_frozen(g, g_c->m->mem);
1088+
delete_old_frozen(g, g_c->mem);
10891089

10901090
return true;
10911091
}
@@ -1572,7 +1572,7 @@ int group_set_max_frozen(const Group_Chats *g_c, uint32_t groupnumber, uint32_t
15721572
}
15731573

15741574
g->maxfrozen = maxfrozen;
1575-
delete_old_frozen(g, g_c->m->mem);
1575+
delete_old_frozen(g, g_c->mem);
15761576
return 0;
15771577
}
15781578

@@ -3805,19 +3805,19 @@ bool conferences_load_state_section(Group_Chats *g_c, const uint8_t *data, uint3
38053805
}
38063806

38073807
/** Create new groupchat instance. */
3808-
Group_Chats *new_groupchats(const Mono_Time *mono_time, Messenger *m)
3808+
Group_Chats *new_groupchats(const Mono_Time *mono_time, const Memory *mem, Messenger *m)
38093809
{
38103810
if (m == nullptr) {
38113811
return nullptr;
38123812
}
38133813

3814-
Group_Chats *temp = (Group_Chats *)mem_alloc(m->mem, sizeof(Group_Chats));
3814+
Group_Chats *temp = (Group_Chats *)mem_alloc(mem, sizeof(Group_Chats));
38153815

38163816
if (temp == nullptr) {
38173817
return nullptr;
38183818
}
38193819

3820-
temp->mem = m->mem;
3820+
temp->mem = mem;
38213821
temp->mono_time = mono_time;
38223822
temp->m = m;
38233823
temp->fr_c = m->fr_c;

0 commit comments

Comments
 (0)