From 9c2b349424c49cd94e18c788e6fe9527d04be5d1 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Fri, 2 Jun 2017 22:07:34 +0200 Subject: add RTP Header extension for Client-to-Mixer Audio Level Indication (#264) * add RTP Header extension for Client-to-Mixer Audio Level Indication https://tools.ietf.org/html/rfc6464 requires libre from this commit or later: https://github.com/creytiv/re/commit/1544a1e375c76a80084b411d21b0431f95e9cdfb * fix warnings * fix warnings * minor cleanup --- src/stream.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 6 deletions(-) (limited to 'src/stream.c') diff --git a/src/stream.c b/src/stream.c index acd4766..b9a0d6a 100644 --- a/src/stream.c +++ b/src/stream.c @@ -148,6 +148,61 @@ static void stream_destructor(void *arg) } +static void handle_rtp(struct stream *s, const struct rtp_header *hdr, + struct mbuf *mb) +{ + struct rtpext extv[8]; + size_t extc = 0; + + /* RFC 5285 -- A General Mechanism for RTP Header Extensions */ + if (hdr->ext && hdr->x.len && mb) { + + const size_t pos = mb->pos; + const size_t end = mb->end; + const size_t ext_stop = mb->pos; + size_t ext_len; + size_t i; + int err; + + if (hdr->x.type != RTPEXT_TYPE_MAGIC) { + info("stream: unknown ext type ignored (0x%04x)\n", + hdr->x.type); + goto handler; + } + + ext_len = hdr->x.len*sizeof(uint32_t); + if (mb->pos < ext_len) { + warning("stream: corrupt rtp packet," + " not enough space for rtpext of %zu bytes\n", + ext_len); + return; + } + + mb->pos = mb->pos - ext_len; + mb->end = ext_stop; + + for (i=0; ipos = pos; + mb->end = end; + } + + handler: + s->rtph(hdr, extv, extc, mb, s->arg); + +} + + static void rtp_recv(const struct sa *src, const struct rtp_header *hdr, struct mbuf *mb, void *arg) { @@ -204,17 +259,17 @@ static void rtp_recv(const struct sa *src, const struct rtp_header *hdr, s->jbuf_started = true; if (lostcalc(s, hdr2.seq) > 0) - s->rtph(hdr, NULL, s->arg); + handle_rtp(s, hdr, NULL); - s->rtph(&hdr2, mb2, s->arg); + handle_rtp(s, &hdr2, mb2); mem_deref(mb2); } else { if (lostcalc(s, hdr->seq) > 0) - s->rtph(hdr, NULL, s->arg); + handle_rtp(s, hdr, NULL); - s->rtph(hdr, mb, s->arg); + handle_rtp(s, hdr, mb); } } @@ -419,7 +474,7 @@ static void stream_start_keepalive(struct stream *s) } -int stream_send(struct stream *s, bool marker, int pt, uint32_t ts, +int stream_send(struct stream *s, bool ext, bool marker, int pt, uint32_t ts, struct mbuf *mb) { int err = 0; @@ -438,7 +493,7 @@ int stream_send(struct stream *s, bool marker, int pt, uint32_t ts, pt = s->pt_enc; if (pt >= 0) { - err = rtp_send(s->rtp, sdp_media_raddr(s->sdp), false, + err = rtp_send(s->rtp, sdp_media_raddr(s->sdp), ext, marker, pt, ts, mb); if (err) s->metric_tx.n_err++; -- cgit v1.2.3