[asterisk-commits] branch file/passthrusdp - r7924 in /team/file/passthrusdp: ./ channels/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Jan 9 20:37:12 CST 2006


Author: file
Date: Mon Jan  9 20:37:10 2006
New Revision: 7924

URL: http://svn.digium.com/view/asterisk?rev=7924&view=rev
Log:
Finally add working SDP passthru... just set passthrusdp=yes for the peer or user entry and give it a whirl. It'll automatically fall back onto going through Asterisk if needed. As well MOH doesn't work in passthru mode right now either.

Modified:
    team/file/passthrusdp/channel.c
    team/file/passthrusdp/channels/chan_sip.c

Modified: team/file/passthrusdp/channel.c
URL: http://svn.digium.com/view/asterisk/team/file/passthrusdp/channel.c?rev=7924&r1=7923&r2=7924&view=diff
==============================================================================
--- team/file/passthrusdp/channel.c (original)
+++ team/file/passthrusdp/channel.c Mon Jan  9 20:37:10 2006
@@ -2187,6 +2187,7 @@
 {
 	int res = -1;
 	struct ast_frame *f = NULL;
+	char temp_text[1024] = "";
 	/* Stop if we're a zombie or need a soft hangup */
 	ast_mutex_lock(&chan->lock);
 	if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan))  {
@@ -2230,9 +2231,10 @@
 		CHECK_BLOCKING(chan);
 		break;
 	case AST_FRAME_TEXT:
-		if (chan->tech->send_text)
-			res = chan->tech->send_text(chan, (char *) fr->data);
-		else
+		if (chan->tech->send_text) {
+			strncpy(temp_text, fr->data, fr->datalen);
+			res = chan->tech->send_text(chan, (char *) temp_text);
+		} else
 			res = 0;
 		break;
 	case AST_FRAME_HTML:

Modified: team/file/passthrusdp/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/file/passthrusdp/channels/chan_sip.c?rev=7924&r1=7923&r2=7924&view=diff
==============================================================================
--- team/file/passthrusdp/channels/chan_sip.c (original)
+++ team/file/passthrusdp/channels/chan_sip.c Mon Jan  9 20:37:10 2006
@@ -560,11 +560,13 @@
 #define SIP_CALL_LIMIT		(1 << 29)
 /* Remote Party-ID Support */
 #define SIP_SENDRPID		(1 << 30)
+/* Passthru SDP Support */
+#define SIP_PASSTHRU_SDP        (1 << 31)
 
 #define SIP_FLAGS_TO_COPY \
 	(SIP_PROMISCREDIR | SIP_TRUSTRPID | SIP_SENDRPID | SIP_DTMF | SIP_REINVITE | \
 	 SIP_PROG_INBAND | SIP_OSPAUTH | SIP_USECLIENTCODE | SIP_NAT | \
-	 SIP_INSECURE_PORT | SIP_INSECURE_INVITE)
+	 SIP_INSECURE_PORT | SIP_INSECURE_INVITE | SIP_PASSTHRU_SDP )
 
 /* a new page of flags for peer */
 #define SIP_PAGE2_RTCACHEFRIENDS	(1 << 0)
@@ -613,6 +615,7 @@
 	struct sockaddr_in recv;		/*!< Received as */
 	struct in_addr ourip;			/*!< Our IP */
 	struct ast_channel *owner;		/*!< Who owns us */
+	char *passthru_sdp;                     /*!< Remote party's SDP for passthru */
 	char exten[AST_MAX_EXTENSION];		/*!< Extension where to start */
 	char refer_to[AST_MAX_EXTENSION];	/*!< Place to store REFER-TO extension */
 	char referred_by[AST_MAX_EXTENSION];	/*!< Place to store REFERRED-BY extension */
@@ -1579,7 +1582,15 @@
 		return 0;
 	if (debug)
 		ast_verbose("Really sending text %s on %s\n", text, ast->name);
-	transmit_message_with_text(p, text);
+	/* See if this is potentially an SDP passthru attempt */
+	if (ast_test_flag(p, SIP_PASSTHRU_SDP) && !strncasecmp(text, "v=", 2)) {
+		/* If we already have SDP - free it for now */
+		if (p->passthru_sdp)
+			free(p->passthru_sdp);
+		p->passthru_sdp = strdup(text);
+	} else {
+		transmit_message_with_text(p, text);
+	}
 	return 0;	
 }
 
