[asterisk-commits] branch oej/sdpcleanup r27330 - in /team/oej/sdpcleanup: ./ channels/chan_sip.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue May 16 06:05:01 MST 2006


Author: oej
Date: Tue May 16 08:05:00 2006
New Revision: 27330

URL: http://svn.digium.com/view/asterisk?rev=27330&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=27330&r1=27329&r2=27330&view=diff
==============================================================================
--- team/oej/sdpcleanup/channels/chan_sip.c (original)
+++ team/oej/sdpcleanup/channels/chan_sip.c Tue May 16 08:05:00 2006
@@ -3875,12 +3875,11 @@
 	int destiterator = 0;
 	int iterator;
 	int sendonly = 0;
-	int x;
 	int numberofports;
 	int debug=sip_debug_test_pvt(p);
 	struct ast_channel *bridgepeer = NULL;
-	struct ast_rtp newaudiortp, newvideortp;
-	int newjointcapability;
+	struct ast_rtp newaudiortp, newvideortp;	/* Buffers for codec handling */
+	int newjointcapability;				/* Negotiated capability */
 	int newpeercapability;
 	int newnoncodeccapability;
 	int numberofmediastreams = 0;
@@ -3891,6 +3890,8 @@
 	}
 
 	/* Initialize the temporary RTP structures we use to evaluate the offer from the peer */
+	memset(&newaudiortp, 0, sizeof(newaudiortp));
+	memset(&newvideortp, 0, sizeof(newvideortp));
 	ast_rtp_pt_default(&newaudiortp);
 	ast_rtp_pt_default(&newvideortp);
 
@@ -3933,6 +3934,7 @@
 
 	/* Find media streams in this SDP offer */
 	while ((m = get_sdp_iterate(&iterator, req, "m"))[0] != '\0') {
+		int x;
 		int audio = FALSE;
 		numberofmediastreams++;
 
@@ -3967,28 +3969,27 @@
 					return -1;
 				}
 				if (debug)
