diff --git a/daemon/sdp.c b/daemon/sdp.c index 3c8739797..10dfaca06 100644 --- a/daemon/sdp.c +++ b/daemon/sdp.c @@ -2127,15 +2127,14 @@ static void insert_codec_parameters(GString *s, struct call_media *cm, flags, cm->type_id); /* fmtp */ - bool added = false; + g_autoptr(GString) fmtp = NULL; if (pt->codec_def && pt->codec_def->format_print) { - g_autoptr(GString) s_dst = g_string_new(""); - added = pt->codec_def->format_print(s_dst, pt); /* try appending list of parameters */ - if (s_dst->len) + fmtp = pt->codec_def->format_print(pt); /* try appending list of parameters */ + if (fmtp && fmtp->len) append_int_tagged_attr_to_gstring(s, "fmtp", pt->payload_type, - &STR_INIT_GS(s_dst), flags, cm->type_id); + &STR_INIT_GS(fmtp), flags, cm->type_id); } - if (!added && pt->format_parameters.len) + if (!fmtp && pt->format_parameters.len) append_int_tagged_attr_to_gstring(s, "fmtp", pt->payload_type, &pt->format_parameters, flags, cm->type_id); diff --git a/lib/codeclib.c b/lib/codeclib.c index b0e1f6377..e02479e22 100644 --- a/lib/codeclib.c +++ b/lib/codeclib.c @@ -2331,11 +2331,11 @@ static int opus_format_parse(struct rtp_codec_format *f, const str *fmtp) { codeclib_key_value_parse(fmtp, true, opus_parse_format_cb, &f->parsed); return 0; } -static bool opus_format_print(GString *s, const struct rtp_payload_type *p) { +static GString *opus_format_print(const struct rtp_payload_type *p) { if (!p->format.fmtp_parsed) - return false; + return NULL; - gsize orig = s->len; + GString *s = g_string_new(""); __auto_type f = &p->format.parsed.opus; if (f->stereo_recv) @@ -2357,10 +2357,10 @@ static bool opus_format_print(GString *s, const struct rtp_payload_type *p) { if (f->minptime) g_string_append_printf(s, "minptime=%i; ", f->minptime); - if (orig != s->len) + if (s->len != 0) g_string_truncate(s, s->len - 2); - return true; + return s; } static void opus_format_answer(struct rtp_payload_type *p, const struct rtp_payload_type *src) { if (!p->format.fmtp_parsed) @@ -3618,12 +3618,12 @@ static void evs_format_print_bw(GString *s, const char *k, enum evs_bw min, enum g_string_append(s, evs_bw_strings[max]); g_string_append(s, "; "); } -static bool evs_format_print(GString *s, const struct rtp_payload_type *p) { +static GString *evs_format_print(const struct rtp_payload_type *p) { if (!p->format.fmtp_parsed) return false; + GString *s = g_string_new(""); __auto_type f = &p->format.parsed.evs; - gsize orig_len = s->len; if (f->hf_only) g_string_append(s, "hf-only=1; "); @@ -3664,10 +3664,10 @@ static bool evs_format_print(GString *s, const struct rtp_payload_type *p) { evs_format_print_bw(s, "bw-recv", f->min_bw_recv, f->max_bw_recv); } - if (orig_len != s->len) + if (s->len != 0) g_string_truncate(s, s->len - 2); // remove trailing "; " if anything was printed - return true; + return s; } static void evs_parse_format_cb(str *key, str *token, void *data) { union codec_format_options *opts = data; diff --git a/lib/codeclib.h b/lib/codeclib.h index 4ee4219ca..4cca70477 100644 --- a/lib/codeclib.h +++ b/lib/codeclib.h @@ -42,7 +42,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 *); +typedef GString *format_print_f(const struct rtp_payload_type *); #ifndef WITHOUT_CODECLIB