From f96fb9777d264125ecf2afe5277d752e42573c0f Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Wed, 17 Jan 2024 16:41:35 +0100 Subject: [PATCH] Increase FEC resilliancy with low traffic Duplicate first packet to increase resilliancy in cases when the traffic is low, usually a single packet of some inter-frame compression like H.264/HEVC. But it will similarly do the job when more packets per frame are used. First packet is duplicated instead of the last one because the last packet can have less symbols than the first if there is more than 1 packet, eg. `DDDD|DF` (D - primary data; F - FEC, | - packet bounadry). refers to GH-361 --- src/transmit.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/transmit.cpp b/src/transmit.cpp index 4d87682c9..fd31276ec 100644 --- a/src/transmit.cpp +++ b/src/transmit.cpp @@ -687,13 +687,13 @@ tx_send_base(struct tx *tx, struct video_frame *frame, struct rtp *rtp_session, } vector packet_sizes = get_packet_sizes(frame, substream, tx->mtu - hdrs_len); - const long mult_pkt_cnt = (long) packet_sizes.size() * tx->mult_count; + long mult_pkt_cnt = (long) packet_sizes.size() * tx->mult_count; const long packet_rate = get_packet_rate(tx, frame, (int) substream, mult_pkt_cnt); // initialize header array with values (except offset which is different among // different packts) - void *rtp_headers = malloc(mult_pkt_cnt * rtp_hdr_len); + void *rtp_headers = malloc((mult_pkt_cnt + 1) * rtp_hdr_len); uint32_t *rtp_hdr_packet = (uint32_t *) rtp_headers; for (int m = 0; m < tx->mult_count; ++m) { unsigned pos = 0; @@ -704,6 +704,11 @@ tx_send_base(struct tx *tx, struct video_frame *frame, struct rtp *rtp_session, pos += packet_sizes.at(i); } } + if (frame->fec_params.type != FEC_NONE) { // dup 1st pkt with RS/LDGM + mult_pkt_cnt += 1; + memcpy(rtp_hdr_packet, rtp_hdr, rtp_hdr_len); + rtp_hdr_packet[1] = htonl(0); + } if (!tx->encryption) { rtp_async_start(rtp_session, mult_pkt_cnt);