[asterisk-commits] file: branch file/rtp_engine-mark2 r183691 - /team/file/rtp_engine-mark2/chan...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Mar 23 09:28:35 CDT 2009


Author: file
Date: Mon Mar 23 09:28:31 2009
New Revision: 183691

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=183691
Log:
Move chan_unistim to the RTP engine architecture. A side effect of this is that this module can now participate in a local RTP bridge.

Modified:
    team/file/rtp_engine-mark2/channels/chan_unistim.c

Modified: team/file/rtp_engine-mark2/channels/chan_unistim.c
URL: http://svn.digium.com/svn-view/asterisk/team/file/rtp_engine-mark2/channels/chan_unistim.c?view=diff&rev=183691&r1=183690&r2=183691
==============================================================================
--- team/file/rtp_engine-mark2/channels/chan_unistim.c (original)
+++ team/file/rtp_engine-mark2/channels/chan_unistim.c Mon Mar 23 09:28:31 2009
@@ -60,7 +60,7 @@
 #include "asterisk/module.h"
 #include "asterisk/pbx.h"
 #include "asterisk/event.h"
-#include "asterisk/rtp.h"
+#include "asterisk/rtp_engine.h"
 #include "asterisk/netsock.h"
 #include "asterisk/acl.h"
 #include "asterisk/callerid.h"
@@ -365,7 +365,7 @@
 	/*! Unistim line */
 	struct unistim_line *parent;
 	/*! RTP handle */
-	struct ast_rtp *rtp;
+	struct ast_rtp_instance *rtp;
 	int alreadygone;
 	char ringvolume;
 	char ringstyle;
@@ -711,7 +711,7 @@
 	.send_digit_begin = unistim_senddigit_begin,
 	.send_digit_end = unistim_senddigit_end,
 	.send_text = unistim_sendtext,
-/*      .bridge = ast_rtp_bridge, */
+	.bridge = ast_rtp_instance_bridge,
 };
 
 static void display_last_error(const char *sz_msg)
@@ -1854,7 +1854,7 @@
 static void swap_subs(struct unistim_line *p, int a, int b)
 {
 /*  struct ast_channel *towner; */
-	struct ast_rtp *rtp;
+	struct ast_rtp_instance *rtp;
 	int fds;
 
 	if (unistimdebug)
@@ -2056,30 +2056,29 @@
 	/* Allocate the RTP */
 	if (unistimdebug)
 		ast_verb(0, "Starting RTP. Bind on %s\n", ast_inet_ntoa(sout.sin_addr));
-	sub->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, sout.sin_addr);
+	sub->rtp = ast_rtp_instance_new(NULL, sched, &sout, NULL);
 	if (!sub->rtp) {
 		ast_log(LOG_WARNING, "Unable to create RTP session: %s binaddr=%s\n",
 				strerror(errno), ast_inet_ntoa(sout.sin_addr));
 		ast_mutex_unlock(&sub->lock);
 		return;
 	}
-	if (sub->rtp && sub->owner) {
-		sub->owner->fds[0] = ast_rtp_fd(sub->rtp);
-		sub->owner->fds[1] = ast_rtcp_fd(sub->rtp);
-	}
-	if (sub->rtp) {
-		ast_rtp_setqos(sub->rtp, qos.tos_audio, qos.cos_audio, "UNISTIM RTP");
-		ast_rtp_setnat(sub->rtp, sub->parent->parent->nat);
-	}
+	ast_rtp_instance_set_prop(sub->rtp, AST_RTP_PROPERTY_RTCP, 1);
+	if (sub->owner) {
+		sub->owner->fds[0] = ast_rtp_instance_fd(sub->rtp, 0);
+		sub->owner->fds[1] = ast_rtp_instance_fd(sub->rtp, 1);
+	}
+	ast_rtp_instance_set_qos(sub->rtp, qos.tos_audio, qos.cos_audio, "UNISTIM RTP");
+	ast_rtp_instance_set_prop(sub->rtp, AST_RTP_PROPERTY_NAT, sub->parent->parent->nat);
 
 	/* Create the RTP connection */
-	ast_rtp_get_us(sub->rtp, &us);
+	memcpy(&us, &sub->rtp->local_address, sizeof(us));
 	sin.sin_family = AF_INET;
 	/* Setting up RTP for our side */
 	memcpy(&sin.sin_addr, &sub->parent->parent->session->sin.sin_addr,
 		   sizeof(sin.sin_addr));
 	sin.sin_port = htons(sub->parent->parent->rtp_port);
-	ast_rtp_set_peer(sub->rtp, &sin);
+	ast_rtp_instance_set_remote_address(sub->rtp, &sin);
 	if (!(sub->owner->nativeformats & sub->owner->readformat)) {
 		int fmt;
 		fmt = ast_best_codec(sub->owner->nativeformats);
@@ -2091,7 +2090,7 @@
 		sub->owner->readformat = fmt;
 		sub->owner->writeformat = fmt;
 	}
-	codec = ast_rtp_lookup_code(sub->rtp, 1, sub->owner->readformat);
+	codec = ast_rtp_codecs_payload_code(&sub->rtp->codecs, 1, sub->owner->readformat);
 	/* Setting up RTP of the phone */
 	if (public_ip.sin_family == 0)  /* NAT IP override ?   */
 		memcpy(&public, &us, sizeof(public));   /* No defined, using IP from recvmsg  */
