From b562f5ca477bde2a48f6aad35e7cdc7da9a7f276 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 23 Feb 2026 10:12:55 -0400 Subject: [PATCH] MT#55283 extend "answer only" logic Provide an extra codec-store for the lookup of the answer codec. This is needed for codec switches during an extra answer, as the original codecs are kept in a different codec-store. Closes #2073 Change-Id: I7e2efc434789ecc8d3b5fcf97240e5c3f7c84652 (cherry picked from commit cfe9a588fac393444edaf460076ff394ad255227) --- daemon/call.c | 15 ++++++++------- daemon/codec.c | 9 ++++++--- include/codec.h | 4 ++-- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index ef8f42666..dd7717d26 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -2540,21 +2540,21 @@ static void codecs_answer(struct call_media *media, struct call_media *other_med STR_FMT(&other_media->monologue->tag), other_media->index); - bool codec_answer_only = true; + const struct codec_store *answer_cs = &media->offered_codecs; // don't do codec answer for a rejected media section if (other_media->streams.length == 0) - codec_answer_only = false; + answer_cs = NULL; else if (sp->rtp_endpoint.port == 0) - codec_answer_only = false; + answer_cs = NULL; if (flags->reuse_codec) codec_store_populate_reuse(&other_media->codecs, &sp->codecs, .codec_set = flags->codec_set, - .answer_only = codec_answer_only); + .answer_cs = answer_cs); else codec_store_populate(&other_media->codecs, &sp->codecs, .codec_set = flags->codec_set, - .answer_only = codec_answer_only, + .answer_cs = answer_cs, .allow_asymmetric = !!flags->allow_asymmetric_codecs); codec_store_strip(&other_media->codecs, &flags->codec_strip, flags->codec_except); codec_store_offer(&other_media->codecs, &flags->codec_offer, &sp->codecs); @@ -4577,12 +4577,13 @@ int monologue_subscribe_answer(struct call_monologue *dst_ml, sdp_ng_flags *flag if (flags->allow_transcoding) { codec_store_populate(&dst_media->codecs, &sp->codecs, .codec_set = flags->codec_set, - .answer_only = true, + .answer_cs = &src_media->codecs, .allow_asymmetric = !!flags->allow_asymmetric_codecs); codec_store_strip(&dst_media->codecs, &flags->codec_strip, flags->codec_except); codec_store_offer(&dst_media->codecs, &flags->codec_offer, &sp->codecs); } else { - codec_store_populate(&dst_media->codecs, &sp->codecs, .answer_only = true, + codec_store_populate(&dst_media->codecs, &sp->codecs, + .answer_cs = &src_media->codecs, .allow_asymmetric = !!flags->allow_asymmetric_codecs); if (!codec_store_is_full_answer(&src_media->codecs, &dst_media->codecs)) return -1; diff --git a/daemon/codec.c b/daemon/codec.c index 24e201d95..0e971fe03 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -5676,7 +5676,7 @@ void __codec_store_populate_reuse(struct codec_store *dst, struct codec_store *s codec_store_add_raw_link(dst, dup, pos); } else { - if (!a.answer_only) { + if (!a.answer_cs) { ilogs(codec, LOG_DEBUG, "Adding codec " STR_FORMAT "/" STR_FORMAT " (%i) to end of list", STR_FMT(&pt->encoding_with_params), @@ -5756,8 +5756,11 @@ void __codec_store_populate(struct codec_store *dst, struct codec_store *src, st GINT_TO_POINTER(pt->payload_type)); if (orig_pt && !rtp_payload_type_eq_compat(orig_pt, pt)) orig_pt = NULL; - if (a.answer_only && !orig_pt) { - if (a.allow_asymmetric) + if (a.answer_cs && !orig_pt) { + orig_pt = t_hash_table_lookup(a.answer_cs->codecs, GINT_TO_POINTER(pt->payload_type)); + if (orig_pt && !rtp_payload_type_eq_compat(orig_pt, pt)) + orig_pt = NULL; + if (a.allow_asymmetric && !orig_pt) orig_pt = codec_store_find_compatible(&orig_dst, pt); if (!orig_pt) { ilogs(codec, LOG_DEBUG, "Not adding stray answer codec " diff --git a/include/codec.h b/include/codec.h index 53776a0cd..9bd7306f3 100644 --- a/include/codec.h +++ b/include/codec.h @@ -164,9 +164,9 @@ void codec_update_all_source_handlers(struct call_monologue *ml, const sdp_ng_fl struct codec_store_args { str_case_value_ht codec_set; - bool answer_only; - bool allow_asymmetric; + const struct codec_store *answer_cs; struct codec_store *merge_cs; + bool allow_asymmetric; }; __attribute__((nonnull(1)))