From a608d8bd690e6660da70e5fecd6868bd910a95c2 Mon Sep 17 00:00:00 2001 From: Richard Aas Date: Sun, 5 Dec 2010 15:44:23 +0000 Subject: [PATCH] RFC 5761 - Multiplexing RTP Data and Control Packets on a Single Port --- docs/README | 1 + include/re_rtp.h | 1 + src/rtp/rtp.c | 38 +++++++++++++++++++++++++++++--------- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/docs/README b/docs/README index ff76202..ded92a9 100644 --- a/docs/README +++ b/docs/README @@ -95,6 +95,7 @@ Features: * RFC 5118 - SIP Torture Test Messages for IPv6 * RFC 5245 - Interactive Connectivity Establishment (ICE) * RFC 5389 - Session Traversal Utilities for NAT (STUN) +* RFC 5761 - Multiplexing RTP Data and Control Packets on a Single Port * RFC 5766 - Traversal Using Relays around NAT (TURN) * RFC 5768 - Indicating Support for ICE in SIP * RFC 5769 - Test vectors for STUN diff --git a/include/re_rtp.h b/include/re_rtp.h index ed06c75..fcd5cd9 100644 --- a/include/re_rtp.h +++ b/include/re_rtp.h @@ -212,6 +212,7 @@ const struct sa *rtp_local(const struct rtp_sock *rs); /* RTCP session api */ void rtcp_start(struct rtp_sock *rs, const char *cname, const struct sa *peer); +void rtcp_enable_mux(struct rtp_sock *rs, bool enabled); void rtcp_set_srate(struct rtp_sock *rs, uint32_t sr_tx, uint32_t sr_rx); int rtcp_send_app(struct rtp_sock *rs, const char name[4], const uint8_t *data, size_t len); diff --git a/src/rtp/rtp.c b/src/rtp/rtp.c index 56f6a97..450db42 100644 --- a/src/rtp/rtp.c +++ b/src/rtp/rtp.c @@ -38,6 +38,7 @@ struct rtp_sock { rtcp_recv_h *rtcph; void *arg; struct rtcp_sess *rtcp; + bool rtcp_mux; }; @@ -167,18 +168,27 @@ static void udp_recv_handler(const struct sa *src, struct mbuf *mb, void *arg) { struct rtp_sock *rs = arg; struct rtp_header hdr; - size_t pos; int err; - pos = mb->pos; - err = rtp_decode(rs, mb, &hdr); - if (err) { - /* Not an RTP packet - try RTCP */ - mb->pos = pos; - rtcp_recv_handler(src, mb, arg); - return; + /* Handle RTCP multiplexed on RTP-port */ + if (rs->rtcp_mux) { + uint8_t pt; + + if (mbuf_get_left(mb) < 2) + return; + + pt = mbuf_buf(mb)[1] & 0x7f; + + if (64 <= pt && pt <= 95) { + rtcp_recv_handler(src, mb, arg); + return; + } } + err = rtp_decode(rs, mb, &hdr); + if (err) + return; + if (rs->rtcp) { rtcp_sess_rx_rtp(rs->rtcp, hdr.seq, hdr.ts, hdr.ssrc, mbuf_get_left(mb), src); @@ -444,12 +454,22 @@ void rtcp_start(struct rtp_sock *rs, const char *cname, } +void rtcp_enable_mux(struct rtp_sock *rs, bool enabled) +{ + if (!rs) + return; + + rs->rtcp_mux = enabled; +} + + int rtcp_send(struct rtp_sock *rs, struct mbuf *mb) { if (!rs || !rs->sock_rtcp || !sa_isset(&rs->rtcp_peer, SA_ALL)) return EINVAL; - return udp_send(rs->sock_rtcp, &rs->rtcp_peer, mb); + return udp_send(rs->rtcp_mux ? rs->sock_rtp : rs->sock_rtcp, + &rs->rtcp_peer, mb); }