[asterisk-commits] branch oej/sdpcleanup r26886 - in
/team/oej/sdpcleanup: ./ channels/chan_sip.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Thu May 11 06:57:42 MST 2006
Author: oej
Date: Thu May 11 08:57:41 2006
New Revision: 26886
URL: http://svn.digium.com/view/asterisk?rev=26886&view=rev
Log:
Update
Modified:
team/oej/sdpcleanup/ (props changed)
team/oej/sdpcleanup/channels/chan_sip.c
Propchange: team/oej/sdpcleanup/
------------------------------------------------------------------------------
automerge = http://edvina.net/training/
Modified: team/oej/sdpcleanup/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/oej/sdpcleanup/channels/chan_sip.c?rev=26886&r1=26885&r2=26886&view=diff
==============================================================================
--- team/oej/sdpcleanup/channels/chan_sip.c (original)
+++ team/oej/sdpcleanup/channels/chan_sip.c Thu May 11 08:57:41 2006
@@ -792,7 +792,7 @@
int jointcapability; /*!< Supported capability at both ends (codecs ) */
int peercapability; /*!< Supported peer capability */
int prefcodec; /*!< Preferred codec (outbound only) */
- int noncodeccapability;
+ int noncodeccapability; /*!< RTP non-codec capabilities */
int maxcallbitrate; /*!< Maximum Call Bitrate for Video Calls */
int callingpres; /*!< Calling presentation */
int authtries; /*!< Times we've tried to authenticate */
@@ -1236,6 +1236,10 @@
static struct ast_rtp *sip_get_vrtp_peer(struct ast_channel *chan);
static int sip_get_codec(struct ast_channel *chan);
static struct ast_frame *sip_rtp_read(struct ast_channel *ast, struct sip_pvt *p);
+
+/*----- SDP handling functions */
+static int add_sdp(struct sip_request *resp, struct sip_pvt *p);
+static int process_sdp(struct sip_pvt *p, struct sip_request *req);
/*! \brief Definition of this channel for PBX channel registration */
static const struct ast_channel_tech sip_tech = {
@@ -3156,6 +3160,7 @@
return NULL;
}
tmp->tech = &sip_tech;
+
/* Select our native format based on codec preference until we receive
something from another device to the contrary. */
if (i->jointcapability)
@@ -3164,11 +3169,22 @@
what = i->capability;
else
what = global_capability;
- needvideo = i->prefcodec & AST_FORMAT_VIDEO_MASK;
- if (option_debug && needvideo)
- ast_log(LOG_DEBUG, "This call needs video! HOLLYWOOD next!\n");
+
+ needvideo = what & AST_FORMAT_VIDEO_MASK;
+
+ if (option_debug) {
+ if (needvideo)
+ ast_log(LOG_DEBUG, "This call needs video! HOLLYWOOD next!\n");
+ else
+ ast_log(LOG_DEBUG, "This call does not need video.\n");
+ }
tmp->nativeformats = ast_codec_choose(&i->prefs, what, 1) | (i->jointcapability & AST_FORMAT_VIDEO_MASK);
+ if (option_debug) {
+ char buf[BUFSIZ];
+ ast_log(LOG_DEBUG, "*** Our native formats are %s \n", ast_getformatname_multiple(buf, BUFSIZ, tmp->nativeformats));
+ }
+
fmt = ast_best_codec(tmp->nativeformats);
if (title)
@@ -3852,8 +3868,8 @@
int portno = -1; /*!< RTP Audio port number */
int vportno = -1; /*!< RTP Video port number */
int peercapability, peernoncodeccapability;
- int vpeercapability=0, vpeernoncodeccapability=0;
- struct sockaddr_in sin;
+ int vpeercapability = 0, vpeernoncodeccapability = 0;
+ struct sockaddr_in sin; /*!< media socket address */
struct sockaddr_in vsin; /*!< Video socket address */
const char *codecs;
struct hostent *hp; /*!< RTP Audio host IP */
@@ -3879,10 +3895,9 @@
return -1;
}
+ /* Initialize the temporary RTP structures we use to evaluate the offer from the peer */
ast_rtp_pt_default(&newaudiortp);
- if (p->vrtp)
- ast_rtp_pt_default(&newvideortp);
-
+ ast_rtp_pt_default(&newvideortp);
/* Update our last rtprx when we receive an SDP, too */
time(&p->lastrtprx);
@@ -3893,6 +3908,7 @@
ast_log(LOG_NOTICE, "Content is '%s', not 'application/sdp'\n", get_header(req, "Content-Type"));
return -1;
}
+
/* Try to find first media stream */
m = get_sdp(req, "m");
destiterator = 0;
@@ -3901,16 +3917,21 @@
ast_log(LOG_WARNING, "Insufficient information for SDP (m = '%s', c = '%s')\n", m, c);
return -1;
}
+
+ /* Check for IPv4 address (not IPv6 yet) */
if (sscanf(c, "IN IP4 %256s", host) != 1) {
ast_log(LOG_WARNING, "Invalid host in c= line, '%s'\n", c);
return -1;
}
+
/* XXX This could block for a long time, and block the main thread! XXX */
hp = ast_gethostbyname(host, &audiohp);
if (!hp) {
ast_log(LOG_WARNING, "Unable to lookup host in c= line, '%s'\n", c);
return -1;
}
+ vhp = hp; /* Copy to video address as default too */
+
iterator = 0;
ast_set_flag(&p->flags[0], SIP_NOVIDEO);
@@ -3998,19 +4019,6 @@
sin.sin_port = htons(portno);
/* Setup video port number */
vsin.sin_port = htons(vportno);
-
- if (p->rtp && sin.sin_port) {
- ast_rtp_set_peer(p->rtp, &sin);
- if (debug)
- ast_verbose("Peer audio RTP is at port %s:%d\n", ast_inet_ntoa(iabuf,sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port));
- }
-
- /* Setup video port number */
- if (p->vrtp && vsin.sin_port) {
- ast_rtp_set_peer(p->vrtp, &vsin);
- if (debug)
- ast_verbose("Peer video RTP is at port %s:%d\n", ast_inet_ntoa(iabuf,sizeof(iabuf), vsin.sin_addr), ntohs(vsin.sin_port));
- }
/* Next, scan through each "a=rtpmap:" line, noting each
* specified RTP payload type (with corresponding MIME subtype):
@@ -4066,8 +4074,7 @@
/* Now gather all of the codecs that we are asked for: */
ast_rtp_get_current_formats(&newaudiortp, &peercapability, &peernoncodeccapability);
- if (p->vrtp)
- ast_rtp_get_current_formats(&newvideortp, &vpeercapability, &vpeernoncodeccapability);
+ ast_rtp_get_current_formats(&newvideortp, &vpeercapability, &vpeernoncodeccapability);
newjointcapability = p->capability & (peercapability | vpeercapability);
newpeercapability = (peercapability | vpeercapability);
@@ -4106,19 +4113,12 @@
return -1;
}
- if (!p->owner) /* There's no open channel owning us */
- return 0;
-
- /* Ok, we're going with this offer */
- if (debug && option_debug)
- ast_log(LOG_DEBUG, "Ok, we're accepting this SDP offer! \n");
-
+ /* We are now ready to change the sip session and p->rtp and p->vrtp with the offered codecs, since
+ they are acceptable */
p->jointcapability = newjointcapability;
p->peercapability = newpeercapability;
p->noncodeccapability = newnoncodeccapability;
- /* We are now ready to change p->rtp and p->vrtp with the offered codecs, since
- they are acceptable */
{
int i;
/* Copy payload types from source to destination */
@@ -4131,6 +4131,30 @@
}
}
}
+
+ /* Setup audio port number */
+ if (p->rtp && sin.sin_port) {
+ ast_rtp_set_peer(p->rtp, &sin);
+ if (debug)
+ ast_verbose("Peer audio RTP is at port %s:%d\n", ast_inet_ntoa(iabuf,sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port));
+ }
+
+ /* Setup video port number */
+ if (p->vrtp && vsin.sin_port) {
+ ast_rtp_set_peer(p->vrtp, &vsin);
+ if (debug)
+ ast_verbose("Peer video RTP is at port %s:%d\n", ast_inet_ntoa(iabuf,sizeof(iabuf), vsin.sin_addr), ntohs(vsin.sin_port));
+ }
+
+ /* Ok, we're going with this offer */
+ if (option_debug) {
+ char buf[BUFSIZ];
+ ast_log(LOG_DEBUG, "We're settling with these formats: %s\n", ast_getformatname_multiple(buf, BUFSIZ, p->capability));
+ }
+
+ if (!p->owner) /* There's no open channel owning us so we can return here. For a re-invite or so, we proceed */
+ return 0;
+
if (!(p->owner->nativeformats & p->jointcapability & AST_FORMAT_AUDIO_MASK)) {
const unsigned slen=512;
@@ -4192,6 +4216,7 @@
}
ast_set_flag(&p->flags[0], SIP_CALL_ONHOLD);
}
+
return 0;
}
@@ -4847,7 +4872,7 @@
int alreadysent = 0;
struct sockaddr_in sin;
struct sockaddr_in vsin;
- char v[256];
+ char v[10];
char s[256];
char o[256];
char c[256];
@@ -4871,6 +4896,7 @@
struct sockaddr_in dest;
struct sockaddr_in vdest = { 0, };
int debug;
+ int needvideo = FALSE;
debug = sip_debug_test_pvt(p);
@@ -4880,7 +4906,7 @@
return -1;
}
capability = p->jointcapability;
-
+
if (!p->sessionid) {
p->sessionid = getpid();
p->sessionversion = p->sessionid;
@@ -4890,6 +4916,7 @@
if (p->vrtp)
ast_rtp_get_us(p->vrtp, &vsin);
+ /* Is this a re-invite to move the media out, then use the original offer from caller */
if (p->redirip.sin_addr.s_addr) {
dest.sin_port = p->redirip.sin_port;
dest.sin_addr = p->redirip.sin_addr;
@@ -4900,8 +4927,18 @@
dest.sin_port = sin.sin_port;
}
+ if(capability & AST_FORMAT_VIDEO_MASK) {
+ if (p->vrtp) {
+ needvideo = TRUE;
+ if (option_debug)
+ ast_log(LOG_DEBUG, "This call needs video offers! \n");
+ } else if (option_debug)
+ ast_log(LOG_DEBUG, "This call needs video offers, but there's no video suupport enabled ! \n");
+ }
+
+
/* Determine video destination */
- if (p->vrtp) {
+ if (needvideo) {
if (p->vredirip.sin_addr.s_addr) {
vdest.sin_port = p->vredirip.sin_port;
vdest.sin_addr = p->vredirip.sin_addr;
@@ -4912,7 +4949,7 @@
}
if (debug) {
ast_verbose("We're at %s port %d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ntohs(sin.sin_port));
- if (p->vrtp)
+ if (needvideo)
ast_verbose("Video is at %s port %d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ntohs(vsin.sin_port));
}
@@ -4939,7 +4976,7 @@
&m_audio_next, &m_audio_left,
&a_audio_next, &a_audio_left,
debug);
- else
+ else if (needvideo)
add_codec_to_sdp(p, p->prefcodec, 90000,
&m_video_next, &m_video_left,
&a_video_next, &a_video_left,
@@ -4963,7 +5000,7 @@
&m_audio_next, &m_audio_left,
&a_audio_next, &a_audio_left,
debug);
- else
+ else if (needvideo)
add_codec_to_sdp(p, pref_codec, 90000,
&m_video_next, &m_video_left,
&a_video_next, &a_video_left,
@@ -5024,7 +5061,7 @@
add_line(resp, o);
add_line(resp, s);
add_line(resp, c);
- if ((p->vrtp) &&
+ if ((needvideo) &&
(!ast_test_flag(&p->flags[0], SIP_NOVIDEO)) &&
(capability & VIDEO_CODEC_MASK)) /* only if video response is appropriate */
add_line(resp, b);
@@ -5041,6 +5078,11 @@
/* Update lastrtprx when we send our SDP */
time(&p->lastrtprx);
time(&p->lastrtptx);
+
+ if (option_debug) {
+ char buf[BUFSIZ];
+ ast_log(LOG_DEBUG, "We're settling with offering these formats: %s\n", ast_getformatname_multiple(buf, BUFSIZ, capability));
+ }
return 0;
}
@@ -7610,20 +7652,24 @@
p->callgroup = user->callgroup;
p->pickupgroup = user->pickupgroup;
p->callingpres = user->callingpres;
- p->capability = user->capability;
- p->jointcapability = user->capability;
- p->maxcallbitrate = user->maxcallbitrate;
- if (!ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) && p->vrtp) {
- ast_rtp_destroy(p->vrtp);
- p->vrtp = NULL;
- }
- if (p->peercapability)
+
+ /* Set default codec settings for this call */
+ p->capability = user->capability; /* User codec choice */
+ p->jointcapability = user->capability; /* Our codecs */
+ if (p->peercapability) /* AND with peer's codecs */
p->jointcapability &= p->peercapability;
if ((ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) ||
(ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO))
p->noncodeccapability |= AST_RTP_DTMF;
else
p->noncodeccapability &= ~AST_RTP_DTMF;
+
+ p->maxcallbitrate = user->maxcallbitrate;
+ /* If we do not support video, remove video from call structure */
+ if (!ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) && p->vrtp) {
+ ast_rtp_destroy(p->vrtp);
+ p->vrtp = NULL;
+ }
}
if (user && debug)
ast_verbose("Found user '%s'\n", user->name);
@@ -10092,10 +10138,11 @@
if (!ast_test_flag(req, SIP_PKT_IGNORE))
sip_cancel_destroy(p);
p->authtries = 0;
- if (!strcasecmp(get_header(req, "Content-Type"), "application/sdp"))
- if (res = process_sdp(p, req) && !ast_test_flag(req, SIP_PKT_IGNORE))
+ if (!strcasecmp(get_header(req, "Content-Type"), "application/sdp")) {
+ if ((res = process_sdp(p, req)) && !ast_test_flag(req, SIP_PKT_IGNORE))
/* This 200 OK's SDP is not acceptable, so we need to ack, then hangup */
ast_set_flag(&p->flags[0], SIP_PENDINGBYE);
+ }
/* Parse contact header for continued conversation */
/* When we get 200 OK, we know which device (and IP) to contact for this call */
@@ -12610,7 +12657,7 @@
#if 0
printf("Setting up to call extension '%s' at '%s'\n", ext ? ext : "<none>", host);
#endif
- p->prefcodec = format;
+ p->prefcodec = format; /* Format for this call */
ast_mutex_lock(&p->lock);
tmpc = sip_new(p, AST_STATE_DOWN, host); /* Place the call */
ast_mutex_unlock(&p->lock);
@@ -12912,6 +12959,7 @@
ast_copy_flags(&user->flags[1], &global_flags[1], SIP_PAGE2_FLAGS_TO_COPY);
user->capability = global_capability;
user->allowtransfer = global_allowtransfer;
+ user->maxcallbitrate = default_maxcallbitrate;
user->prefs = default_prefs;
/* set default context */
strcpy(user->context, default_context);
@@ -13800,8 +13848,9 @@
}
if (changed && !ast_test_flag(&p->flags[0], SIP_GOTREFER)) {
if (chan->_state != AST_STATE_UP) {
- char iabuf[INET_ADDRSTRLEN];
- ast_log(LOG_DEBUG, "Early media setting SIP '%s' - Sending early media to %s\n", p->callid, ast_inet_ntoa(iabuf, sizeof(iabuf), rtp ? p->redirip.sin_addr : p->ourip));
+ char iabuf[INET_ADDRSTRLEN];
+ if (option_debug)
+ ast_log(LOG_DEBUG, "Early remote bridge setting SIP '%s' - Sending media to %s\n", p->callid, ast_inet_ntoa(iabuf, sizeof(iabuf), rtp ? p->redirip.sin_addr : p->ourip));
} else if (!p->pendinginvite) {
if (option_debug > 2) {
char iabuf[INET_ADDRSTRLEN];
More information about the asterisk-commits
mailing list