mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Reduce nesting by doing more early returns on error.
This almost entirely avoids any else-after-return in toxcore. One case is left, and that one is more readable this way. Why no else after return: https://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return Why exemptions exist: https://blog.mozilla.org/nnethercote/2009/08/31/no-else-after-return-considered-harmful/
This commit is contained in:
parent
253abe5de4
commit
9a96bb9a5b
|
@ -299,18 +299,21 @@ void vc_iterate(VCSession *vc)
|
|||
return;
|
||||
}
|
||||
|
||||
struct RTPMessage *p;
|
||||
|
||||
vpx_codec_err_t rc;
|
||||
|
||||
pthread_mutex_lock(vc->queue_mutex);
|
||||
|
||||
uint32_t full_data_len;
|
||||
struct RTPMessage *p;
|
||||
|
||||
if (!rb_read((RingBuffer *)vc->vbuf_raw, (void **)&p)) {
|
||||
LOGGER_TRACE(vc->log, "no Video frame data available");
|
||||
pthread_mutex_unlock(vc->queue_mutex);
|
||||
return;
|
||||
}
|
||||
|
||||
if (rb_read((RingBuffer *)vc->vbuf_raw, (void **)&p)) {
|
||||
pthread_mutex_unlock(vc->queue_mutex);
|
||||
const struct RTPHeader *const header = &p->header;
|
||||
|
||||
uint32_t full_data_len;
|
||||
|
||||
if (header->flags & RTP_LARGE_FRAME) {
|
||||
full_data_len = header->data_length_full;
|
||||
LOGGER_DEBUG(vc->log, "vc_iterate:001:full_data_len=%d", (int)full_data_len);
|
||||
|
@ -321,12 +324,14 @@ void vc_iterate(VCSession *vc)
|
|||
|
||||
LOGGER_DEBUG(vc->log, "vc_iterate: rb_read p->len=%d p->header.xe=%d", (int)full_data_len, p->header.xe);
|
||||
LOGGER_DEBUG(vc->log, "vc_iterate: rb_read rb size=%d", (int)rb_size((RingBuffer *)vc->vbuf_raw));
|
||||
rc = vpx_codec_decode(vc->decoder, p->data, full_data_len, nullptr, MAX_DECODE_TIME_US);
|
||||
const vpx_codec_err_t rc = vpx_codec_decode(vc->decoder, p->data, full_data_len, nullptr, MAX_DECODE_TIME_US);
|
||||
free(p);
|
||||
|
||||
if (rc != VPX_CODEC_OK) {
|
||||
LOGGER_ERROR(vc->log, "Error decoding video: %d %s", (int)rc, vpx_codec_err_to_string(rc));
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Play decoded images */
|
||||
vpx_codec_iter_t iter = nullptr;
|
||||
vpx_image_t *dest = nullptr;
|
||||
|
@ -342,14 +347,6 @@ void vc_iterate(VCSession *vc)
|
|||
}
|
||||
}
|
||||
|
||||
return;
|
||||
} else {
|
||||
LOGGER_TRACE(vc->log, "no Video frame data available");
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(vc->queue_mutex);
|
||||
}
|
||||
|
||||
int vc_queue_message(void *vcp, struct RTPMessage *msg)
|
||||
{
|
||||
/* This function is called with complete messages
|
||||
|
|
|
@ -2270,12 +2270,9 @@ static unsigned int lossy_packet_not_received(Group_c *g, int peer_index, uint16
|
|||
g->group[peer_index].top_lossy_number = message_number;
|
||||
g->group[peer_index].bottom_lossy_number = (message_number - MAX_LOSSY_COUNT) + 1;
|
||||
g->group[peer_index].recv_lossy[message_number % MAX_LOSSY_COUNT] = 1;
|
||||
|
||||
return 0;
|
||||
} else { // top_distance < MAX_LOSSY_COUNT
|
||||
unsigned int i;
|
||||
|
||||
for (i = g->group[peer_index].bottom_lossy_number; i != (g->group[peer_index].bottom_lossy_number + top_distance);
|
||||
for (unsigned int i = g->group[peer_index].bottom_lossy_number;
|
||||
i != g->group[peer_index].bottom_lossy_number + top_distance;
|
||||
++i) {
|
||||
g->group[peer_index].recv_lossy[i % MAX_LOSSY_COUNT] = 0;
|
||||
}
|
||||
|
@ -2283,9 +2280,10 @@ static unsigned int lossy_packet_not_received(Group_c *g, int peer_index, uint16
|
|||
g->group[peer_index].top_lossy_number = message_number;
|
||||
g->group[peer_index].bottom_lossy_number = (message_number - MAX_LOSSY_COUNT) + 1;
|
||||
g->group[peer_index].recv_lossy[message_number % MAX_LOSSY_COUNT] = 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata)
|
||||
|
|
Loading…
Reference in New Issue
Block a user