From e4e1742da677b722a591f74cde66caa4b5000c04 Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Fri, 25 Jul 2025 13:27:41 +0200 Subject: [PATCH] MT#63298 AmB2BSession: introduce `getMediaPort()` Introduce AmSdp port getter. Just takes the first available port which is > 0. Change-Id: I49a4b850219c64d4720dafb3684dc9d11fa4594f --- core/AmB2BSession.cpp | 15 +++++++++++++++ core/AmB2BSession.h | 3 +++ 2 files changed, 18 insertions(+) diff --git a/core/AmB2BSession.cpp b/core/AmB2BSession.cpp index 2cfedd36..f32dba08 100644 --- a/core/AmB2BSession.cpp +++ b/core/AmB2BSession.cpp @@ -302,6 +302,21 @@ void AmB2BSession::addFakeSDPbasedOnPort(const AmMimeBody *src_sdp, AmMimeBody & createFakeReply(&fake_mimebody, new_body); } +unsigned int AmB2BSession::getMediaPort(const AmSdp& sdp) +{ + unsigned int result = 0; + + for (auto it = sdp.media.begin(); it != sdp.media.end(); ++it) + { + /* must be a legal port which must also not be ICE dummy port */ + if (it->port > 0 && it->port != 9) { + result = it->port; + break; + } + } + return result; +} + void AmB2BSession::acceptPendingInvite(AmSipRequest *invite) { // reply the INVITE with fake 200 reply diff --git a/core/AmB2BSession.h b/core/AmB2BSession.h index 3bce1913..33090c88 100644 --- a/core/AmB2BSession.h +++ b/core/AmB2BSession.h @@ -213,6 +213,9 @@ private: /** create fake AmSipReply. SDP body based on SDP offer, but with a desired port */ void addFakeSDPbasedOnPort(const AmMimeBody *src_sdp, AmMimeBody &new_body, unsigned int& desired_port); + /** get the first available media port */ + unsigned int getMediaPort(const AmSdp& sdp); + /** generate 200 SIP reply on a pending INVITE (uses fake body) */ virtual void acceptPendingInvite(AmSipRequest *invite);