aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xchannels/chan_h323.c2
-rwxr-xr-xchannels/chan_mgcp.c16
-rwxr-xr-xchannels/chan_sip.c31
-rwxr-xr-xchannels/chan_skinny.c2
-rwxr-xr-xinclude/asterisk/rtp.h2
-rwxr-xr-xrtp.c41
6 files changed, 59 insertions, 35 deletions
diff --git a/channels/chan_h323.c b/channels/chan_h323.c
index ec2e0a4c8..20f8cd1ea 100755
--- a/channels/chan_h323.c
+++ b/channels/chan_h323.c
@@ -1776,7 +1776,7 @@ static char *convertcap(int cap)
}
-static int oh323_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp)
+static int oh323_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, int codecs)
{
/* XXX Deal with Video */
struct oh323_pvt *p;
diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c
index 9399a9ae6..27adaccfa 100755
--- a/channels/chan_mgcp.c
+++ b/channels/chan_mgcp.c
@@ -433,7 +433,7 @@ static int transmit_response(struct mgcp_subchannel *sub, char *msg, struct mgcp
static int transmit_notify_request(struct mgcp_subchannel *sub, char *tone);
static int transmit_modify_request(struct mgcp_subchannel *sub);
static int transmit_notify_request_with_callerid(struct mgcp_subchannel *sub, char *tone, char *callerid);
-static int transmit_modify_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp *rtp);
+static int transmit_modify_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp *rtp, int codecs);
static int transmit_connection_del(struct mgcp_subchannel *sub);
static int transmit_audit_endpoint(struct mgcp_endpoint *p);
static void start_rtp(struct mgcp_subchannel *sub);
@@ -1908,13 +1908,17 @@ static int add_sdp(struct mgcp_request *resp, struct mgcp_subchannel *sub, struc
return 0;
}
-static int transmit_modify_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp *rtp)
+static int transmit_modify_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp *rtp, int codecs)
{
struct mgcp_request resp;
char local[256];
char tmp[80];
int x;
+ int capability;
struct mgcp_endpoint *p = sub->parent;
+ capability = p->capability;
+ if (codecs)
+ capability = codecs;
if (!strlen(sub->cxident) && rtp) {
/* We don't have a CXident yet, store the destination and
wait a bit */
@@ -1923,7 +1927,7 @@ static int transmit_modify_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp
}
snprintf(local, sizeof(local), "p:20");
for (x=1;x<= AST_FORMAT_MAX_AUDIO; x <<= 1) {
- if (p->capability & x) {
+ if (capability & x) {
snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype(1, x));
strcat(local, tmp);
}
@@ -2298,7 +2302,7 @@ static void handle_response(struct mgcp_endpoint *p, struct mgcp_subchannel *sub
}
strncpy(sub->cxident, c, sizeof(sub->cxident) - 1);
if (sub->tmpdest.sin_addr.s_addr) {
- transmit_modify_with_sdp(sub, NULL);
+ transmit_modify_with_sdp(sub, NULL, 0);
}
}
else {
@@ -3710,13 +3714,13 @@ static struct ast_rtp *mgcp_get_rtp_peer(struct ast_channel *chan)
return NULL;
}
-static int mgcp_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp)
+static int mgcp_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, int codecs)
{
/* XXX Is there such thing as video support with MGCP? XXX */
struct mgcp_subchannel *sub;
sub = chan->pvt->pvt;
if (sub) {
- transmit_modify_with_sdp(sub, rtp);
+ transmit_modify_with_sdp(sub, rtp, codecs);
return 0;
}
return -1;
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 57e749f2a..a9b75da33 100755
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -493,7 +493,7 @@ static int transmit_response_with_auth(struct sip_pvt *p, char *msg, struct sip_
static int transmit_request(struct sip_pvt *p, char *msg, int inc, int reliable, int newbranch);
static int transmit_request_with_auth(struct sip_pvt *p, char *msg, int inc, int reliable, int newbranch);
static int transmit_invite(struct sip_pvt *p, char *msg, int sendsdp, char *auth, char *authheader, char *vxml_url,char *distinctive_ring, int init);
-static int transmit_reinvite_with_sdp(struct sip_pvt *p, struct ast_rtp *rtp, struct ast_rtp *vrtp);
+static int transmit_reinvite_with_sdp(struct sip_pvt *p, struct ast_rtp *rtp, struct ast_rtp *vrtp, int codec);
static int transmit_info_with_digit(struct sip_pvt *p, char digit);
static int transmit_message_with_text(struct sip_pvt *p, char *text);
static int transmit_refer(struct sip_pvt *p, char *dest);
@@ -3003,7 +3003,7 @@ static int add_digit(struct sip_request *req, char digit)
}
/*--- add_sdp: Add Session Description Protocol message ---*/
-static int add_sdp(struct sip_request *resp, struct sip_pvt *p, struct ast_rtp *rtp, struct ast_rtp *vrtp)
+static int add_sdp(struct sip_request *resp, struct sip_pvt *p, struct ast_rtp *rtp, struct ast_rtp *vrtp, int codecs)
{
int len;
int codec;
@@ -3022,6 +3022,7 @@ static int add_sdp(struct sip_request *resp, struct sip_pvt *p, struct ast_rtp *
char a[1024] = "";
char a2[1024] = "";
int x;
+ int capability;
struct sockaddr_in dest;
struct sockaddr_in vdest = { 0, };
/* XXX We break with the "recommendation" and send our IP, in order that our
@@ -3031,6 +3032,10 @@ static int add_sdp(struct sip_request *resp, struct sip_pvt *p, struct ast_rtp *
ast_log(LOG_WARNING, "No way to add SDP without an RTP structure\n");
return -1;
}
+ capability = p->jointcapability;
+ if (codecs)
+ capability = codecs & p->jointcapability;
+
if (!p->sessionid) {
p->sessionid = getpid();
p->sessionversion = p->sessionid;
@@ -3073,7 +3078,7 @@ static int add_sdp(struct sip_request *resp, struct sip_pvt *p, struct ast_rtp *
snprintf(t, sizeof(t), "t=0 0\r\n");
snprintf(m, sizeof(m), "m=audio %d RTP/AVP", ntohs(dest.sin_port));
snprintf(m2, sizeof(m2), "m=video %d RTP/AVP", ntohs(vdest.sin_port));
- if (p->jointcapability & p->prefcodec) {
+ if (capability & p->prefcodec) {
if (sip_debug_test_pvt(p))
ast_verbose("Answering/Requesting with root capability %d\n", p->prefcodec);
codec = ast_rtp_lookup_code(p->rtp, 1, p->prefcodec);
@@ -3094,7 +3099,7 @@ static int add_sdp(struct sip_request *resp, struct sip_pvt *p, struct ast_rtp *
/* Start by sending our preferred codecs */
cur = prefs;
while(cur) {
- if ((p->jointcapability & cur->codec) && !(alreadysent & cur->codec)) {
+ if ((capability & cur->codec) && !(alreadysent & cur->codec)) {
if (sip_debug_test_pvt(p))
ast_verbose("Answering with preferred capability 0x%x(%s)\n", cur->codec, ast_getformatname(cur->codec));
codec = ast_rtp_lookup_code(p->rtp, 1, cur->codec);
@@ -3116,7 +3121,7 @@ static int add_sdp(struct sip_request *resp, struct sip_pvt *p, struct ast_rtp *
}
/* Now send any other common codecs, and non-codec formats: */
for (x = 1; x <= (videosupport ? AST_FORMAT_MAX_VIDEO : AST_FORMAT_MAX_AUDIO); x <<= 1) {
- if ((p->jointcapability & x) && !(alreadysent & x)) {
+ if ((capability & x) && !(alreadysent & x)) {
if (sip_debug_test_pvt(p))
ast_verbose("Answering with capability 0x%x(%s)\n", x, ast_getformatname(x));
codec = ast_rtp_lookup_code(p->rtp, 1, x);
@@ -3161,7 +3166,7 @@ static int add_sdp(struct sip_request *resp, struct sip_pvt *p, struct ast_rtp *
if ((sizeof(m) <= strlen(m) - 2) || (sizeof(m2) <= strlen(m2) - 2) || (sizeof(a) == strlen(a)) || (sizeof(a2) == strlen(a2)))
ast_log(LOG_WARNING, "SIP SDP may be truncated due to undersized buffer!!\n");
len = strlen(v) + strlen(s) + strlen(o) + strlen(c) + strlen(t) + strlen(m) + strlen(a);
- if ((p->vrtp) && (p->jointcapability & VIDEO_CODEC_MASK)) /* only if video response is appropriate */
+ if ((p->vrtp) && (capability & VIDEO_CODEC_MASK)) /* only if video response is appropriate */
len += strlen(m2) + strlen(a2);
snprintf(costr, sizeof(costr), "%d", len);
add_header(resp, "Content-Type", "application/sdp");
@@ -3173,7 +3178,7 @@ static int add_sdp(struct sip_request *resp, struct sip_pvt *p, struct ast_rtp *
add_line(resp, t);
add_line(resp, m);
add_line(resp, a);
- if ((p->vrtp) && (p->jointcapability & VIDEO_CODEC_MASK)) { /* only if video response is appropriate */
+ if ((p->vrtp) && (capability & VIDEO_CODEC_MASK)) { /* only if video response is appropriate */
add_line(resp, m2);
add_line(resp, a2);
}
@@ -3205,7 +3210,7 @@ static int transmit_response_with_sdp(struct sip_pvt *p, char *msg, struct sip_r
return -1;
}
respprep(&resp, p, msg, req);
- add_sdp(&resp, p, NULL, NULL);
+ add_sdp(&resp, p, NULL, NULL, 0);
return send_response(p, &resp, retrans, seqno);
}
@@ -3272,7 +3277,7 @@ static int determine_firstline_parts( struct sip_request *req ) {
/* transmit_reinvite_with_sdp: Transmit reinvite with SDP :-) ---*/
/* A re-invite is basically a new INVITE with the same CALL-ID and TAG as the
INVITE that opened the SIP dialogue */
-static int transmit_reinvite_with_sdp(struct sip_pvt *p, struct ast_rtp *rtp, struct ast_rtp *vrtp)
+static int transmit_reinvite_with_sdp(struct sip_pvt *p, struct ast_rtp *rtp, struct ast_rtp *vrtp, int codec)
{
struct sip_request req;
if (p->canreinvite == REINVITE_UPDATE)
@@ -3281,7 +3286,7 @@ static int transmit_reinvite_with_sdp(struct sip_pvt *p, struct ast_rtp *rtp, st
reqprep(&req, p, "INVITE", 0, 1);
add_header(&req, "Allow", ALLOWED_METHODS);
- add_sdp(&req, p, rtp, vrtp);
+ add_sdp(&req, p, rtp, vrtp, codec);
/* Use this as the basis */
copy_request(&p->initreq, &req);
parse(&p->initreq);
@@ -3428,7 +3433,7 @@ static int transmit_invite(struct sip_pvt *p, char *cmd, int sdp, char *auth, ch
}
add_header(&req, "Allow", ALLOWED_METHODS);
if (sdp) {
- add_sdp(&req, p, NULL, NULL);
+ add_sdp(&req, p, NULL, NULL, 0);
} else {
add_header(&req, "Content-Length", "0");
add_blank_header(&req);
@@ -7725,7 +7730,7 @@ static struct ast_rtp *sip_get_vrtp_peer(struct ast_channel *chan)
return NULL;
}
-static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp)
+static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, int codec)
{
struct sip_pvt *p;
p = chan->pvt->pvt;
@@ -7739,7 +7744,7 @@ static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struc
else
memset(&p->vredirip, 0, sizeof(p->vredirip));
if (!p->gotrefer) {
- transmit_reinvite_with_sdp(p, rtp, vrtp);
+ transmit_reinvite_with_sdp(p, rtp, vrtp, codec);
p->outgoing = 1;
}
return 0;
diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c
index ec15a2c39..093b08338 100755
--- a/channels/chan_skinny.c
+++ b/channels/chan_skinny.c
@@ -948,7 +948,7 @@ static struct ast_rtp *skinny_get_rtp_peer(struct ast_channel *chan)
return NULL;
}
-static int skinny_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp)
+static int skinny_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, int codecs)
{
struct skinny_subchannel *sub;
sub = chan->pvt->pvt;
diff --git a/include/asterisk/rtp.h b/include/asterisk/rtp.h
index 385b24a6a..6f01e1e11 100755
--- a/include/asterisk/rtp.h
+++ b/include/asterisk/rtp.h
@@ -38,7 +38,7 @@ extern "C" {
struct ast_rtp_protocol {
struct ast_rtp *(*get_rtp_info)(struct ast_channel *chan); /* Get RTP struct, or NULL if unwilling to transfer */
struct ast_rtp *(*get_vrtp_info)(struct ast_channel *chan); /* Get RTP struct, or NULL if unwilling to transfer */
- int (*set_rtp_peer)(struct ast_channel *chan, struct ast_rtp *peer, struct ast_rtp *vpeer); /* Set RTP peer */
+ int (*set_rtp_peer)(struct ast_channel *chan, struct ast_rtp *peer, struct ast_rtp *vpeer, int codecs); /* Set RTP peer */
int (*get_codec)(struct ast_channel *chan);
char *type;
struct ast_rtp_protocol *next;
diff --git a/rtp.c b/rtp.c
index c111430b7..12658cfe8 100755
--- a/rtp.c
+++ b/rtp.c
@@ -1257,6 +1257,8 @@ int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, st
void *pvt0, *pvt1;
int to;
+ int codec0,codec1, oldcodec0, oldcodec1;
+
memset(&vt0, 0, sizeof(vt0));
memset(&vt1, 0, sizeof(vt1));
memset(&vac0, 0, sizeof(vac0));
@@ -1307,10 +1309,15 @@ int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, st
ast_mutex_unlock(&c1->lock);
return -2;
}
- if (pr0->get_codec && pr1->get_codec) {
- int codec0,codec1;
+ if (pr0->get_codec)
codec0 = pr0->get_codec(c0);
+ else
+ codec0 = 0;
+ if (pr1->get_codec)
codec1 = pr1->get_codec(c1);
+ else
+ codec1 = 0;
+ if (pr0->get_codec && pr1->get_codec) {
/* Hey, we can't do reinvite if both parties speak diffrent codecs */
if (!(codec0 & codec1)) {
ast_log(LOG_WARNING, "codec0 = %d is not codec1 = %d, cannot native bridge.\n",codec0,codec1);
@@ -1319,7 +1326,7 @@ int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, st
return -2;
}
}
- if (pr0->set_rtp_peer(c0, p1, vp1))
+ if (pr0->set_rtp_peer(c0, p1, vp1, codec1))
ast_log(LOG_WARNING, "Channel '%s' failed to talk to '%s'\n", c0->name, c1->name);
else {
/* Store RTP peer */
@@ -1327,7 +1334,7 @@ int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, st
if (vp1)
ast_rtp_get_peer(p1, &vac1);
}
- if (pr1->set_rtp_peer(c1, p0, vp0))
+ if (pr1->set_rtp_peer(c1, p0, vp0, codec0))
ast_log(LOG_WARNING, "Channel '%s' failed to talk back to '%s'\n", c1->name, c0->name);
else {
/* Store RTP peer */
@@ -1340,17 +1347,19 @@ int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, st
cs[0] = c0;
cs[1] = c1;
cs[2] = NULL;
+ oldcodec0 = codec0;
+ oldcodec1 = codec1;
for (;;) {
if ((c0->pvt->pvt != pvt0) ||
(c1->pvt->pvt != pvt1) ||
(c0->masq || c0->masqr || c1->masq || c1->masqr)) {
ast_log(LOG_DEBUG, "Oooh, something is weird, backing out\n");
if (c0->pvt->pvt == pvt0) {
- if (pr0->set_rtp_peer(c0, NULL, NULL))
+ if (pr0->set_rtp_peer(c0, NULL, NULL, 0))
ast_log(LOG_WARNING, "Channel '%s' failed to revert\n", c0->name);
}
if (c1->pvt->pvt == pvt1) {
- if (pr1->set_rtp_peer(c1, NULL, NULL))
+ if (pr1->set_rtp_peer(c1, NULL, NULL, 0))
ast_log(LOG_WARNING, "Channel '%s' failed to revert back\n", c1->name);
}
/* Tell it to try again later */
@@ -1359,23 +1368,29 @@ int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, st
to = -1;
ast_rtp_get_peer(p1, &t1);
ast_rtp_get_peer(p0, &t0);
+ if (pr0->get_codec)
+ codec0 = pr0->get_codec(c0);
+ if (pr1->get_codec)
+ codec1 = pr1->get_codec(c1);
if (vp1)
ast_rtp_get_peer(vp1, &vt1);
if (vp0)
ast_rtp_get_peer(vp0, &vt0);
- if (inaddrcmp(&t1, &ac1) || (vp1 && inaddrcmp(&vt1, &vac1))) {
- ast_log(LOG_DEBUG, "Oooh, '%s' changed end address\n", c1->name);
- if (pr0->set_rtp_peer(c0, t1.sin_addr.s_addr ? p1 : NULL, vt1.sin_addr.s_addr ? vp1 : NULL))
+ if (inaddrcmp(&t1, &ac1) || (vp1 && inaddrcmp(&vt1, &vac1)) || (codec1 != oldcodec1)) {
+ ast_log(LOG_DEBUG, "Oooh, '%s' changed end address (format %d)\n", c1->name, codec1);
+ if (pr0->set_rtp_peer(c0, t1.sin_addr.s_addr ? p1 : NULL, vt1.sin_addr.s_addr ? vp1 : NULL, codec1))
ast_log(LOG_WARNING, "Channel '%s' failed to update to '%s'\n", c0->name, c1->name);
memcpy(&ac1, &t1, sizeof(ac1));
memcpy(&vac1, &vt1, sizeof(vac1));
+ oldcodec1 = codec1;
}
if (inaddrcmp(&t0, &ac0) || (vp0 && inaddrcmp(&vt0, &vac0))) {
- ast_log(LOG_DEBUG, "Oooh, '%s' changed end address\n", c0->name);
- if (pr1->set_rtp_peer(c1, t0.sin_addr.s_addr ? p0 : NULL, vt0.sin_addr.s_addr ? vp0 : NULL))
+ ast_log(LOG_DEBUG, "Oooh, '%s' changed end address (format %d)\n", c0->name, codec0);
+ if (pr1->set_rtp_peer(c1, t0.sin_addr.s_addr ? p0 : NULL, vt0.sin_addr.s_addr ? vp0 : NULL, codec0))
ast_log(LOG_WARNING, "Channel '%s' failed to update to '%s'\n", c1->name, c0->name);
memcpy(&ac0, &t0, sizeof(ac0));
memcpy(&vac0, &vt0, sizeof(vac0));
+ oldcodec0 = codec0;
}
who = ast_waitfor_n(cs, 2, &to);
if (!who) {
@@ -1393,11 +1408,11 @@ int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, st
*rc = who;
ast_log(LOG_DEBUG, "Oooh, got a %s\n", f ? "digit" : "hangup");
if ((c0->pvt->pvt == pvt0) && (!c0->_softhangup)) {
- if (pr0->set_rtp_peer(c0, NULL, NULL))
+ if (pr0->set_rtp_peer(c0, NULL, NULL, 0))
ast_log(LOG_WARNING, "Channel '%s' failed to revert\n", c0->name);
}
if ((c1->pvt->pvt == pvt1) && (!c1->_softhangup)) {
- if (pr1->set_rtp_peer(c1, NULL, NULL))
+ if (pr1->set_rtp_peer(c1, NULL, NULL, 0))
ast_log(LOG_WARNING, "Channel '%s' failed to revert back\n", c1->name);
}
/* That's all we needed */