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

rtp/rtcp: add RTCP Generic NACK packet send (RFC 4585 6.2.1) #1186

Merged
merged 2 commits into from
Sep 5, 2024
Merged
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
2 changes: 2 additions & 0 deletions include/re_rtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ int rtcp_send_app(struct rtp_sock *rs, const char name[4],
const uint8_t *data, size_t len);
int rtcp_send_fir(struct rtp_sock *rs, uint32_t ssrc);
int rtcp_send_nack(struct rtp_sock *rs, uint16_t fsn, uint16_t blp);
int rtcp_send_gnack(struct rtp_sock *rs, uint32_t ssrc, uint16_t fsn,
uint16_t blp);
int rtcp_send_pli(struct rtp_sock *rs, uint32_t fb_ssrc);
int rtcp_send_fir_rfc5104(struct rtp_sock *rs, uint32_t ssrc,
uint8_t fir_seqn);
Expand Down
30 changes: 30 additions & 0 deletions src/rtp/rtcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,36 @@ int rtcp_send_nack(struct rtp_sock *rs, uint16_t fsn, uint16_t blp)
}


static int encode_gnack(struct mbuf *mb, void *arg)
{
struct gnack *fci = arg;

int err = mbuf_write_u16(mb, htons(fci->pid));
err |= mbuf_write_u16(mb, htons(fci->blp));
return err;
}


/**
* Send an RTCP Generic NACK packet (RFC 4585 6.2.1)
*
* @param rs RTP Socket
* @param ssrc SSRC of the target encoder
* @param fsn First Sequence Number lost
* @param blp Bitmask of lost packets
*
* @return 0 for success, otherwise errorcode
*/
int rtcp_send_gnack(struct rtp_sock *rs, uint32_t ssrc, uint16_t fsn,
uint16_t blp)
{
struct gnack fci = {fsn, blp};
return rtcp_quick_send(rs, RTCP_RTPFB, RTCP_RTPFB_GNACK,
rtp_sess_ssrc(rs), ssrc, &encode_gnack,
&fci);
}


/**
* Send an RTCP Picture Loss Indication (PLI) packet
*
Expand Down
13 changes: 13 additions & 0 deletions test/rtcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ struct agent {
struct sa laddr_rtcp;
unsigned rtp_count;
unsigned psfb_count;
unsigned rtpfb_count;
unsigned gnack_count;
};


Expand All @@ -222,6 +224,12 @@ static void rtcp_recv_handler(const struct sa *src, struct rtcp_msg *msg,

switch (msg->hdr.pt) {

case RTCP_RTPFB:
if (msg->r.fb.fci.gnackv->pid == 42)
++ag->gnack_count;
++ag->rtpfb_count;
break;

case RTCP_PSFB:
++ag->psfb_count;
re_cancel();
Expand Down Expand Up @@ -266,6 +274,9 @@ static int test_rtcp_loop_base(bool mux)
rtcp_start(a.rtp_sock, "cname", &b.laddr_rtcp);
rtcp_start(b.rtp_sock, "cname", &a.laddr_rtcp);

err = rtcp_send_gnack(a.rtp_sock, rtp_sess_ssrc(b.rtp_sock), 42, 0);
TEST_ERR(err);

err = rtcp_send_pli(a.rtp_sock, rtp_sess_ssrc(b.rtp_sock));
TEST_ERR(err);

Expand All @@ -276,6 +287,8 @@ static int test_rtcp_loop_base(bool mux)
ASSERT_EQ(0, a.psfb_count);
ASSERT_EQ(0, b.rtp_count);
ASSERT_EQ(1, b.psfb_count);
ASSERT_EQ(1, b.rtpfb_count);
ASSERT_EQ(1, b.gnack_count);

out:
mem_deref(b.rtp_sock);
Expand Down
Loading