Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: The logger drops frame with the "Success" status. #2765

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 29 additions & 26 deletions toxav/rtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "../toxcore/ccompat.h"
#include "../toxcore/logger.h"
#include "../toxcore/mono_time.h"
#include "../toxcore/tox.h"
#include "../toxcore/util.h"

/**
Expand All @@ -27,16 +28,12 @@
* return -1 on failure, 0 on success
*
*/
static int rtp_send_custom_lossy_packet(Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t length)
static Tox_Err_Friend_Custom_Packet rtp_send_custom_lossy_packet(Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t length)
{
Tox_Err_Friend_Custom_Packet error;
tox_friend_send_lossy_packet(tox, friendnumber, data, (size_t)length, &error);

if (error == TOX_ERR_FRIEND_CUSTOM_PACKET_OK) {
return 0;
}

return -1;
return error;
}

// allocate_len is NOT including header!
Expand Down Expand Up @@ -818,12 +815,8 @@ int rtp_send_data(RTPSession *session, const uint8_t *data, uint32_t length,
rtp_header_pack(rdata + 1, &header);
memcpy(rdata + 1 + RTP_HEADER_SIZE, data, length);

if (-1 == rtp_send_custom_lossy_packet(session->tox, session->friend_number, rdata, rdata_size)) {
char *netstrerror = net_new_strerror(net_error());
LOGGER_WARNING(session->m->log, "RTP send failed (len: %u)! net error: %s",
rdata_size, netstrerror);
net_kill_strerror(netstrerror);
}
const Tox_Err_Friend_Custom_Packet error = rtp_send_custom_lossy_packet(session->tox, session->friend_number, rdata, rdata_size);
rtp_report_error_maybe(error, session, rdata_size);
} else {
/*
* The length is greater than the maximum allowed length (including header)
Expand All @@ -836,13 +829,9 @@ int rtp_send_data(RTPSession *session, const uint8_t *data, uint32_t length,
rtp_header_pack(rdata + 1, &header);
memcpy(rdata + 1 + RTP_HEADER_SIZE, data + sent, piece);

if (-1 == rtp_send_custom_lossy_packet(session->tox, session->friend_number,
rdata, piece + RTP_HEADER_SIZE + 1)) {
char *netstrerror = net_new_strerror(net_error());
LOGGER_WARNING(session->m->log, "RTP send failed (len: %d)! net error: %s",
piece + RTP_HEADER_SIZE + 1, netstrerror);
net_kill_strerror(netstrerror);
}
const Tox_Err_Friend_Custom_Packet error = rtp_send_custom_lossy_packet(session->tox, session->friend_number,
rdata, piece + RTP_HEADER_SIZE + 1);
rtp_report_error_maybe(error, session, piece + RTP_HEADER_SIZE + 1);

sent += piece;
header.offset_lower = sent;
Expand All @@ -856,16 +845,30 @@ int rtp_send_data(RTPSession *session, const uint8_t *data, uint32_t length,
rtp_header_pack(rdata + 1, &header);
memcpy(rdata + 1 + RTP_HEADER_SIZE, data + sent, piece);

if (-1 == rtp_send_custom_lossy_packet(session->tox, session->friend_number, rdata,
piece + RTP_HEADER_SIZE + 1)) {
char *netstrerror = net_new_strerror(net_error());
LOGGER_WARNING(session->m->log, "RTP send failed (len: %d)! net error: %s",
piece + RTP_HEADER_SIZE + 1, netstrerror);
net_kill_strerror(netstrerror);
}
const Tox_Err_Friend_Custom_Packet error = rtp_send_custom_lossy_packet(session->tox, session->friend_number, rdata,
piece + RTP_HEADER_SIZE + 1);
rtp_report_error_maybe(error, session, piece + RTP_HEADER_SIZE + 1);
}
}

++session->sequnum;
return 0;
}

/**
* Log the neterror error if any.
*
* @param error the error from rtp_send_custom_lossy_packet.
* @param session The A/V session to send the data for.
* @param rdata_size The package length to be shown in the log.
*/
void rtp_report_error_maybe(Tox_Err_Friend_Custom_Packet error, RTPSession *session, uint16_t rdata_size)
{
if (TOX_ERR_FRIEND_CUSTOM_PACKET_OK != error) {
char *netstrerror = net_new_strerror(net_error());
const char *toxerror = tox_err_friend_custom_packet_to_string(error);
LOGGER_WARNING(session->m->log, "RTP send failed (len: %u)! tox error: %s net error: %s",
rdata_size, toxerror, netstrerror);
net_kill_strerror(netstrerror);
}
}
8 changes: 8 additions & 0 deletions toxav/rtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ int rtp_stop_receiving(RTPSession *session);
*/
int rtp_send_data(RTPSession *session, const uint8_t *data, uint32_t length,
bool is_keyframe, const Logger *log);
/**
* Log the neterror error if any.
*
* @param error the error from rtp_send_custom_lossy_packet.
* @param session The A/V session to send the data for.
* @param rdata_size The package length to be shown in the log.
*/
void rtp_report_error_maybe(Tox_Err_Friend_Custom_Packet error, RTPSession *session, uint16_t rdata_size);

#ifdef __cplusplus
} /* extern "C" */
Expand Down