Skip to content

Commit e32ac00

Browse files
nickolay168iphydf
authored andcommitted
fix: Add more information on why the frame was not sent.
1 parent ab88700 commit e32ac00

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

toxav/rtp.c

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

77
#include <assert.h>
8-
#include <errno.h>
98
#include <stdlib.h>
109
#include <string.h>
1110

@@ -768,22 +767,35 @@ void rtp_stop_receiving(Tox *tox)
768767
tox_callback_friend_lossy_packet_per_pktid(tox, nullptr, RTP_TYPE_VIDEO);
769768
}
770769

770+
/**
771+
* Log the neterror error if any.
772+
*
773+
* @param error the error from rtp_send_custom_lossy_packet.
774+
* @param rdata_size The package length to be shown in the log.
775+
*/
776+
static void rtp_report_error_maybe(const Logger *log, Tox_Err_Friend_Custom_Packet error, uint16_t rdata_size)
777+
{
778+
if (error != TOX_ERR_FRIEND_CUSTOM_PACKET_OK) {
779+
char *netstrerror = net_new_strerror(net_error());
780+
const char *toxerror = tox_err_friend_custom_packet_to_string(error);
781+
LOGGER_WARNING(log, "RTP send failed (len: %u)! tox error: %s net error: %s",
782+
rdata_size, toxerror, netstrerror);
783+
net_kill_strerror(netstrerror);
784+
}
785+
}
786+
771787
static void rtp_send_piece(const Logger *log, Tox *tox, uint32_t friend_number, const struct RTPHeader *header,
772788
const uint8_t *data, uint8_t *rdata, uint16_t length)
773789
{
774790
rtp_header_pack(rdata + 1, header);
775791
memcpy(rdata + 1 + RTP_HEADER_SIZE, data, length);
776792

793+
const uint16_t rdata_size = length + RTP_HEADER_SIZE + 1;
794+
777795
Tox_Err_Friend_Custom_Packet error;
778-
tox_friend_send_lossy_packet(tox, friend_number,
779-
rdata, length + RTP_HEADER_SIZE + 1, &error);
796+
tox_friend_send_lossy_packet(tox, friend_number, rdata, rdata_size, &error);
780797

781-
if (error != TOX_ERR_FRIEND_CUSTOM_PACKET_OK) {
782-
char *netstrerror = net_new_strerror(net_error());
783-
LOGGER_WARNING(log, "RTP send failed (len: %d)! tox error: %s, net error: %s",
784-
length + RTP_HEADER_SIZE + 1, tox_err_friend_custom_packet_to_string(error), netstrerror);
785-
net_kill_strerror(netstrerror);
786-
}
798+
rtp_report_error_maybe(log, error, rdata_size);
787799
}
788800

789801
static struct RTPHeader rtp_default_header(const RTPSession *session, uint32_t length, bool is_keyframe)

0 commit comments

Comments
 (0)