[svn-commits] branch oej/sdpcleanup r32303 - /team/oej/sdpcleanup/channels/chan_sip.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Mon Jun 5 08:26:42 MST 2006


Author: oej
Date: Mon Jun  5 10:26:42 2006
New Revision: 32303

URL: http://svn.digium.com/view/asterisk?rev=32303&view=rev
Log:
Cleanup, remove debug comments

Modified:
    team/oej/sdpcleanup/channels/chan_sip.c

Modified: team/oej/sdpcleanup/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/oej/sdpcleanup/channels/chan_sip.c?rev=32303&r1=32302&r2=32303&view=diff
==============================================================================
--- team/oej/sdpcleanup/channels/chan_sip.c (original)
+++ team/oej/sdpcleanup/channels/chan_sip.c Mon Jun  5 10:26:42 2006
@@ -3286,7 +3286,7 @@
 
 	/* Set the native formats for audio  and merge in video */
 	tmp->nativeformats = ast_codec_choose(&i->prefs, what, 1) | (i->jointcapability & AST_FORMAT_VIDEO_MASK);
-	if (option_debug) {
+	if (option_debug > 2) {
 		char buf[BUFSIZ];
 		ast_log(LOG_DEBUG, "*** Our native formats are %s \n", ast_getformatname_multiple(buf, BUFSIZ, tmp->nativeformats));
 		ast_log(LOG_DEBUG, "*** Joint capabilities are %s \n", ast_getformatname_multiple(buf, BUFSIZ, i->jointcapability));
@@ -4076,7 +4076,9 @@
 	return 0;
 }
 
-/*! \brief Process SIP SDP, select formats and activate RTP channels */
+/*! \brief Process SIP SDP offer, select formats and activate RTP channels
+	If offer is rejected, we will not change any properties of the call
+*/
 static int process_sdp(struct sip_pvt *p, struct sip_request *req)
 {
 	const char *m;		/* SDP media offer */
@@ -5069,19 +5071,24 @@
 {
 	int len = 0;
 	int alreadysent = 0;
+
 	struct sockaddr_in sin;
 	struct sockaddr_in vsin;
-	char v[10];
-	char s[256];
+	struct sockaddr_in dest;
+	struct sockaddr_in vdest = { 0, };
+
+	/* SDP fields */
+	char *v = 	"v=0\r\n";		/* Version */
+	char *subject = 	"s=session\r\n";	/* Subject of the session */
 	char o[256];
-	char c[256];
-	char t[256] = "";
-	char b[256] = "";
+	char c[256];		/* Connection data */
+	char *t = "";
+	char b[256] = "";	/* Max bitrate */
 	char *hold;
-	char m_audio[256];
-	char m_video[256];
-	char a_audio[1024];
-	char a_video[1024];
+	char m_audio[256];	/* Media declaration line for audio */
+	char m_video[256];	/* Media declaration line for video */
+	char a_audio[1024];	/* Attributes for audio */
+	char a_video[1024];	/* Attributes for video */
 	char *m_audio_next = m_audio;
 	char *m_video_next = m_video;
 	size_t m_audio_left = sizeof(m_audio);
@@ -5090,13 +5097,14 @@
 	char *a_video_next = a_video;
 	size_t a_audio_left = sizeof(a_audio);
 	size_t a_video_left = sizeof(a_video);
+
 	char iabuf[INET_ADDRSTRLEN];
 	int x;
 	int capability;
-	struct sockaddr_in dest;
-	struct sockaddr_in vdest = { 0, };
 	int debug;
 	int needvideo = FALSE;
+
+	m_video[0] = '\0';	/* Reset the video media string if it's not needed */
 	
 	debug = sip_debug_test_pvt(p);
 
@@ -5105,13 +5113,15 @@
 		ast_log(LOG_WARNING, "No way to add SDP without an RTP structure\n");
 		return -1;
 	}
-	capability = p->jointcapability;
-
+
+	/* Set RTP Session ID and version */
 	if (!p->sessionid) {
 		p->sessionid = getpid();
 		p->sessionversion = p->sessionid;
 	} else
 		p->sessionversion++;
+
+	/* Get our addresses */
 	ast_rtp_get_us(p->rtp, &sin);
 	if (p->vrtp)
 		ast_rtp_get_us(p->vrtp, &vsin);
@@ -5126,12 +5136,17 @@
 		dest.sin_addr = p->ourip;
 		dest.sin_port = sin.sin_port;
 	}
+
+	/* Ok, let's start working with codec selection here */
+	capability = p->jointcapability;
+
 	if (option_debug > 1) {
 		char codecbuf[BUFSIZ];
 		ast_log(LOG_DEBUG, "** Our capability: %s Video flag: %s\n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), capability), ast_test_flag(&p->flags[0], SIP_NOVIDEO) ? "True" : "False");
 		ast_log(LOG_DEBUG, "** Our prefcodec: %s \n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), p->prefcodec));
 	}
 
+	/* Check if we need video in this call */
 	if((capability & AST_FORMAT_VIDEO_MASK) && !ast_test_flag(&p->flags[0], SIP_NOVIDEO)) {
 		if (p->vrtp) {
 			needvideo = TRUE;
@@ -5142,20 +5157,27 @@
 	}
 		
 
+	/* Ok, we need video. Let's add what we need for video and set codecs.
+	   Video is handled differently than audio since we can not transcode. */
 	if (needvideo) {
+		t = "t=0 0\r\n";
+		ast_build_string(&m_video_next, &m_video_left, "m=video %d RTP/AVP", ntohs(vdest.sin_port));
+
 		/* Determine video destination */
 		if (p->vredirip.sin_addr.s_addr) {
+			vdest.sin_addr = p->vredirip.sin_addr;
 			vdest.sin_port = p->vredirip.sin_port;
-			vdest.sin_addr = p->vredirip.sin_addr;
 		} else {
 			vdest.sin_addr = p->ourip;
 			vdest.sin_port = vsin.sin_port;
 		}
+
 		/* Build max bitrate string */
 		if (p->maxcallbitrate)
 			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));	
+
 		/* For video, we can't negotiate video offers. Let's compare the incoming call with what we got. */
 		if (p->prefcodec) {
 			int videocapability = (capability & p->prefcodec) & AST_FORMAT_VIDEO_MASK; /* Outbound call */
@@ -5171,7 +5193,8 @@
 
 			/* Replace video capabilities with the new videocapability */
 			capability = (capability & AST_FORMAT_AUDIO_MASK) | videocapability;
-			if (option_debug > 2) {
+
+			if (option_debug > 4) {
 				char codecbuf[BUFSIZ];
 				if (videocapability)
 					ast_log(LOG_DEBUG, "** Our video codec selection is: %s \n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), videocapability));
@@ -5182,25 +5205,29 @@
 	if (debug) 
 		ast_verbose("Audio is at %s port %d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ntohs(sin.sin_port));	
 
+	/* Start building generic SDP headers */
+
 	/* We break with the "recommendation" and send our IP, in order that our
 	   peer doesn't have to ast_gethostbyname() us */
 
-	snprintf(v, sizeof(v), "v=0\r\n");
 	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 (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));
-	ast_build_string(&m_video_next, &m_video_left, "m=video %d RTP/AVP", ntohs(vdest.sin_port));
 
 	if (ast_test_flag(&p->flags[0], SIP_CALL_ONHOLD))
 		hold = "a=recvonly\r\n";
 	else
 		hold = "a=sendrecv\r\n";
 
-	/* Prefer the audio codec we were requested to use, first, no matter what */
+	/* Now, start adding audio codecs. These are added in this order:
+		- First what was requested by the calling channel
+		- Then preferences in order from sip.conf device config for this peer/user
+		- Then other codecs in capabilities, including video
+	*/
+
+	/* Prefer the audio codec we were requested to use, first, no matter what 
+		Note that p->prefcodec can include video codecs, so mask them out
+	 */
 	if (capability & p->prefcodec) {
 		add_codec_to_sdp(p, p->prefcodec & AST_FORMAT_AUDIO_MASK, 8000,
 				 &m_audio_next, &m_audio_left,
@@ -5209,7 +5236,6 @@
 		alreadysent |= p->prefcodec & AST_FORMAT_AUDIO_MASK;
 	}
 
-	ast_log(LOG_DEBUG, "****** ONE ************************\n");
 
 	/* Start by sending our preferred audio codecs */
 	for (x = 0; x < 32; x++) {
@@ -5230,7 +5256,6 @@
 				 debug);
 		alreadysent |= pref_codec;
 	}
-	ast_log(LOG_DEBUG, "****** TWO ************************\n");
 
 	/* Now send any other common audio and video codecs, and non-codec formats: */
 	for (x = 1; x <= (needvideo ? AST_FORMAT_MAX_VIDEO : AST_FORMAT_MAX_AUDIO); x <<= 1) {
@@ -5247,17 +5272,12 @@
 					 &m_audio_next, &m_audio_left,
 					 &a_audio_next, &a_audio_left,
 					 debug);
-		else {
+		else 
 			add_codec_to_sdp(p, x, 90000,
 					 &m_video_next, &m_video_left,
 					 &a_video_next, &a_video_left,
 					 debug);
-			if (option_debug > 2)
-				ast_log(LOG_DEBUG, "Adding video codec to SDP... %d\n", x);
-		}
-	}
-
-	ast_log(LOG_DEBUG, "****** THREE ************************\n");
+	}
 
 	/* Now add DTMF RFC2833 telephony-event as a codec */
 	for (x = 1; x <= AST_RTP_MAX; x <<= 1) {
@@ -5269,8 +5289,9 @@
 				    &a_audio_next, &a_audio_left,
 				    debug);
 	}
+
 	if (option_debug > 2)
-		ast_log(LOG_DEBUG, "Done with adding codecs to SDP\n");
+		ast_log(LOG_DEBUG, "-- Done with adding codecs to SDP\n");
 
 	if(!ast_internal_timing_enabled(p->owner))
 		ast_build_string(&a_audio_next, &a_audio_left, "a=silenceSupp:off - - - -\r\n");
@@ -5279,13 +5300,10 @@
 		ast_log(LOG_WARNING, "SIP SDP may be truncated due to undersized buffer!!\n");
 
 	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) + strlen(hold);
 	if (needvideo)
-		len += strlen(m_video) + strlen(a_video) + strlen(b) + strlen(hold);
-
-	len = strlen(v) + strlen(s) + strlen(o) + strlen(c) + strlen(t) + strlen(m_audio) + strlen(a_audio) + strlen(hold);
+		ast_build_string(&m_video_next, &m_video_left, "\r\n");
+
+	len = strlen(v) + strlen(subject) + 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);
 
@@ -5293,7 +5311,7 @@
 	add_header_contentLength(resp, len);
 	add_line(resp, v);
 	add_line(resp, o);
-	add_line(resp, s);
+	add_line(resp, subject);
 	add_line(resp, c);
 	if (needvideo) 	/* only if video response is appropriate */
 		add_line(resp, b);
@@ -5304,7 +5322,7 @@
 	if (needvideo) { /* only if video response is appropriate */
 		add_line(resp, m_video);
 		add_line(resp, a_video);
-		add_line(resp, hold);
+		add_line(resp, hold);	/* Repeat hold for the video stream */
 	}
 
 	/* Update lastrtprx when we send our SDP */
@@ -5312,10 +5330,8 @@
 
 	if (option_debug > 2) {
 		char buf[BUFSIZ];
-		ast_log(LOG_DEBUG, "We're settling with offering these formats: %s\n", ast_getformatname_multiple(buf, BUFSIZ, capability));
-	}
-	if (option_debug > 2)
-		ast_log(LOG_DEBUG, "Done building SDP\n");
+		ast_log(LOG_DEBUG, "Done building SDP. Settling with this capability: %s\n", ast_getformatname_multiple(buf, BUFSIZ, capability));
+	}
 
 	return 0;
 }



More information about the svn-commits mailing list