-						ast_verbose("Found RTP video format %d\n", codec);
-					ast_rtp_set_m_type(&newvideortp, codec);
-				}
-			} else 
-				ast_log(LOG_WARNING, "Unsupported SDP media type in offer: %s\n", m);
-			if (numberofports > 1)
-				ast_log(LOG_WARNING, "SDP offered %d ports for media, not supported by Asterisk. Will try anyway...\n", numberofports);
+					ast_verbose("Found RTP video format %d\n", codec);
+				ast_rtp_set_m_type(&newvideortp, codec);
+			}
+		} else 
+			ast_log(LOG_WARNING, "Unsupported SDP media type in offer: %s\n", m);
+		if (numberofports > 1)
+			ast_log(LOG_WARNING, "SDP offered %d ports for media, not supported by Asterisk. Will try anyway...\n", numberofports);
 		
 
-			/* Check for Media-description-level-address for audio */
-			if (pedanticsipchecking) {
-				c = get_sdp_iterate(&destiterator, req, "c");
-				if (!ast_strlen_zero(c)) {
-					if (sscanf(c, "IN IP4 %256s", host) != 1) {
-						ast_log(LOG_WARNING, "Invalid secondary host in c= line, '%s'\n", c);
-				} else {
-					/* XXX This could block for a long time, and block the main thread! XXX */
-					if (!audio && !(hp = ast_gethostbyname(host, &audiohp)))
+		/* Check for Media-description-level-address for audio */
+		c = get_sdp_iterate(&destiterator, req, "c");
+		if (!ast_strlen_zero(c)) {
+			if (sscanf(c, "IN IP4 %256s", host) != 1) {
+				ast_log(LOG_WARNING, "Invalid secondary host in c= line, '%s'\n", c);
+			} else {
+				/* XXX This could block for a long time, and block the main thread! XXX */
+				if (audio) {
+					if ( !(hp = ast_gethostbyname(host, &audiohp)))
 						ast_log(LOG_WARNING, "Unable to lookup RTP Audio host in secondary c= line, '%s'\n", c);
-					else if (!(vhp = ast_gethostbyname(host, &videohp)))
-						ast_log(LOG_WARNING, "Unable to lookup RTP video host in secondary c= line, '%s'\n", c);
-				}
+				} else if (!(vhp = ast_gethostbyname(host, &videohp)))
+					ast_log(LOG_WARNING, "Unable to lookup RTP video host in secondary c= line, '%s'\n", c);
 			}
 
 		}
@@ -4041,6 +4042,11 @@
 			if (debug)
 				ast_verbose("Got unsupported a:fmtp in SDP offer \n");
 			continue;
+		} else if (!strncasecmp(a, "framerate:", (size_t) 10)) {
+			/* Video stuff:  Not supported */
+			if (debug)
+				ast_verbose("Got unsupported a:framerate in SDP offer \n");
+			continue;
 		} else if (!strncasecmp(a, "maxprate:", (size_t) 9)) {
 			/* Video stuff:  Not supported */
 			if (debug)
@@ -4088,42 +4094,38 @@
 		
 	if (debug) {
 		/* shame on whoever coded this.... */
-		const unsigned slen=512;
-		char s1[slen], s2[slen], s3[slen], s4[slen];
+		char s1[BUFSIZ], s2[BUFSIZ], s3[BUFSIZ], s4[BUFSIZ];
 
 		ast_verbose("Capabilities: us - %s, peer - audio=%s/video=%s, combined - %s\n",
-			ast_getformatname_multiple(s1, slen, p->capability),
-			ast_getformatname_multiple(s2, slen, newpeercapability),
-			ast_getformatname_multiple(s3, slen, vpeercapability),
-			ast_getformatname_multiple(s4, slen, newjointcapability));
-
-		ast_verbose("Non-codec capabilities: us - %s, peer - %s, combined - %s\n",
-			ast_rtp_lookup_mime_multiple(s1, slen, noncodeccapability, 0),
-			ast_rtp_lookup_mime_multiple(s2, slen, peernoncodeccapability, 0),
-			ast_rtp_lookup_mime_multiple(s3, slen, newnoncodeccapability, 0));
+			ast_getformatname_multiple(s1, BUFSIZ, p->capability),
+			ast_getformatname_multiple(s2, BUFSIZ, newpeercapability),
+			ast_getformatname_multiple(s3, BUFSIZ, vpeercapability),
+			ast_getformatname_multiple(s4, BUFSIZ, newjointcapability));
+
+		ast_verbose("Non-codec capabilities (dtmf): us - %s, peer - %s, combined - %s\n",
+			ast_rtp_lookup_mime_multiple(s1, BUFSIZ, noncodeccapability, 0),
+			ast_rtp_lookup_mime_multiple(s2, BUFSIZ, peernoncodeccapability, 0),
+			ast_rtp_lookup_mime_multiple(s3, BUFSIZ, newnoncodeccapability, 0));
 	}
 	if (!newjointcapability) {
-		ast_log(LOG_NOTICE, "No compatible codecs!\n");
+		ast_log(LOG_NOTICE, "No compatible codecs, not accepting this offer!\n");
 		/* Do NOT Change current setting */
 		return -1;
 	}
 
 	/* 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;
-		
+	p->jointcapability = newjointcapability;	/* Our joint codec profile for this call */
+	p->peercapability = newpeercapability;		/* The other sides capability in latest offer */
+	p->noncodeccapability = newnoncodeccapability;	/* DTMF capabilities */
+
 	{
 		int i;
 		/* Copy payload types from source to destination */
 		for (i=0; i < MAX_RTP_PT; ++i) {
-			p->rtp->current_RTP_PT[i].isAstFormat = newaudiortp.current_RTP_PT[i].isAstFormat;
-			p->rtp->current_RTP_PT[i].code = newaudiortp.current_RTP_PT[i].code; 
-			if (p->vrtp) {
-				p->vrtp->current_RTP_PT[i].isAstFormat = newvideortp.current_RTP_PT[i].isAstFormat;
-				p->vrtp->current_RTP_PT[i].code = newvideortp.current_RTP_PT[i].code; 
-			}
+			p->rtp->current_RTP_PT[i]= newaudiortp.current_RTP_PT[i];
+			if (p->vrtp) 
+				p->vrtp->current_RTP_PT[i]= newvideortp.current_RTP_PT[i];
 		}
 	}
 
@@ -4142,7 +4144,7 @@
 	}
 
 	/* Ok, we're going with this offer */
