Skip to content

Commit

Permalink
cleanup: Mark all local non-pointers as const where possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Feb 23, 2022
1 parent 17c8f50 commit b13590a
Show file tree
Hide file tree
Showing 25 changed files with 221 additions and 221 deletions.
2 changes: 1 addition & 1 deletion other/bootstrap_daemon/docker/tox-bootstrapd.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d69f99a7aa2e9290024b1dea3443fbfe9bfbaba444db5ccace5df2d88f15300a /usr/local/bin/tox-bootstrapd
dd4f76c70a0f0a4799b73ee372d81dbc6228e4b25890b7d5f4b0a89950e1c465 /usr/local/bin/tox-bootstrapd
12 changes: 6 additions & 6 deletions toxav/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void ac_iterate(ACSession *ac)

if (rc == 2) {
LOGGER_DEBUG(ac->log, "OPUS correction");
int fs = (ac->lp_sampling_rate * ac->lp_frame_duration) / 1000;
const int fs = (ac->lp_sampling_rate * ac->lp_frame_duration) / 1000;
rc = opus_decode(ac->decoder, nullptr, 0, temp_audio_buffer, fs, 1);
} else {
/* Get values from packet and decode. */
Expand Down Expand Up @@ -230,7 +230,7 @@ int ac_queue_message(Mono_Time *mono_time, void *acp, struct RTPMessage *msg)
}

pthread_mutex_lock(ac->queue_mutex);
int rc = jbuf_write(ac->log, (struct JitterBuffer *)ac->j_buf, msg);
const int rc = jbuf_write(ac->log, (struct JitterBuffer *)ac->j_buf, msg);
pthread_mutex_unlock(ac->queue_mutex);