@@ -3724,7 +3723,7 @@
 		if (sub->rtp) {
 			if (unistimdebug)
 				ast_verb(0, "Destroying RTP session\n");
-			ast_rtp_destroy(sub->rtp);
+			ast_rtp_instance_destroy(sub->rtp);
 			sub->rtp = NULL;
 		}
 		return 0;
@@ -3769,7 +3768,7 @@
 		if (sub->rtp) {
 			if (unistimdebug)
 				ast_verb(0, "Destroying RTP session\n");
-			ast_rtp_destroy(sub->rtp);
+			ast_rtp_instance_destroy(sub->rtp);
 			sub->rtp = NULL;
 		}
 		return 0;
@@ -3794,7 +3793,7 @@
 	if (sub->rtp) {
 		if (unistimdebug)
 			ast_verb(0, "Destroying RTP session\n");
-		ast_rtp_destroy(sub->rtp);
+		ast_rtp_instance_destroy(sub->rtp);
 		sub->rtp = NULL;
 	} else if (unistimdebug)
 		ast_verb(0, "No RTP session to destroy\n");
@@ -3921,10 +3920,10 @@
 
 	switch (ast->fdno) {
 	case 0:
-		f = ast_rtp_read(sub->rtp);     /* RTP Audio */
+		f = ast_rtp_instance_read(sub->rtp, 0);     /* RTP Audio */
 		break;
 	case 1:
-		f = ast_rtcp_read(sub->rtp);    /* RTCP Control Channel */
+		f = ast_rtp_instance_read(sub->rtp, 1);    /* RTCP Control Channel */
 		break;
 	default:
 		f = &ast_null_frame;
@@ -3990,7 +3989,7 @@
 	if (sub) {
 		ast_mutex_lock(&sub->lock);
 		if (sub->rtp) {
-			res = ast_rtp_write(sub->rtp, frame);
+			res = ast_rtp_instance_write(sub->rtp, frame);
 		}
 		ast_mutex_unlock(&sub->lock);
 	}
@@ -4456,8 +4455,8 @@
 	if ((sub->rtp) && (sub->subtype == 0)) {
 		if (unistimdebug)
 			ast_verb(0, "New unistim channel with a previous rtp handle ?\n");
-		tmp->fds[0] = ast_rtp_fd(sub->rtp);
-		tmp->fds[1] = ast_rtcp_fd(sub->rtp);
+		tmp->fds[0] = ast_rtp_instance_fd(sub->rtp, 0);
+		tmp->fds[1] = ast_rtp_instance_fd(sub->rtp, 1);
 	}
 	if (sub->rtp)
 		ast_jb_configure(tmp, &global_jbconf);
@@ -5527,51 +5526,18 @@
 	return 0;
 }
 
-static enum ast_rtp_get_result unistim_get_vrtp_peer(struct ast_channel *chan, 
-	struct ast_rtp **rtp)
-{
-	return AST_RTP_TRY_NATIVE;
-}
-
-static enum ast_rtp_get_result unistim_get_rtp_peer(struct ast_channel *chan, 
-	struct ast_rtp **rtp)
-{
-	struct unistim_subchannel *sub;
-	enum ast_rtp_get_result res = AST_RTP_GET_FAILED;
-
-	if (unistimdebug)
-		ast_verb(0, "unistim_get_rtp_peer called\n");
-		
-	sub = chan->tech_pvt;
-	if (sub && sub->rtp) {
-		*rtp = sub->rtp;
-		res = AST_RTP_TRY_NATIVE;
-	}
-
-	return res;
-}
-
-static int unistim_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, 
-	struct ast_rtp *vrtp, struct ast_rtp *trtp, int codecs, int nat_active)
-{
-	struct unistim_subchannel *sub;
-
-	if (unistimdebug)
-		ast_verb(0, "unistim_set_rtp_peer called\n");
-
-	sub = chan->tech_pvt;
-
-	if (sub)
-		return 0;
-
-	return -1;
-}
-
-static struct ast_rtp_protocol unistim_rtp = {
+static enum ast_rtp_glue_result unistim_get_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance **instance)
+{
+	struct unistim_subchannel *sub = chan->tech_pvt;
+
+	*instance = sub->rtp;
+
+	return AST_RTP_GLUE_RESULT_LOCAL;
+}
+
+static struct ast_rtp_glue unistim_rtp_glue = {
 	.type = channel_type,
 	.get_rtp_info = unistim_get_rtp_peer,
-	.get_vrtp_info = unistim_get_vrtp_peer,
-	.set_rtp_peer = unistim_set_rtp_peer,
 };
 
 /*--- load_module: PBX load module - initialization ---*/
@@ -5604,7 +5570,7 @@
 		goto chanreg_failed;
 	} 
 
-	ast_rtp_proto_register(&unistim_rtp);
+	ast_rtp_glue_register(&unistim_rtp_glue);
 
 	ast_cli_register_multiple(unistim_cli, ARRAY_LEN(unistim_cli));
 
@@ -5635,7 +5601,7 @@
 	ast_cli_unregister_multiple(unistim_cli, ARRAY_LEN(unistim_cli));
 
 	ast_channel_unregister(&unistim_tech);
-	ast_rtp_proto_unregister(&unistim_rtp);
+	ast_rtp_glue_unregister(&unistim_rtp_glue);
 
 	ast_mutex_lock(&monlock);
 	if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP) && (monitor_thread != AST_PTHREADT_NULL)) {




More information about the asterisk-commits mailing list