-	if (option_debug) {
+	if (option_debug > 1) {
 		char buf[BUFSIZ];
 		ast_log(LOG_DEBUG, "We're settling with these formats: %s\n", ast_getformatname_multiple(buf, BUFSIZ, p->capability));
 	}
@@ -4152,12 +4154,12 @@
 
 
 	if (!(p->owner->nativeformats & p->jointcapability & AST_FORMAT_AUDIO_MASK)) {
-		const unsigned slen=512;
-		char s1[slen], s2[slen];
-		if (debug)
-			ast_log(LOG_DEBUG, "Oooh, we need to change our formats since our peer supports only %s and not %s\n", 
-				ast_getformatname_multiple(s1, slen, p->jointcapability),
-				ast_getformatname_multiple(s2, slen, p->owner->nativeformats));
+		if (debug) {
+			char s1[BUFSIZ], s2[BUFSIZ];
+			ast_log(LOG_DEBUG, "Oooh, we need to change our audio formats since our peer supports only %s and not %s\n", 
+				ast_getformatname_multiple(s1, BUFSIZ, p->jointcapability),
+				ast_getformatname_multiple(s2, BUFSIZ, p->owner->nativeformats));
+		}
 		p->owner->nativeformats = ast_codec_choose(&p->prefs, p->jointcapability, 1) | (p->capability & vpeercapability);
 		ast_set_read_format(p->owner, p->owner->readformat);
 		ast_set_write_format(p->owner, p->owner->writeformat);
@@ -4867,7 +4869,8 @@
 	char o[256];
 	char c[256];
 	char t[256];
-	char b[256];
+	char b[256] = "";
+	char hold[256] = "";
 	char m_audio[256];
 	char m_video[256];
 	char a_audio[1024];
@@ -4917,7 +4920,7 @@
 		dest.sin_port = sin.sin_port;
 	}
 
-	if(capability & AST_FORMAT_VIDEO_MASK) {
+	if((capability & AST_FORMAT_VIDEO_MASK) && ast_test_flag(&p->flags[0], SIP_NOVIDEO))) {
 		if (p->vrtp) {
 			needvideo = TRUE;
 			if (option_debug)
@@ -4927,8 +4930,8 @@
 	}
 		
 
-	/* Determine video destination */
 	if (needvideo) {
+		/* Determine video destination */
 		if (p->vredirip.sin_addr.s_addr) {
 			vdest.sin_port = p->vredirip.sin_port;
 			vdest.sin_addr = p->vredirip.sin_addr;
@@ -4936,12 +4939,13 @@
 			vdest.sin_addr = p->ourip;
 			vdest.sin_port = vsin.sin_port;
 		}
-	}
-	if (debug) {
-		ast_verbose("We're at %s port %d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ntohs(sin.sin_port));	
-		if (needvideo)
+		/* Build max bitrate string */
+		snprintf(b, sizeof(b), "b=CT:%d\r\n", p->maxcallbitrate);
+		if (debug) 
 			ast_verbose("Video is at %s port %d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ntohs(vsin.sin_port));	
 	}
+	if (debug) 
+		ast_verbose("Audio is at %s port %d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ntohs(sin.sin_port));	
 
 	/* We break with the "recommendation" and send our IP, in order that our
 	   peer doesn't have to ast_gethostbyname() us */
@@ -4950,10 +4954,7 @@
 	snprintf(o, sizeof(o), "o=root %d %d IN IP4 %s\r\n", p->sessionid, p->sessionversion, ast_inet_ntoa(iabuf, sizeof(iabuf), dest.sin_addr));
 	snprintf(s, sizeof(s), "s=session\r\n");
 	snprintf(c, sizeof(c), "c=IN IP4 %s\r\n", ast_inet_ntoa(iabuf, sizeof(iabuf), dest.sin_addr));
-	if ((p->vrtp) &&
-	    (!ast_test_flag(&p->flags[0], SIP_NOVIDEO)) &&
-	    (capability & VIDEO_CODEC_MASK)) /* only if video response is appropriate */
-		snprintf(b, sizeof(b), "b=CT:%d\r\n", p->maxcallbitrate);
+	if (needvideo)
 	snprintf(t, sizeof(t), "t=0 0\r\n");
 
 	ast_build_string(&m_audio_next, &m_audio_left, "m=audio %d RTP/AVP", ntohs(dest.sin_port));
@@ -5000,12 +5001,12 @@
 
 	/* Now send any other common codecs, and non-codec formats: */
 	for (x = 1;
-	     x <= ((ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) && p->vrtp) ? AST_FORMAT_MAX_VIDEO : AST_FORMAT_MAX_AUDIO);
+	     x <= needvideo ? AST_FORMAT_MAX_VIDEO : AST_FORMAT_MAX_AUDIO;
 	     x <<= 1) {
-		if (!(capability & x))
+		if (!(capability & x))	/* Codec not requested */
 			continue;
 
-		if (alreadysent & x)
+		if (alreadysent & x)	/* Already added to SDP */
 			continue;
 
 		if (x <= AST_FORMAT_MAX_AUDIO)
@@ -5039,11 +5040,14 @@
 	ast_build_string(&m_audio_next, &m_audio_left, "\r\n");
 	ast_build_string(&m_video_next, &m_video_left, "\r\n");
 
-	len = strlen(v) + strlen(s) + strlen(o) + strlen(c) + strlen(t) + strlen(m_audio) + strlen(a_audio);
-	if ((p->vrtp) &&
-	    (!ast_test_flag(&p->flags[0], SIP_NOVIDEO)) &&
-	    (capability & VIDEO_CODEC_MASK)) /* only if video response is appropriate */
-		len += strlen(m_video) + strlen(a_video) + strlen(b);
+	if (ast_test_flag(&p->flags[0], SIP_CALL_ONHOLD))
+		sprintf(hold, "a=recvonly");
+	else
+		sprintf(hold, "a=sendrecv");
+
+	len = strlen(v) + strlen(s) + strlen(o) + strlen(c) + strlen(t) + strlen(m_audio) + strlen(a_audio) + strlen(hold);
+	if (needvideo) /* only if video response is appropriate */
+		len += strlen(m_video) + strlen(a_video) + strlen(b) + strlen(hold);
 
 	add_header(resp, "Content-Type", "application/sdp");
 	add_header_contentLength(resp, len);
@@ -5051,18 +5055,16 @@
 	add_line(resp, o);
 	add_line(resp, s);
 	add_line(resp, c);
-	if ((needvideo) &&
-	    (!ast_test_flag(&p->flags[0], SIP_NOVIDEO)) &&
-	    (capability & VIDEO_CODEC_MASK)) /* only if video response is appropriate */
+	if (needvideo) 	/* only if video response is appropriate */
 		add_line(resp, b);
 	add_line(resp, t);
 	add_line(resp, m_audio);
 	add_line(resp, a_audio);
-	if ((p->vrtp) &&
-	    (!ast_test_flag(&p->flags[0], SIP_NOVIDEO)) &&
-	    (capability & VIDEO_CODEC_MASK)) { /* only if video response is appropriate */
+	add_line(resp, hold);
+	if (needvideo) { /* only if video response is appropriate */
 		add_line(resp, m_video);
 		add_line(resp, a_video);
+		add_line(resp, hold);
 	}
 
 	/* Update lastrtprx when we send our SDP */
@@ -10068,14 +10070,14 @@
 	}
 }
 
-/*! \brief Handle SIP response in dialogue */
+/*! \brief Handle SIP response to INVITE dialogue */
 static void handle_response_invite(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno)
 {
 	int outgoing = ast_test_flag(&p->flags[0], SIP_OUTGOING);
 	int res = 0;
+	int reinvite = (p->owner && p->owner->_state == AST_STATE_UP);
 	
 	if (option_debug > 3) {
-		int reinvite = (p->owner && p->owner->_state == AST_STATE_UP);
 		if (reinvite)
 			ast_log(LOG_DEBUG, "SIP response %d to RE-invite on %s call %s\n", resp, outgoing ? "outgoing" : "incoming", p->callid);
 		else
@@ -10133,8 +10135,10 @@
 		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))
-				/* This 200 OK's SDP is not acceptable, so we need to ack, then hangup */
-				ast_set_flag(&p->flags[0], SIP_PENDINGBYE);	
+				if (!reinvite)
+					/* This 200 OK's SDP is not acceptable, so we need to ack, then hangup */
+					/* For re-invites, we try to recover */
+					ast_set_flag(&p->flags[0], SIP_PENDINGBYE);	
 		}
 
 		/* Parse contact header for continued conversation */
@@ -10159,7 +10163,7 @@
 		}
 		
 		if (!ast_test_flag(req, SIP_PKT_IGNORE) && p->owner) {
-			if (p->owner->_state != AST_STATE_UP) {
+			if (!reinvite)
 				ast_queue_control(p->owner, AST_CONTROL_ANSWER);
 			} else {	/* RE-invite */
 				ast_queue_frame(p->owner, &ast_null_frame);
@@ -13851,11 +13855,13 @@
 		changed = 1;
 	}
 	if (changed && !ast_test_flag(&p->flags[0], SIP_GOTREFER)) {
-		if (chan->_state != AST_STATE_UP) {
+		if (chan->_state != AST_STATE_UP) {	/* We are in early state */
 			char iabuf[INET_ADDRSTRLEN];
+			if (recordhistory)
+				append_history(p, "ExtInv", "Initial invite sent with remote bridge proposal.");
 			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) {
+		} else if (!p->pendinginvite) {		/* We are up, and have no outstanding invite */
 			if (option_debug > 2) {
 				char iabuf[INET_ADDRSTRLEN];
 				ast_log(LOG_DEBUG, "Sending reinvite on SIP '%s' - It's audio soon redirected to IP %s\n", p->callid, ast_inet_ntoa(iabuf, sizeof(iabuf), rtp ? p->redirip.sin_addr : p->ourip));
@@ -13866,6 +13872,7 @@
 				char iabuf[INET_ADDRSTRLEN];
 				ast_log(LOG_DEBUG, "Deferring reinvite on SIP '%s' - It's audio will be redirected to IP %s\n", p->callid, ast_inet_ntoa(iabuf, sizeof(iabuf), rtp ? p->redirip.sin_addr : p->ourip));
 			}
+			/* We have a pending Invite. Send re-invite when we're done with the invite */
 			ast_set_flag(&p->flags[0], SIP_NEEDREINVITE);	
 		}
 	}



More information about the asterisk-commits mailing list