@@ -2028,6 +2039,8 @@
 		} else if (!p->options->addsipheaders && !strncasecmp(ast_var_name(current), "SIPADDHEADER", strlen("SIPADDHEADER"))) {
 			/* Check whether there is a variable with a name starting with SIPADDHEADER */
 			p->options->addsipheaders = 1;
+		} else if (ast_test_flag(p, SIP_PASSTHRU_SDP) && !p->passthru_sdp && !strcasecmp(ast_var_name(current), "SDP") && strlen(ast_var_value(current))) {
+			p->passthru_sdp = strdup(ast_var_value(current));
 		}
 
 		
@@ -2129,6 +2142,9 @@
 
 	if (p->rpid_from)
 		free(p->rpid_from);
+
+	if (p->passthru_sdp)
+		free(p->passthru_sdp);
 
 	/* Unlink us from the owner if we have one */
 	if (p->owner) {
@@ -2504,6 +2520,12 @@
 		ast_setstate(ast, AST_STATE_UP);
 		if (option_debug)
 			ast_log(LOG_DEBUG, "sip_answer(%s)\n", ast->name);
+		if (ast_test_flag(p, SIP_PASSTHRU_SDP)) {
+			pbx_builtin_setvar_helper(ast, "_SDP", "");
+			/* If we have a local RTP stream setup... get rid of the passthru SDP */
+			if (p->rtp && p->passthru_sdp)
+				free(p->passthru_sdp);
+		}
 		res = transmit_response_with_sdp(p, "200 OK", &p->initreq, 1);
 	}
 	ast_mutex_unlock(&p->lock);
@@ -3382,15 +3404,32 @@
 	int vpeercapability=0, vpeernoncodeccapability=0;
 	struct sockaddr_in sin;
 	char *codecs;
+	char sdp_temp[1024] = "";
 	struct hostent *hp;
 	struct ast_hostent ahp;
+	struct ast_frame f;
 	int codec;
 	int destiterator = 0;
 	int iterator;
 	int sendonly = 0;
-	int x,y;
+	int x,y,i;
 	int debug=sip_debug_test_pvt(p);
 	struct ast_channel *bridgepeer = NULL;
+
+	if (ast_test_flag(p, SIP_PASSTHRU_SDP) && p->passthru_sdp) {
+		for (i=0; i<req->lines; i++) {
+			strcat(sdp_temp, req->line[i]);
+			strcat(sdp_temp, "\n");
+		}
+		memset(&f, 0, sizeof(f));
+                f.frametype = AST_FRAME_TEXT;
+                f.subclass = 0;
+                f.offset = 0;
+                f.data = sdp_temp;
+                f.datalen = strlen(sdp_temp);
+                ast_queue_frame(p->owner, &f);
+		return 0;
+	}
 
 	if (!p->rtp) {
 		ast_log(LOG_ERROR, "Got SDP but have no RTP session allocated.\n");
@@ -4503,7 +4542,11 @@
 		return -1;
 	}
 	respprep(&resp, p, msg, req);
-	if (p->rtp) {
+	if (ast_test_flag(p, SIP_PASSTHRU_SDP) && p->passthru_sdp) {
+                add_header(&resp, "Content-Type", "application/sdp");
+                add_header_contentLength(&resp, strlen(p->passthru_sdp));
+                add_line(&resp, p->passthru_sdp);
+	} else if (p->rtp) {
 		ast_rtp_offered_from_local(p->rtp, 0);
 		add_sdp(&resp, p);
 	} else {
@@ -4915,7 +4958,12 @@
 			}
 		}
 	}
