MT#55283 simplify fmtp printing

As we don't directly append to an existing GString any more anyway,
simplify the function signature by just returning a new GString if the
format string is known.

Change-Id: I9f8e6fbd93ea063eecb519cd57366effd4022f75
pull/1786/head
Richard Fuchs 1 year ago
parent 9ce741daee
commit 1a11d9fbab

@ -2127,15 +2127,14 @@ static void insert_codec_parameters(GString *s, struct call_media *cm,
flags, cm->type_id); flags, cm->type_id);
/* fmtp */ /* fmtp */
bool added = false; g_autoptr(GString) fmtp = NULL;
if (pt->codec_def && pt->codec_def->format_print) { if (pt->codec_def && pt->codec_def->format_print) {
g_autoptr(GString) s_dst = g_string_new(""); fmtp = pt->codec_def->format_print(pt); /* try appending list of parameters */
added = pt->codec_def->format_print(s_dst, pt); /* try appending list of parameters */ if (fmtp && fmtp->len)
if (s_dst->len)
append_int_tagged_attr_to_gstring(s, "fmtp", pt->payload_type, 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, append_int_tagged_attr_to_gstring(s, "fmtp", pt->payload_type,
&pt->format_parameters, flags, cm->type_id); &pt->format_parameters, flags, cm->type_id);

@ -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); codeclib_key_value_parse(fmtp, true, opus_parse_format_cb, &f->parsed);
return 0; 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) 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; __auto_type f = &p->format.parsed.opus;
if (f->stereo_recv) if (f->stereo_recv)
@ -2357,10 +2357,10 @@ static bool opus_format_print(GString *s, const struct rtp_payload_type *p) {
if (f->minptime) if (f->minptime)
g_string_append_printf(s, "minptime=%i; ", 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); 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) { static void opus_format_answer(struct rtp_payload_type *p, const struct rtp_payload_type *src) {
if (!p->format.fmtp_parsed) 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, evs_bw_strings[max]);
g_string_append(s, "; "); 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) if (!p->format.fmtp_parsed)
return false; return false;
GString *s = g_string_new("");
__auto_type f = &p->format.parsed.evs; __auto_type f = &p->format.parsed.evs;
gsize orig_len = s->len;
if (f->hf_only) if (f->hf_only)
g_string_append(s, "hf-only=1; "); 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); 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 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) { static void evs_parse_format_cb(str *key, str *token, void *data) {
union codec_format_options *opts = data; union codec_format_options *opts = data;

@ -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 compatible with b (not necessarily the other way around)
// -1: a is not compatible with b // -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 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 #ifndef WITHOUT_CODECLIB

Loading…
Cancel
Save