Skip to content

Commit

Permalink
Handle needed RTP packet retransmissions reasonably
Browse files Browse the repository at this point in the history
  • Loading branch information
wberube committed Jul 10, 2024
1 parent 3dc590e commit ee45813
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions src/rtsp/rtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
}

Expand Down

0 comments on commit ee45813

Please sign in to comment.