-	if (sdp && p->rtp) {
+	if (p->passthru_sdp) {
+		/* Use provided SDP on transmit */
+		add_header(&req, "Content-Type", "application/sdp");
+		add_header_contentLength(&req, strlen(p->passthru_sdp));
+		add_line(&req, p->passthru_sdp);
+	} else if (sdp && p->rtp) {
 		ast_rtp_offered_from_local(p->rtp, 1);
 		add_sdp(&req, p);
 	} else {
@@ -7917,6 +7965,7 @@
 		ast_cli(fd, "  User=Phone   : %s\n", (ast_test_flag(peer, SIP_USEREQPHONE)?"Yes":"No"));
 		ast_cli(fd, "  Trust RPID   : %s\n", (ast_test_flag(peer, SIP_TRUSTRPID) ? "Yes" : "No"));
 		ast_cli(fd, "  Send RPID    : %s\n", (ast_test_flag(peer, SIP_SENDRPID) ? "Yes" : "No"));
+		ast_cli(fd, "  Passthru SDP : %s\n", (ast_test_flag(peer, SIP_PASSTHRU_SDP) ? "Yes" : "No"));
 
 		/* - is enumerated */
 		ast_cli(fd, "  DTMFmode     : %s\n", dtmfmode2str(ast_test_flag(peer, SIP_DTMF)));
@@ -8254,6 +8303,7 @@
 #define FORMAT  "%-15.15s  %-10.10s  %-11.11s  %5.5d/%5.5d  %-4.4s  %-3.3s %-3.3s  %-15.15s\n"
 	struct sip_pvt *cur;
 	char iabuf[INET_ADDRSTRLEN];
+	char *format = NULL;
 	int numchans = 0;
 	if (argc != 3)
 		return RESULT_SHOWUSAGE;
@@ -8265,11 +8315,15 @@
 		ast_cli(fd, FORMAT3, "Peer", "User", "Call ID", "Extension", "Last state", "Type");
 	while (cur) {
 		if (cur->subscribed == NONE && !subscriptions) {
+			if (cur->passthru_sdp)
+				format = ast_strdupa("pass");
+			else
+				format = ast_getformatname(cur->owner ? cur->owner->nativeformats : 0);
 			ast_cli(fd, FORMAT, ast_inet_ntoa(iabuf, sizeof(iabuf), cur->sa.sin_addr), 
 				ast_strlen_zero(cur->username) ? ( ast_strlen_zero(cur->cid_num) ? "(None)" : cur->cid_num ) : cur->username, 
 				cur->callid, 
-				cur->ocseq, cur->icseq, 
-				ast_getformatname(cur->owner ? cur->owner->nativeformats : 0), 
+				cur->ocseq, cur->icseq,
+				format, 
 				ast_test_flag(cur, SIP_CALL_ONHOLD) ? "Yes" : "No",
 				ast_test_flag(cur, SIP_NEEDDESTROY) ? "(d)" : "",
 				cur->lastmsg );
@@ -10222,6 +10276,8 @@
 static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, int debug, int ignore, int seqno, struct sockaddr_in *sin, int *recount, char *e)
 {
 	int res = 1;
+	int i = 0;
+	char built_sdp[1024] = "";
 	struct ast_channel *c=NULL;
 	int gotdest;
 	struct ast_frame af = { AST_FRAME_NULL, };
@@ -10386,6 +10442,14 @@
 		case AST_STATE_DOWN:
 			transmit_response(p, "100 Trying", req);
 			ast_setstate(c, AST_STATE_RING);
+			if (ast_test_flag(p, SIP_PASSTHRU_SDP)) {
+				for (i=0; i<req->lines; i++) {
+					strcat(built_sdp, req->line[i]);
+					strcat(built_sdp, "\n");
+				}
+				/* Okay... add it to the channel */
+				pbx_builtin_setvar_helper(c, "_SDP", built_sdp);
+			}
 			if (strcmp(p->exten, ast_pickup_ext())) {
 				enum ast_pbx_result res;
 
@@ -11677,6 +11741,10 @@
 	} else if (!strcasecmp(v->name, "promiscredir")) {
 		ast_set_flag(mask, SIP_PROMISCREDIR);
 		ast_set2_flag(flags, ast_true(v->value), SIP_PROMISCREDIR);
+		res = 1;
+	} else if (!strcasecmp(v->name, "passthrusdp")) {
+		ast_set_flag(mask, SIP_PASSTHRU_SDP);
+		ast_set2_flag(flags, ast_true(v->value), SIP_PASSTHRU_SDP);
 		res = 1;
 	}
 



More information about the asterisk-commits mailing list