From f2a0e2309adc972347ec79bbdb8aad38121061f0 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 (cherry picked from commit abbc02296f9d0396c268fb5d0987e341e58e473f) (cherry picked from commit f7b6a6c86e731604e3a463b84c1c580f4ab0ce50) --- 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 1d5c99c98..60f044d4a 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 ff79e0d35..469dbca08 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -2482,7 +2482,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 db468546c..e2872dde3 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -1142,7 +1142,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) { @@ -1178,10 +1181,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 - struct rtp_payload_type *sink_dtmf_pt = __supp_payload_type(supplemental_sinks, - sink_pt->clock_rate, "telephone-event"); - struct rtp_payload_type *sink_cn_pt = __supp_payload_type(supplemental_sinks, - sink_pt->clock_rate, "CN"); + struct rtp_payload_type *sink_dtmf_pt = NULL; + struct 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; + } struct rtp_payload_type *real_sink_dtmf_pt = NULL; // for DTMF delay // XXX synthesise missing supp codecs according to codec tracker XXX needed? @@ -4962,6 +4973,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 " (%i)", STR_FMT(&pt->encoding_with_params), @@ -5301,7 +5314,9 @@ void codec_store_transcode(struct codec_store *cs, GQueue *offer, struct codec_s #endif } -void codec_store_answer(struct codec_store *dst, struct codec_store *src, struct sdp_ng_flags *flags) { +void __codec_store_answer(struct codec_store *dst, struct codec_store *src, struct 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); @@ -5408,6 +5423,8 @@ void codec_store_answer(struct codec_store *dst, struct codec_store *src, struct // handle associated supplemental codecs if (h->cn_payload_type != -1) { pt = g_hash_table_lookup(orig_dst.codecs, GINT_TO_POINTER(h->cn_payload_type)); + if (!pt && a.allow_asymmetric) + pt = g_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 @@ -5418,6 +5435,8 @@ void codec_store_answer(struct codec_store *dst, struct codec_store *src, struct dtmf_payload_type = h->real_dtmf_payload_type; if (dtmf_payload_type != -1) { pt = g_hash_table_lookup(orig_dst.codecs, GINT_TO_POINTER(dtmf_payload_type)); + if (!pt && a.allow_asymmetric) + pt = g_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 bbc4209ee..d9642cdf4 100644 --- a/include/codec.h +++ b/include/codec.h @@ -148,7 +148,10 @@ void codec_store_track(struct codec_store *, GQueue *); __attribute__((nonnull(1, 2, 3))) void codec_store_transcode(struct codec_store *, GQueue *, struct codec_store *); __attribute__((nonnull(1, 2, 3))) -void codec_store_answer(struct codec_store *dst, struct codec_store *src, struct sdp_ng_flags *flags); +void __codec_store_answer(struct codec_store *dst, struct codec_store *src, struct 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)))