From abbc02296f9d0396c268fb5d0987e341e58e473f Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 18 Jun 2024 13:06:12 -0400 Subject: [PATCH] MT#60347 extend allow-asymmetric-codecs ... to be operational and useful on supplemental codecs (DTMF etc) Change-Id: Ifedefb143b984e6bac49dbbd744fe4647891bc7a --- README.md | 4 ++++ daemon/call.c | 3 ++- daemon/codec.c | 31 +++++++++++++++++++++++++------ include/codec.h | 5 ++++- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1d5c99c98d..60f044d4a9 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,10 @@ For quick access, documentation for development: * [Troubleshooting Overview](https://rtpengine.readthedocs.io/en/latest/troubleshooting.html) * [Glossary](https://rtpengine.readthedocs.io/en/latest/glossary.html) +# Sponsors + +* [Dataport AöR](https://www.dataport.de/) + # Contribution Every bit matters. Join us. Make the rtpengine community stronger. diff --git a/daemon/call.c b/daemon/call.c index 2cb63c7f7c..59db528a0f 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -2519,7 +2519,8 @@ static void codecs_answer(struct call_media *media, struct call_media *other_med ilogs(codec, LOG_DEBUG, "Codec answer for " STR_FORMAT " #%u", STR_FMT(&other_media->monologue->tag), other_media->index); - codec_store_answer(&media->codecs, &other_media->codecs, flags); + codec_store_answer(&media->codecs, &other_media->codecs, flags, + .allow_asymmetric = !!flags->allow_asymmetric_codecs); // set up handlers codec_handlers_update(media, other_media, .flags = flags, .sp = sp, diff --git a/daemon/codec.c b/daemon/codec.c index e9d1f1c5c2..87abb2b20d 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -1213,7 +1213,10 @@ void __codec_handlers_update(struct call_media *receiver, struct call_media *sin if (!sink_pt) { // no matching/identical output codec. maybe we have the same output codec, // but with a different payload type or a different format? - sink_pt = codec_store_find_compatible(&sink->codecs, pt); + if (!a.allow_asymmetric) + sink_pt = codec_store_find_compatible(&sink->codecs, pt); + else + sink_pt = pt; } if (sink_pt && !pt->codec_def->supplemental) { @@ -1254,10 +1257,18 @@ void __codec_handlers_update(struct call_media *receiver, struct call_media *sin sink_pt_fixed:; // we have found a usable output codec. gather matching output supp codecs - rtp_payload_type *sink_dtmf_pt = __supp_payload_type(supplemental_sinks, - sink_pt->clock_rate, "telephone-event"); - rtp_payload_type *sink_cn_pt = __supp_payload_type(supplemental_sinks, - sink_pt->clock_rate, "CN"); + rtp_payload_type *sink_dtmf_pt = NULL; + rtp_payload_type *sink_cn_pt = NULL; + if (!a.allow_asymmetric) { + sink_dtmf_pt = __supp_payload_type(supplemental_sinks, + sink_pt->clock_rate, "telephone-event"); + sink_cn_pt = __supp_payload_type(supplemental_sinks, + sink_pt->clock_rate, "CN"); + } + else { + sink_dtmf_pt = recv_dtmf_pt; + sink_cn_pt = recv_cn_pt; + } rtp_payload_type *real_sink_dtmf_pt = NULL; // for DTMF delay // XXX synthesise missing supp codecs according to codec tracker XXX needed? @@ -5201,6 +5212,8 @@ void __codec_store_populate(struct codec_store *dst, struct codec_store *src, st pt->payload_type); continue; } + if (orig_pt->codec_def && orig_pt->codec_def->supplemental) + orig_pt = NULL; } ilogs(codec, LOG_DEBUG, "Adding codec " STR_FORMAT "/" STR_FORMAT " (%i)", STR_FMT(&pt->encoding_with_params), @@ -5558,7 +5571,9 @@ void codec_store_transcode(struct codec_store *cs, str_q *offer, struct codec_st #endif } -void codec_store_answer(struct codec_store *dst, struct codec_store *src, sdp_ng_flags *flags) { +void __codec_store_answer(struct codec_store *dst, struct codec_store *src, sdp_ng_flags *flags, + struct codec_store_args a) +{ // retain existing setup for supplemental codecs, but start fresh otherwise struct codec_store orig_dst; codec_store_move(&orig_dst, dst); @@ -5672,6 +5687,8 @@ void codec_store_answer(struct codec_store *dst, struct codec_store *src, sdp_ng // handle associated supplemental codecs if (h->cn_payload_type != -1) { pt = t_hash_table_lookup(orig_dst.codecs, GINT_TO_POINTER(h->cn_payload_type)); + if (!pt && a.allow_asymmetric) + pt = t_hash_table_lookup(src->codecs, GINT_TO_POINTER(h->cn_payload_type)); if (!pt) ilogs(codec, LOG_DEBUG, "CN payload type %i is missing", h->cn_payload_type); else @@ -5682,6 +5699,8 @@ void codec_store_answer(struct codec_store *dst, struct codec_store *src, sdp_ng dtmf_payload_type = h->real_dtmf_payload_type; if (dtmf_payload_type != -1) { pt = t_hash_table_lookup(orig_dst.codecs, GINT_TO_POINTER(dtmf_payload_type)); + if (!pt && a.allow_asymmetric) + pt = t_hash_table_lookup(src->codecs, GINT_TO_POINTER(dtmf_payload_type)); if (!pt) ilogs(codec, LOG_DEBUG, "DTMF payload type %i is missing", dtmf_payload_type); else diff --git a/include/codec.h b/include/codec.h index 25099e7497..b5db0f7796 100644 --- a/include/codec.h +++ b/include/codec.h @@ -149,7 +149,10 @@ void codec_store_track(struct codec_store *, str_q *); __attribute__((nonnull(1, 2, 3))) void codec_store_transcode(struct codec_store *, str_q *, struct codec_store *); __attribute__((nonnull(1, 2, 3))) -void codec_store_answer(struct codec_store *dst, struct codec_store *src, sdp_ng_flags *flags); +void __codec_store_answer(struct codec_store *dst, struct codec_store *src, sdp_ng_flags *flags, + struct codec_store_args); +#define codec_store_answer(dst, src, flags, ...) \ + __codec_store_answer(dst, src, flags, (struct codec_store_args) {__VA_ARGS__}) __attribute__((nonnull(1, 2))) void codec_store_synthesise(struct codec_store *dst, struct codec_store *opposite); __attribute__((nonnull(1, 2)))