From af4ca41edbf105f269f86ac1afac870195fb5247 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 2 Sep 2025 13:48:17 -0400 Subject: [PATCH] MT#63317 support filtering of extensions Change-Id: Iac4fa87b89dc7d011115d149f8cfd4c74cd1ca7a --- daemon/media_socket.c | 33 +++++++++++++++++++++++++++++++++ t/auto-daemon-tests-rtp-ext.pl | 10 +++++----- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 432a2ab6f..714deb116 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -2078,6 +2078,14 @@ const struct rtpext_printer rtpext_printer_copy = { }; + +static bool extmap_has_ext(const struct media_packet *mp, const struct rtp_extension_data *ext) { + if (!mp->media_out->extmap_ops->lookup(mp->media_out, ext->ext->id)) + return false; + return true; +} + + static size_t rtpext_printer_extmap_length(const struct media_packet *mp) { if (mp->rtcp) return 0; @@ -2102,6 +2110,8 @@ static size_t rtpext_printer_extmap_print(struct rtp_header *rh, void *dst, cons return 0; if (!mp->extmap.length) return 0; + if (!mp->media_out || !mp->media_out->extmap.length) + return 0; // no extensions __auto_type media = mp->media_out; if (!media) @@ -2113,6 +2123,10 @@ static size_t rtpext_printer_extmap_print(struct rtp_header *rh, void *dst, cons for (__auto_type l = mp->extmap.head; l; l = l->next) { __auto_type ext = l->data; + + if (!extmap_has_ext(mp, ext)) + continue; + size_t len = media->extmap_ops->print(dst, ext); dst += len; } @@ -2158,16 +2172,24 @@ static bool extmap_short_is_valid(const struct rtp_extension_data *ext) { } size_t extmap_length_short(const struct media_packet *mp) { + if (!mp->media_out || !mp->media_out->extmap.length) + return 0; // no extensions + const extmap_data_q *q = &mp->extmap; size_t ret = 4; // 0xbede + int16 length for (__auto_type l = q->head; l; l = l->next) { __auto_type ext = l->data; + + if (!extmap_has_ext(mp, ext)) + continue; + if (!extmap_short_is_valid(ext)) { ilog(LOG_WARN | LOG_FLAG_LIMIT, "RTP extension with id %d length %zu not valid " "for short form", ext->ext->id, ext->content.len); continue; } + ret++; // 1-byte header ret += ext->content.len; } @@ -2206,20 +2228,31 @@ static bool extmap_long_is_valid(const struct rtp_extension_data *ext) { } size_t extmap_length_long(const struct media_packet *mp) { + if (!mp->media_out || !mp->media_out->extmap.length) + return 0; // no extensions + const extmap_data_q *q = &mp->extmap; size_t ret = 4; // 0x0100 + int16 length for (__auto_type l = q->head; l; l = l->next) { __auto_type ext = l->data; + + if (!extmap_has_ext(mp, ext)) + continue; + if (!extmap_long_is_valid(ext)) { ilog(LOG_WARN | LOG_FLAG_LIMIT, "RTP extension with id %d length %zu not valid " "for long form", ext->ext->id, ext->content.len); continue; } + ret += 2; // 2-byte header ret += ext->content.len; } + if (ret == 4) + return 0; // nothing left + return ret; } diff --git a/t/auto-daemon-tests-rtp-ext.pl b/t/auto-daemon-tests-rtp-ext.pl index 66283101c..68e6774c9 100755 --- a/t/auto-daemon-tests-rtp-ext.pl +++ b/t/auto-daemon-tests-rtp-ext.pl @@ -438,7 +438,7 @@ SDP snd($sock_a, $port_b, rtp( 8, 1000, 3000+160*0, 0x1234, "\x10" . ("\x00" x 158) . "\x50", [[1, "foo"], [2, "woot"], [3, "meh"], [4, "yugh"]])); rcv($sock_b, $port_a, rtpm(8, 1000, 3000+160*0, 0x1234, "\x10" . ("\x00" x 158) . "\x50", [[2, "woot"]])); snd($sock_b, $port_a, rtp( 8, 8000, 7000+160*0, 0x6543, "\x10" . ("\x00" x 158) . "\x50", [[1, "foo"], [2, "woot"], [3, "meh"], [4, "yugh"]])); -rcv($sock_a, $port_b, rtpm(8, 8000, 7000+160*0, 0x6543, "\x10" . ("\x00" x 158) . "\x50", [[1, "foo"], [2, "woot"]])); # XXX should be just 2 ? +rcv($sock_a, $port_b, rtpm(8, 8000, 7000+160*0, 0x6543, "\x10" . ("\x00" x 158) . "\x50", [[2, "woot"]])); @@ -505,7 +505,7 @@ a=rtcp:PORT SDP snd($sock_a, $port_b, rtp( 8, 1000, 3000+160*0, 0x1234, "\x39" . ("\x29" x 158) . "\x74", [[1, "foo"], [2, "blah"], [4, "argh"], [3, "yikes"]])); -rcv($sock_b, $port_a, rtpm(8, 1000, 3000+160*0, 0x1234, "\x39" . ("\x29" x 158) . "\x74", [[1, "foo"], [2, "blah"], [3, "yikes"]])); +rcv($sock_b, $port_a, rtpm(8, 1000, 3000+160*0, 0x1234, "\x39" . ("\x29" x 158) . "\x74", [[1, "foo"], [2, "blah"]])); snd($sock_b, $port_a, rtp( 8, 8000, 7000+160*0, 0x6543, "\x39" . ("\x29" x 158) . "\x74", [[1, "foo"], [2, "blah"], [4, "argh"], [3, "yikes"]])); rcv($sock_a, $port_b, rtpm(8, 8000, 7000+160*0, 0x6543, "\x39" . ("\x29" x 158) . "\x74", [[1, "foo"], [2, "blah"]])); @@ -579,7 +579,7 @@ a=rtcp:PORT SDP snd($sock_a, $port_b, rtp( 8, 1000, 3000+160*0, 0x1234, "\x39" . ("\x29" x 158) . "\x74", [[1, "foo"], [2, "blah"], [4, "argh"], [3, "yikes"]])); -rcv($sock_b, $port_a, rtpm(0, 1000, 3000+160*0, 0x1234, "\x13" . ("\x03" x 158) . "\x5a", [[1, "foo"], [2, "blah"], [3, "yikes"]])); +rcv($sock_b, $port_a, rtpm(0, 1000, 3000+160*0, 0x1234, "\x13" . ("\x03" x 158) . "\x5a", [[1, "foo"], [2, "blah"]])); snd($sock_b, $port_a, rtp( 0, 8000, 7000+160*0, 0x6543, "\x39" . ("\x29" x 158) . "\x74", [[1, "foo"], [2, "blah"], [4, "argh"], [3, "yikes"]])); rcv($sock_a, $port_b, rtpm(8, 8000, 7000+160*0, 0x6543, "\x10" . ("\x00" x 158) . "\x50", [[1, "foo"], [2, "blah"]])); @@ -649,7 +649,7 @@ a=rtcp:PORT SDP snd($sock_a, $port_b, rtp( 8, 1000, 3000+160*0, 0x1234, "\x39" . ("\x29" x 158) . "\x74", [[18, "foo"], [19, "blah"], [21, "argh"], [20, "yikes"]])); -rcv($sock_b, $port_a, rtpm(8, 1000, 3000+160*0, 0x1234, "\x39" . ("\x29" x 158) . "\x74", [[18, "foo"], [19, "blah"], [20, "yikes"]])); +rcv($sock_b, $port_a, rtpm(8, 1000, 3000+160*0, 0x1234, "\x39" . ("\x29" x 158) . "\x74", [[18, "foo"], [19, "blah"]])); snd($sock_b, $port_a, rtp( 8, 8000, 7000+160*0, 0x6543, "\x39" . ("\x29" x 158) . "\x74", [[18, "foo"], [19, "blah"], [21, "argh"], [20, "yikes"]])); rcv($sock_a, $port_b, rtpm(8, 8000, 7000+160*0, 0x6543, "\x39" . ("\x29" x 158) . "\x74", [[18, "foo"], [19, "blah"]])); @@ -723,7 +723,7 @@ a=rtcp:PORT SDP snd($sock_a, $port_b, rtp( 8, 1000, 3000+160*0, 0x1234, "\x39" . ("\x29" x 158) . "\x74", [[18, "foo"], [19, "blah"], [21, "argh"], [20, "yikes"]])); -rcv($sock_b, $port_a, rtpm(0, 1000, 3000+160*0, 0x1234, "\x13" . ("\x03" x 158) . "\x5a", [[18, "foo"], [19, "blah"], [20, "yikes"]])); +rcv($sock_b, $port_a, rtpm(0, 1000, 3000+160*0, 0x1234, "\x13" . ("\x03" x 158) . "\x5a", [[18, "foo"], [19, "blah"]])); snd($sock_b, $port_a, rtp( 0, 8000, 7000+160*0, 0x6543, "\x39" . ("\x29" x 158) . "\x74", [[18, "foo"], [19, "blah"], [21, "argh"], [20, "yikes"]])); rcv($sock_a, $port_b, rtpm(8, 8000, 7000+160*0, 0x6543, "\x10" . ("\x00" x 158) . "\x50", [[18, "foo"], [19, "blah"]]));