From 3f2744f0325d30717dbf9131cf7adf19880e39b8 Mon Sep 17 00:00:00 2001 From: Hoan Luu Huu <110280845+xquanluu@users.noreply.github.com> Date: Thu, 3 Apr 2025 18:58:39 +0700 Subject: [PATCH] fixed replaceEndpoint offer single codec that callee does not support (#1131) --- lib/session/call-session.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/session/call-session.js b/lib/session/call-session.js index 3292f2d5..8a16689f 100644 --- a/lib/session/call-session.js +++ b/lib/session/call-session.js @@ -2354,10 +2354,32 @@ Duration=${duration} ` // Destroy previous ep if it's still running. if (this.ep?.connected) this.ep.destroy(); - this.ep = await this.ms.createEndpoint({remoteSdp: this.dlg.remote.sdp}); + /* Codec negotiation issue explanation: + * + * Problem scenario: + * 1. Initial negotiation: + * - FreeSWITCH → SBC: offers multiple codecs (PCMU, PCMA, G722) + * - SBC → Callee: passes all codecs (PCMU, PCMA, G722) + * - Callee → SBC: responds with PCMA (its supported codec) + * - SBC → FreeSWITCH: responds with PCMU (after transcoding) + * + * 2. After endpoint replacement: + * - If we only offer PCMU in the new endpoint + * - FreeSWITCH → SBC: offers only PCMU + * - SBC → Callee: offers only PCMU + * - Call fails: Callee rejects since it only supports PCMA + * + * Solution: + * Always have FreeSWITCH offer multiple codecs to the SBC, don't pass remote sdp here to ensure + * the SBC can reoffer the same codecs that the callee originally accepted. + * This prevents call failures during media renegotiation. + */ + + this.ep = await this.ms.createEndpoint(); this._configMsEndpoint(); - await this.dlg.modify(this.ep.local.sdp); + const sdp = await this.dlg.modify(this.ep.local.sdp); + await this.ep.modify(sdp); this.logger.debug('CallSession:replaceEndpoint completed'); return this.ep; }