From d646547bdb18b3783c3fd4760c2394f14b260d23 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 30 Oct 2009 01:06:51 +0000 Subject: [PATCH] filter out unwanted media on rtp git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@15284 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_utils.h | 3 +++ src/switch_rtp.c | 10 ++++++---- src/switch_utils.c | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/include/switch_utils.h b/src/include/switch_utils.h index d75af5b9b9..36ce888307 100644 --- a/src/include/switch_utils.h +++ b/src/include/switch_utils.h @@ -186,6 +186,9 @@ SWITCH_DECLARE(switch_status_t) switch_find_local_ip(_Out_opt_bytecapcount_(len) */ SWITCH_DECLARE(char *) get_addr(char *buf, switch_size_t len, struct sockaddr *sa, socklen_t salen); +SWITCH_DECLARE(int) get_addr_int(switch_sockaddr_t *sa); +SWITCH_DECLARE(int) switch_cmp_addr(switch_sockaddr_t *sa1, switch_sockaddr_t *sa2); + /*! \brief get the port number of an ip address \param sa the struct sockaddr * to get the port from diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 0a8ac5e127..d3d756b3fd 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -1934,11 +1934,13 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ } } - - - if (bytes && ((rtp_session->cng_pt && rtp_session->recv_msg.header.pt == rtp_session->cng_pt) || rtp_session->recv_msg.header.pt == 13)) { + + if (bytes && !switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTOADJ) && + (!switch_cmp_addr(rtp_session->from_addr, rtp_session->remote_addr) || + ((rtp_session->cng_pt && rtp_session->recv_msg.header.pt == rtp_session->cng_pt) || rtp_session->recv_msg.header.pt == 13))) { bytes = 0; - goto recvfrom; + goto recvfrom; + } if (bytes && diff --git a/src/switch_utils.c b/src/switch_utils.c index 742925ff8b..80356d0886 100644 --- a/src/switch_utils.c +++ b/src/switch_utils.c @@ -1338,10 +1338,28 @@ static const char *switch_inet_ntop6(unsigned char const *src, char *dst, size_t #endif +SWITCH_DECLARE(int) get_addr_int(switch_sockaddr_t *sa) +{ + struct sockaddr_in *s = (struct sockaddr_in *)&sa->sa; + + return ntohs(s->sin_addr.s_addr); +} + + +SWITCH_DECLARE(int) switch_cmp_addr(switch_sockaddr_t *sa1, switch_sockaddr_t *sa2) +{ + struct sockaddr_in *s1 = (struct sockaddr_in *)&sa1->sa; + struct sockaddr_in *s2 = (struct sockaddr_in *)&sa2->sa; + + return (ntohs(s1->sin_addr.s_addr) == ntohs(s2->sin_addr.s_addr) && ntohs(s1->sin_port) == ntohs(s2->sin_port)); +} + + SWITCH_DECLARE(char *) get_addr(char *buf, switch_size_t len, struct sockaddr *sa, socklen_t salen) { switch_assert(buf); *buf = '\0'; + if (sa) { getnameinfo(sa, salen, buf, (socklen_t)len, NULL, 0, NI_NUMERICHOST); }