From c815f35f8825288ef32518a6fbb7637b761a6909 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 12 Oct 2022 13:37:14 -0400 Subject: [PATCH] MT#55447 add dedicated format printing function Change-Id: I19485a331afa4c1bee98317ca4b8a73b0e3deeae --- daemon/sdp.c | 21 ++++++++++++++++++++- lib/codeclib.h | 3 +++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/daemon/sdp.c b/daemon/sdp.c index 5ce06fa33..61a24dca2 100644 --- a/daemon/sdp.c +++ b/daemon/sdp.c @@ -1864,11 +1864,30 @@ static void insert_codec_parameters(GString *s, struct call_media *cm) { g_string_append_printf(s, "a=rtpmap:%u " STR_FORMAT "\r\n", pt->payload_type, STR_FMT(&pt->encoding_with_params)); - if (pt->format_parameters.len) { + + bool check_format = true; + if (pt->codec_def && pt->codec_def->format_print) { + gsize prev_len = s->len; + g_string_append_printf(s, "a=fmtp:%u ", pt->payload_type); + gsize fmtp_len = s->len; + bool success = pt->codec_def->format_print(s, pt); + if (!success) + g_string_truncate(s, prev_len); // backtrack + else { + check_format = false; // done with this + // anything printed? + if (s->len == fmtp_len) + g_string_truncate(s, prev_len); // backtrack + else + g_string_append(s, "\r\n"); + } + } + if (check_format && pt->format_parameters.len) { g_string_append_printf(s, "a=fmtp:%u " STR_FORMAT "\r\n", pt->payload_type, STR_FMT(&pt->format_parameters)); } + for (GList *l = pt->rtcp_fb.head; l; l = l->next) { str *fb = l->data; g_string_append_printf(s, "a=rtcp-fb:%u " STR_FORMAT "\r\n", diff --git a/lib/codeclib.h b/lib/codeclib.h index 3b9e3a05d..3a039d542 100644 --- a/lib/codeclib.h +++ b/lib/codeclib.h @@ -40,6 +40,7 @@ INLINE enum media_type codec_get_type(const str *type) { // 1: a is compatible with b (not necessarily the other way around) // -1: a is not compatible with b typedef int format_cmp_f(const struct rtp_payload_type *a, const struct rtp_payload_type *b); +typedef bool format_print_f(GString *, const struct rtp_payload_type *); #ifndef WITHOUT_CODECLIB @@ -143,6 +144,7 @@ struct codec_def_s { const char *default_fmtp; format_parse_f * const format_parse; format_cmp_f * const format_cmp; + format_print_f * const format_print; packetizer_f * const packetizer; const int bits_per_sample; const enum media_type media_type; @@ -402,6 +404,7 @@ struct codec_def_s { int dtmf; int supplemental; format_cmp_f * const format_cmp; + format_print_f * const format_print; const str silence_pattern; }; struct packet_sequencer_s {