From ee458133803c597d1cc9a501e4d3c0a2af7fd57b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20B=C3=A9rub=C3=A9?= Date: Wed, 10 Jul 2024 13:51:05 -0400 Subject: [PATCH] Handle needed RTP packet retransmissions reasonably --- src/rtsp/rtp.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/rtsp/rtp.c b/src/rtsp/rtp.c index 83f4e83..be8d632 100644 --- a/src/rtsp/rtp.c +++ b/src/rtsp/rtp.c @@ -158,6 +158,7 @@ static inline int __rtp_send_eachconnection(struct list_t *e, void *v) struct transfer_item_t *trans; struct nal_rtp_t *rtp = v; int track_id = rtp->packet.header.pt == 96 ? 0 : 1; + char attempts = 0; list_upcast(trans,e); @@ -169,26 +170,23 @@ static inline int __rtp_send_eachconnection(struct list_t *e, void *v) rtp->packet.header.ssrc = htonl(con->ssrc); con->trans[track_id].rtp_seq += 1; - send_bytes = send(con->trans[track_id].server_rtp_fd, - &(rtp->packet),rtp->rtpsize,0); + do { + send_bytes = send(con->trans[track_id].server_rtp_fd, + &(rtp->packet),rtp->rtpsize,0); + + if(send_bytes == rtp->rtpsize) { + con->trans[track_id].rtcp_packet_cnt += 1; + con->trans[track_id].rtcp_octet += rtp->rtpsize; + return SUCCESS; + } else if(con->con_state != __CON_S_PLAYING) { + DBG("connection state changed before send\n"); + return SUCCESS; + } else + usleep(1000); + } while (++attempts < 10 && + send_bytes == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)); - if(send_bytes == rtp->rtpsize) { - con->trans[track_id].rtcp_packet_cnt += 1; - con->trans[track_id].rtcp_octet += rtp->rtpsize; - return SUCCESS; - } - - if(con->con_state != __CON_S_PLAYING) { - DBG("connection state changed before send\n"); - return SUCCESS; - } - - if(send_bytes == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)){ - ERR("EAGAIN\n"); - return FAILURE; - } - - ERR("send:%d:%s\n",send_bytes,strerror(errno)); + ERR("send:%d:%s\n", send_bytes, strerror(errno)); return FAILURE; }