From 8c995885506e1ab5c60cf7060d3812a8634f1932 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 15 Jan 2024 13:36:20 -0500 Subject: [PATCH] MT#55283 directly print T.38 attributes Make sure sdp_attributes is only used for _received_ SDP attributes, and not ones that we want to send out. The only places where self-generated attributes are being used is the T.38 gateway. Change-Id: I1f035cd42a35fa250ea477700a1a88ad59efcc38 --- daemon/sdp.c | 11 +++++++++++ daemon/t38.c | 41 ++++++++++++++++++++++++----------------- include/sdp.h | 5 +++++ 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/daemon/sdp.c b/daemon/sdp.c index 39a9cca93..2d43a197b 100644 --- a/daemon/sdp.c +++ b/daemon/sdp.c @@ -425,6 +425,17 @@ static void append_tagged_attr_to_gstring(GString *s, const char * name, const s static void append_int_tagged_attr_to_gstring(GString *s, const char * name, unsigned int tag, const str * value, const sdp_ng_flags *flags, enum media_type media_type); +void sdp_append_str_attr(GString *s, const sdp_ng_flags *flags, enum media_type media_type, + const str *name, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + g_autoptr(GString) gs = g_string_new(""); + g_string_vprintf(gs, fmt, ap); + va_end(ap); + append_str_attr_to_gstring(s, name, &STR_INIT_GS(gs), flags, media_type); +} + INLINE void append_attr_to_gstring(GString *s, const char * name, const str * value, const sdp_ng_flags *flags, enum media_type media_type) { diff --git a/daemon/t38.c b/daemon/t38.c index a409aa518..e2460822b 100644 --- a/daemon/t38.c +++ b/daemon/t38.c @@ -332,6 +332,28 @@ static int span_log_level_map(int level) { return level; } +void t38_insert_media_attributes(GString *gs, union sdp_attr_print_arg a, const sdp_ng_flags *flags) { + struct t38_gateway *tg = a.cm->t38_gateway; + if (!tg) + return; + + sdp_append_attr(gs, flags, MT_IMAGE, "T38FaxVersion", "%i", tg->options.version); + sdp_append_attr(gs, flags, MT_IMAGE, "T38MaxBitRate", "14400"); + sdp_append_attr(gs, flags, MT_IMAGE, "T38FaxRateManagement", "%s", + tg->options.local_tcf ? "localTFC" : "transferredTCF"); + sdp_append_attr(gs, flags, MT_IMAGE, "T38FaxMaxBuffer", "1800"); + sdp_append_attr(gs, flags, MT_IMAGE, "T38FaxMaxDatagram", "512"); + + if (tg->options.max_ec_entries == 0) + sdp_append_attr(gs, flags, MT_IMAGE, "T38FaxUdpEC", "t38UDPNoEC"); + else if (tg->options.fec_span > 1) + sdp_append_attr(gs, flags, MT_IMAGE, "T38FaxUdpEC", "t38UDPFEC"); + else + sdp_append_attr(gs, flags, MT_IMAGE, "T38FaxUdpEC", "t38UDPRedundancy"); + // XXX more options possible here +} + + // call is locked in W int t38_gateway_pair(struct call_media *t38_media, struct call_media *pcm_media, const struct t38_options *options) @@ -423,22 +445,7 @@ int t38_gateway_pair(struct call_media *t38_media, struct call_media *pcm_media, pcm_media->t38_gateway = obj_get(tg); // add SDP options for T38 - t_queue_clear_full(&t38_media->sdp_attributes, str_free); - - t_queue_push_tail(&t38_media->sdp_attributes, str_sprintf("T38FaxVersion:%i", tg->options.version)); - t_queue_push_tail(&t38_media->sdp_attributes, str_sprintf("T38MaxBitRate:14400")); - t_queue_push_tail(&t38_media->sdp_attributes, str_sprintf("T38FaxRateManagement:%s", - tg->options.local_tcf ? "localTFC" : "transferredTCF")); - t_queue_push_tail(&t38_media->sdp_attributes, str_sprintf("T38FaxMaxBuffer:1800")); - t_queue_push_tail(&t38_media->sdp_attributes, str_sprintf("T38FaxMaxDatagram:512")); - - if (tg->options.max_ec_entries == 0) - t_queue_push_tail(&t38_media->sdp_attributes, str_sprintf("T38FaxUdpEC:t38UDPNoEC")); - else if (tg->options.fec_span > 1) - t_queue_push_tail(&t38_media->sdp_attributes, str_sprintf("T38FaxUdpEC:t38UDPFEC")); - else - t_queue_push_tail(&t38_media->sdp_attributes, str_sprintf("T38FaxUdpEC:t38UDPRedundancy")); - // XXX more options possible here + t38_media->sdp_attr_print = t38_insert_media_attributes; return 0; @@ -771,7 +778,7 @@ void t38_gateway_stop(struct t38_gateway *tg) { if (tg->pcm_player) media_player_stop(tg->pcm_player); if (tg->t38_media) - t_queue_clear_full(&tg->t38_media->sdp_attributes, str_free); + tg->t38_media->sdp_attr_print = sdp_insert_media_attributes; } diff --git a/include/sdp.h b/include/sdp.h index f3264f23b..0703fbfba 100644 --- a/include/sdp.h +++ b/include/sdp.h @@ -42,6 +42,11 @@ void sdp_init(void); sdp_attr_print_f sdp_insert_media_attributes; sdp_attr_print_f sdp_insert_monologue_attributes; +void sdp_append_str_attr(GString *s, const sdp_ng_flags *flags, enum media_type media_type, + const str *name, const char *fmt, ...) + __attribute__ ((format (printf, 5, 6))); +#define sdp_append_attr(s, g, t, n, f, ...) sdp_append_str_attr(s, g, t, &STR_INIT(n), f, ##__VA_ARGS__) + int sdp_parse(str *body, sdp_sessions_q *sessions, const sdp_ng_flags *); int sdp_streams(const sdp_sessions_q *sessions, sdp_streams_q *streams, sdp_ng_flags *); void sdp_streams_clear(sdp_streams_q *);