if (rc == -1) {
Expand Down Expand Up @@ -311,9 +311,9 @@ static void jbuf_free(struct JitterBuffer *q)
}
static int jbuf_write(const Logger *log, struct JitterBuffer *q, struct RTPMessage *m)
{
uint16_t sequnum = m->header.sequnum;
const uint16_t sequnum = m->header.sequnum;

unsigned int num = sequnum % q->size;
const unsigned int num = sequnum % q->size;

if ((uint32_t)(sequnum - q->bottom) > q->size) {
LOGGER_DEBUG(log, "Clearing filled jitter buffer: %p", (void *)q);
Expand Down Expand Up @@ -344,7 +344,7 @@ static struct RTPMessage *jbuf_read(struct JitterBuffer *q, int32_t *success)
return nullptr;
}

unsigned int num = q->bottom % q->size;
const unsigned int num = q->bottom % q->size;

if (q->queue[num] != nullptr) {
struct RTPMessage *ret = q->queue[num];
Expand Down Expand Up @@ -474,7 +474,7 @@ static bool reconfigure_audio_encoder(const Logger *log, OpusEncoder **e, uint32
return true; /* Nothing changed */
}

int status = opus_encoder_ctl(*e, OPUS_SET_BITRATE(new_br));
const int status = opus_encoder_ctl(*e, OPUS_SET_BITRATE(new_br));

if (status != OPUS_OK) {
LOGGER_ERROR(log, "Error while setting encoder ctl: %s", opus_strerror(status));
Expand Down
2 changes: 1 addition & 1 deletion toxav/bwcontroller.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ BWController *bwc_new(Messenger *m, Tox *tox, uint32_t friendnumber, m_cb *mcb,
retu->m = m;
retu->friend_number = friendnumber;
retu->bwc_mono_time = bwc_mono_time;
uint64_t now = current_time_monotonic(bwc_mono_time);
const uint64_t now = current_time_monotonic(bwc_mono_time);
retu->cycle.last_sent_timestamp = now;
retu->cycle.last_refresh_timestamp = now;
retu->tox = tox;
Expand Down
18 changes: 9 additions & 9 deletions toxav/groupav.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ static void terminate_queue(Group_JitterBuffer *q)
*/
static int queue(Group_JitterBuffer *q, const Mono_Time *mono_time, Group_Audio_Packet *pk)
{
uint16_t sequnum = pk->sequnum;
const uint16_t sequnum = pk->sequnum;

unsigned int num = sequnum % q->size;
const unsigned int num = sequnum % q->size;

if (!mono_time_is_timeout(mono_time, q->last_queued_time, GROUP_JBUF_DEAD_SECONDS)) {
if ((uint32_t)(sequnum - q->bottom) > (1 << 15)) {
Expand Down Expand Up @@ -132,7 +132,7 @@ static Group_Audio_Packet *dequeue(Group_JitterBuffer *q, int *success)
return nullptr;
}

unsigned int num = q->bottom % q->size;
const unsigned int num = q->bottom % q->size;

if (q->queue[num] != nullptr) {
Group_Audio_Packet *ret = q->queue[num];
Expand Down Expand Up @@ -304,10 +304,10 @@ static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, uint3
int16_t *out_audio = nullptr;
int out_audio_samples = 0;

unsigned int sample_rate = 48000;
const unsigned int sample_rate = 48000;

if (success == 1) {
int channels = opus_packet_get_nb_channels(pk->data);
const int channels = opus_packet_get_nb_channels(pk->data);

if (channels == OPUS_INVALID_PACKET) {
free_audio_packet(pk);
Expand Down Expand Up @@ -337,7 +337,7 @@ static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, uint3
peer_av->decoder_channels = channels;
}

int num_samples = opus_decoder_get_nb_samples(peer_av->audio_decoder, pk->data, pk->length);
const int num_samples = opus_decoder_get_nb_samples(peer_av->audio_decoder, pk->data, pk->length);

out_audio = (int16_t *)malloc(num_samples * peer_av->decoder_channels * sizeof(int16_t));

Expand Down Expand Up @@ -529,7 +529,7 @@ bool groupchat_av_enabled(const Group_Chats *g_c, uint32_t groupnumber)
*/
int add_av_groupchat(const Logger *log, Tox *tox, Group_Chats *g_c, audio_data_cb *audio_callback, void *userdata)
{
int groupnumber = add_groupchat(g_c, GROUPCHAT_TYPE_AV);
const int groupnumber = add_groupchat(g_c, GROUPCHAT_TYPE_AV);

if (groupnumber == -1) {
return -1;
Expand All @@ -551,7 +551,7 @@ int add_av_groupchat(const Logger *log, Tox *tox, Group_Chats *g_c, audio_data_c
int join_av_groupchat(const Logger *log, Tox *tox, Group_Chats *g_c, uint32_t friendnumber, const uint8_t *data,
uint16_t length, audio_data_cb *audio_callback, void *userdata)
{
int groupnumber = join_groupchat(g_c, friendnumber, GROUPCHAT_TYPE_AV, data, length);
const int groupnumber = join_groupchat(g_c, friendnumber, GROUPCHAT_TYPE_AV, data, length);

if (groupnumber == -1) {
return -1;
Expand Down Expand Up @@ -640,7 +640,7 @@ int group_send_audio(Group_Chats *g_c, uint32_t groupnumber, const int16_t *pcm,
}

uint8_t encoded[1024];
int32_t size = opus_encode(group_av->audio_encoder, pcm, samples, encoded, sizeof(encoded));
const int32_t size = opus_encode(group_av->audio_encoder, pcm, samples, encoded, sizeof(encoded));

if (size <= 0) {
return -1;
Expand Down
4 changes: 2 additions & 2 deletions toxav/rtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ static void update_bwc_values(const Logger *log, RTPSession *session, const stru
if (session->first_packets_counter < DISMISS_FIRST_LOST_VIDEO_PACKET_COUNT) {
++session->first_packets_counter;
} else {
uint32_t data_length_full = msg->header.data_length_full; // without header
uint32_t received_length_full = msg->header.received_length_full; // without header
const uint32_t data_length_full = msg->header.data_length_full; // without header
const uint32_t received_length_full = msg->header.received_length_full; // without header
bwc_add_recv(session->bwc, data_length_full);

if (received_length_full < data_length_full) {
Expand Down
12 changes: 6 additions & 6 deletions toxav/toxav.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ static void iterate_common(ToxAV *av, bool audio)
return;
}

uint64_t start = current_time_monotonic(av->toxav_mono_time);
const uint64_t start = current_time_monotonic(av->toxav_mono_time);
// time until the first audio or video frame is over
int32_t frame_time = IDLE_ITERATION_INTERVAL_MS;

Expand Down Expand Up @@ -330,7 +330,7 @@ static void iterate_common(ToxAV *av, bool audio)
}
}

uint32_t fid = i->friend_number;
const uint32_t fid = i->friend_number;

pthread_mutex_unlock(i->toxav_call_mutex);
pthread_mutex_lock(av->mutex);
Expand Down Expand Up @@ -628,7 +628,7 @@ bool toxav_call_control(ToxAV *av, uint32_t friend_number, Toxav_Call_Control co
{
pthread_mutex_lock(av->mutex);

Toxav_Err_Call_Control rc = call_control(av, friend_number, control);
const Toxav_Err_Call_Control rc = call_control(av, friend_number, control);

pthread_mutex_unlock(av->mutex);

Expand Down Expand Up @@ -854,7 +854,7 @@ bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pc

sampling_rate = net_htonl(sampling_rate);
memcpy(dest, &sampling_rate, sizeof(sampling_rate));
int vrc = opus_encode(call->audio->encoder, pcm, sample_count,
const int vrc = opus_encode(call->audio->encoder, pcm, sample_count,
dest + sizeof(sampling_rate), SIZEOF_VLA(dest) - sizeof(sampling_rate));

if (vrc < 0) {
Expand Down Expand Up @@ -1001,7 +1001,7 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u
memcpy(img.planes[VPX_PLANE_U], u, (width / 2) * (height / 2));
memcpy(img.planes[VPX_PLANE_V], v, (width / 2) * (height / 2));

vpx_codec_err_t vrc = vpx_codec_encode(call->video->encoder, &img,
const vpx_codec_err_t vrc = vpx_codec_encode(call->video->encoder, &img,
call->video->frame_counter, 1, vpx_encode_flags, MAX_ENCODE_TIME_US);

vpx_img_free(&img);
Expand Down Expand Up @@ -1338,7 +1338,7 @@ static ToxAVCall *call_remove(ToxAVCall *call)
return nullptr;
}

uint32_t friend_number = call->friend_number;
const uint32_t friend_number = call->friend_number;
ToxAV *av = call->av;

ToxAVCall *prev = call->prev;
Expand Down
12 changes: 6 additions & 6 deletions toxav/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static vpx_codec_iface_t *video_codec_encoder_interface(void)

static void vc_init_encoder_cfg(const Logger *log, vpx_codec_enc_cfg_t *cfg, int16_t kf_max_dist)
{
vpx_codec_err_t rc = vpx_codec_enc_config_default(video_codec_encoder_interface(), cfg, 0);
const vpx_codec_err_t rc = vpx_codec_enc_config_default(video_codec_encoder_interface(), cfg, 0);

if (rc != VPX_CODEC_OK) {
LOGGER_ERROR(log, "vc_init_encoder_cfg:Failed to get config: %s", vpx_codec_err_to_string(rc));
Expand Down Expand Up @@ -157,7 +157,7 @@ VCSession *vc_new(Mono_Time *mono_time, const Logger *log, ToxAV *av, uint32_t f
return nullptr;
}

int cpu_used_value = VP8E_SET_CPUUSED_VALUE;
const int cpu_used_value = VP8E_SET_CPUUSED_VALUE;

vc->vbuf_raw = rb_new(VIDEO_DECODE_BUFFER_SIZE);

Expand Down Expand Up @@ -193,7 +193,7 @@ VCSession *vc_new(Mono_Time *mono_time, const Logger *log, ToxAV *av, uint32_t f

if (VIDEO_VP8_DECODER_POST_PROCESSING_ENABLED == 1) {
vp8_postproc_cfg_t pp = {VP8_DEBLOCK, 1, 0};
vpx_codec_err_t cc_res = vpx_codec_control(vc->decoder, VP8_SET_POSTPROC, &pp);
const vpx_codec_err_t cc_res = vpx_codec_control(vc->decoder, VP8_SET_POSTPROC, &pp);

if (cc_res != VPX_CODEC_OK) {
LOGGER_WARNING(log, "Failed to turn on postproc");
Expand Down Expand Up @@ -300,7 +300,7 @@ void vc_iterate(VCSession *vc)
return;
}

uint16_t log_rb_size = rb_size(vc->vbuf_raw);
const uint16_t log_rb_size = rb_size(vc->vbuf_raw);
pthread_mutex_unlock(vc->queue_mutex);
const struct RTPHeader *const header = &p->header;

Expand Down Expand Up @@ -376,7 +376,7 @@ int vc_queue_message(Mono_Time *mono_time, void *vcp, struct RTPMessage *msg)
free(rb_write(vc->vbuf_raw, msg));

/* Calculate time it took for peer to send us this frame */
uint32_t t_lcfd = current_time_monotonic(mono_time) - vc->linfts;
const uint32_t t_lcfd = current_time_monotonic(mono_time) - vc->linfts;
vc->lcfd = t_lcfd > 100 ? vc->lcfd : t_lcfd;
vc->linfts = current_time_monotonic(mono_time);
pthread_mutex_unlock(vc->queue_mutex);
Expand Down Expand Up @@ -426,7 +426,7 @@ int vc_reconfigure_encoder(VCSession *vc, uint32_t bit_rate, uint16_t width, uin
return -1;
}

int cpu_used_value = VP8E_SET_CPUUSED_VALUE;
const int cpu_used_value = VP8E_SET_CPUUSED_VALUE;

rc = vpx_codec_control(&new_c, VP8E_SET_CPUUSED, cpu_used_value);

Expand Down
4 changes: 2 additions & 2 deletions toxcore/DHT.c
Original file line number Diff line number Diff line change
Expand Up @@ -1810,7 +1810,7 @@ static void do_Close(DHT *dht)

dht->num_to_bootstrap = 0;

uint8_t not_killed = do_ping_and_sendnode_requests(
const uint8_t not_killed = do_ping_and_sendnode_requests(
dht, &dht->close_lastgetnodes, dht->self_public_key, dht->close_clientlist, LCLIENT_LIST, &dht->close_bootstrap_times,
0);

Expand Down Expand Up @@ -2171,7 +2171,7 @@ static int handle_NATping(void *object, const IP_Port *source, const uint8_t *so
uint64_t ping_id;
memcpy(&ping_id, packet + 1, sizeof(uint64_t));

uint32_t friendnumber = index_of_friend_pk(dht->friends_list, dht->num_friends, source_pubkey);
const uint32_t friendnumber = index_of_friend_pk(dht->friends_list, dht->num_friends, source_pubkey);

if (friendnumber == UINT32_MAX) {
return 1;
Expand Down
8 changes: 4 additions & 4 deletions toxcore/LAN_discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ static Broadcast_Info *fetch_broadcast_info(uint16_t port)
if (net_family_is_ipv4(gateway.family) && net_family_is_ipv4(subnet_mask.family)) {
IP_Port *ip_port = &broadcast->ip_ports[broadcast->count];
ip_port->ip.family = net_family_ipv4;
uint32_t gateway_ip = net_ntohl(gateway.ip.v4.uint32);
uint32_t subnet_ip = net_ntohl(subnet_mask.ip.v4.uint32);
uint32_t broadcast_ip = gateway_ip + ~subnet_ip - 1;
const uint32_t gateway_ip = net_ntohl(gateway.ip.v4.uint32);
const uint32_t subnet_ip = net_ntohl(subnet_mask.ip.v4.uint32);
const uint32_t broadcast_ip = gateway_ip + ~subnet_ip - 1;
ip_port->ip.ip.v4.uint32 = net_htonl(broadcast_ip);
ip_port->port = port;
++broadcast->count;
Expand Down Expand Up @@ -155,7 +155,7 @@ static Broadcast_Info *fetch_broadcast_info(uint16_t port)
* a larger array, not done (640kB and 16 interfaces shall be
* enough, for everybody!)
*/
int n = ifc.ifc_len / sizeof(struct ifreq);
const int n = ifc.ifc_len / sizeof(struct ifreq);

for (int i = 0; i < n; ++i) {
/* there are interfaces with are incapable of broadcast */
Expand Down
Loading

0 comments on commit b13590a

Please sign in to comment.