From f934f7737df90078333956fb9bddd8c37311af65 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 1 Sep 2025 11:13:04 -0400 Subject: [PATCH] MT#63317 support long form extension printing Change-Id: Ib1f1d51dcf6ac0c74fdeb92311bd04d72bf7e7c2 --- daemon/call.c | 3 +++ daemon/media_socket.c | 46 ++++++++++++++++++++++++++++++++++++++++++ include/media_socket.h | 4 ++++ 3 files changed, 53 insertions(+) diff --git a/daemon/call.c b/daemon/call.c index 44d69b17c..edc0dd3a9 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -676,6 +676,9 @@ static const struct extmap_ops extmap_ops_short = { }; static const struct extmap_ops extmap_ops_long = { .lookup = call_media_ext_lookup_ht, + .length = extmap_length_long, + .header = extmap_header_long, + .print = extmap_print_long, }; diff --git a/daemon/media_socket.c b/daemon/media_socket.c index a48e04cc9..432a2ab6f 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -2197,6 +2197,52 @@ size_t extmap_print_short(void *_dst, const struct rtp_extension_data *ext) { +static bool extmap_long_is_valid(const struct rtp_extension_data *ext) { + if (ext->ext->id <= 0 || ext->ext->id >= 256) + return false; + if (ext->content.len > 255) + return false; + return true; +} + +size_t extmap_length_long(const struct media_packet *mp) { + 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_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; + } + + return ret; +} + +void extmap_header_long(void *_dst) { + unsigned char *dst = _dst; + dst[0] = 0x10; + dst[1] = 0x00; +} + +size_t extmap_print_long(void *_dst, const struct rtp_extension_data *ext) { + unsigned char *dst = _dst; + + if (!extmap_long_is_valid(ext)) + return 0; + + dst[0] = ext->ext->id; + dst[1] = ext->content.len; + memcpy(dst + 2, ext->content.s, ext->content.len); + return ext->content.len + 2; +} + + + // `out_media` can be NULL XXX streamline this to remove this exception const struct streamhandler *determine_handler(const struct transport_protocol *in_proto, struct call_media *out_media, bool must_recrypt) diff --git a/include/media_socket.h b/include/media_socket.h index d35b63aa7..ecc90882d 100644 --- a/include/media_socket.h +++ b/include/media_socket.h @@ -329,6 +329,10 @@ size_t extmap_length_short(const struct media_packet *); void extmap_header_short(void *); size_t extmap_print_short(void *, const struct rtp_extension_data *); +size_t extmap_length_long(const struct media_packet *); +void extmap_header_long(void *); +size_t extmap_print_long(void *, const struct rtp_extension_data *); + extern local_intf_q all_local_interfaces; // read-only during runtime