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,55 +299,52 @@ void vc_iterate(VCSession *vc)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RTPMessage *p;
|
|
||||||
|
|
||||||
vpx_codec_err_t rc;
|
|
||||||
|
|
||||||
pthread_mutex_lock(vc->queue_mutex);
|
pthread_mutex_lock(vc->queue_mutex);
|
||||||
|
|
||||||
uint32_t full_data_len;
|
struct RTPMessage *p;
|
||||||
|
|
||||||
if (rb_read((RingBuffer *)vc->vbuf_raw, (void **)&p)) {
|
if (!rb_read((RingBuffer *)vc->vbuf_raw, (void **)&p)) {
|
||||||
pthread_mutex_unlock(vc->queue_mutex);
|
|
||||||
const struct RTPHeader *const header = &p->header;
|
|
||||||
|
|
||||||
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);
|
|
||||||
} else {
|
|
||||||
full_data_len = p->len;
|
|
||||||
LOGGER_DEBUG(vc->log, "vc_iterate:002");
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
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 {
|
|
||||||
/* Play decoded images */
|
|
||||||
vpx_codec_iter_t iter = nullptr;
|
|
||||||
vpx_image_t *dest = nullptr;
|
|
||||||
|
|
||||||
while ((dest = vpx_codec_get_frame(vc->decoder, &iter)) != nullptr) {
|
|
||||||
if (vc->vcb.first) {
|
|
||||||
vc->vcb.first(vc->av, vc->friend_number, dest->d_w, dest->d_h,
|
|
||||||
(const uint8_t *)dest->planes[0], (const uint8_t *)dest->planes[1], (const uint8_t *)dest->planes[2],
|
|
||||||
dest->stride[0], dest->stride[1], dest->stride[2], vc->vcb.second);
|
|
||||||
}
|
|
||||||
|
|
||||||
vpx_img_free(dest); // is this needed? none of the VPx examples show that
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
LOGGER_TRACE(vc->log, "no Video frame data available");
|
LOGGER_TRACE(vc->log, "no Video frame data available");
|
||||||
|
pthread_mutex_unlock(vc->queue_mutex);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(vc->queue_mutex);
|
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);
|
||||||
|
} else {
|
||||||
|
full_data_len = p->len;
|
||||||
|
LOGGER_DEBUG(vc->log, "vc_iterate:002");
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
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));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Play decoded images */
|
||||||
|
vpx_codec_iter_t iter = nullptr;
|
||||||
|
vpx_image_t *dest = nullptr;
|
||||||
|
|
||||||
|
while ((dest = vpx_codec_get_frame(vc->decoder, &iter)) != nullptr) {
|
||||||
|
if (vc->vcb.first) {
|
||||||
|
vc->vcb.first(vc->av, vc->friend_number, dest->d_w, dest->d_h,
|
||||||
|
(const uint8_t *)dest->planes[0], (const uint8_t *)dest->planes[1], (const uint8_t *)dest->planes[2],
|
||||||
|
dest->stride[0], dest->stride[1], dest->stride[2], vc->vcb.second);
|
||||||
|
}
|
||||||
|
|
||||||
|
vpx_img_free(dest); // is this needed? none of the VPx examples show that
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int vc_queue_message(void *vcp, struct RTPMessage *msg)
|
int vc_queue_message(void *vcp, struct RTPMessage *msg)
|
||||||
|
|
|
@ -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].top_lossy_number = message_number;
|
||||||
g->group[peer_index].bottom_lossy_number = (message_number - MAX_LOSSY_COUNT) + 1;
|
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;
|
g->group[peer_index].recv_lossy[message_number % MAX_LOSSY_COUNT] = 1;
|
||||||
|
|
||||||
return 0;
|
|
||||||
} else { // top_distance < MAX_LOSSY_COUNT
|
} else { // top_distance < MAX_LOSSY_COUNT
|
||||||
unsigned int i;
|
for (unsigned int i = g->group[peer_index].bottom_lossy_number;
|
||||||
|
i != g->group[peer_index].bottom_lossy_number + top_distance;
|
||||||
for (i = g->group[peer_index].bottom_lossy_number; i != (g->group[peer_index].bottom_lossy_number + top_distance);
|
|
||||||
++i) {
|
++i) {
|
||||||
g->group[peer_index].recv_lossy[i % MAX_LOSSY_COUNT] = 0;
|
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].top_lossy_number = message_number;
|
||||||
g->group[peer_index].bottom_lossy_number = (message_number - MAX_LOSSY_COUNT) + 1;
|
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;
|
g->group[peer_index].recv_lossy[message_number % MAX_LOSSY_COUNT] = 1;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata)
|
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