[asterisk-commits] file: branch file/rtp_engine-mark2 r183697 - in /team/file/rtp_engine-mark2: ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Mar 23 12:07:53 CDT 2009


Author: file
Date: Mon Mar 23 12:07:49 2009
New Revision: 183697

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=183697
Log:
Move chan_gtalk over to using the RTP engine architecture.

Modified:
    team/file/rtp_engine-mark2/channels/chan_gtalk.c
    team/file/rtp_engine-mark2/include/asterisk/rtp_engine.h
    team/file/rtp_engine-mark2/main/rtp_engine.c
    team/file/rtp_engine-mark2/res/res_rtp_asterisk.c

Modified: team/file/rtp_engine-mark2/channels/chan_gtalk.c
URL: http://svn.digium.com/svn-view/asterisk/team/file/rtp_engine-mark2/channels/chan_gtalk.c?view=diff&rev=183697&r1=183696&r2=183697
==============================================================================
--- team/file/rtp_engine-mark2/channels/chan_gtalk.c (original)
+++ team/file/rtp_engine-mark2/channels/chan_gtalk.c Mon Mar 23 12:07:49 2009
@@ -52,7 +52,8 @@
 #include "asterisk/pbx.h"
 #include "asterisk/sched.h"
 #include "asterisk/io.h"
-#include "asterisk/rtp.h"
+#include "asterisk/rtp_engine.h"
+#include "asterisk/stun.h"
 #include "asterisk/acl.h"
 #include "asterisk/callerid.h"
 #include "asterisk/file.h"
@@ -112,8 +113,8 @@
 	char cid_name[80];               /*!< Caller ID name */
 	char exten[80];                  /*!< Called extension */
 	struct ast_channel *owner;       /*!< Master Channel */
-	struct ast_rtp *rtp;             /*!< RTP audio session */
-	struct ast_rtp *vrtp;            /*!< RTP video session */
+	struct ast_rtp_instance *rtp;             /*!< RTP audio session */
+	struct ast_rtp_instance *vrtp;            /*!< RTP video session */
 	int jointcapability;             /*!< Supported capability at both ends (codecs ) */
 	int peercapability;
 	struct gtalk_pvt *next;	/* Next entity */
@@ -183,11 +184,6 @@
 static struct gtalk_pvt *gtalk_alloc(struct gtalk *client, const char *us, const char *them, const char *sid);
 static char *gtalk_do_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 static char *gtalk_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
-/*----- RTP interface functions */
-static int gtalk_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp,
-							   struct ast_rtp *vrtp, struct ast_rtp *trtp, int codecs, int nat_active);
-static enum ast_rtp_get_result gtalk_get_rtp_peer(struct ast_channel *chan, struct ast_rtp **rtp);
-static int gtalk_get_codec(struct ast_channel *chan);
 
 /*! \brief PBX interface structure for channel registration */
 static const struct ast_channel_tech gtalk_tech = {
@@ -197,7 +193,7 @@
 	.requester = gtalk_request,
 	.send_digit_begin = gtalk_digit_begin,
 	.send_digit_end = gtalk_digit_end,
-	.bridge = ast_rtp_bridge,
+	.bridge = ast_rtp_instance_bridge,
 	.call = gtalk_call,
 	.hangup = gtalk_hangup,
 	.answer = gtalk_answer,
@@ -215,14 +211,6 @@
 static struct sched_context *sched;	/*!< The scheduling context */
 static struct io_context *io;	/*!< The IO context */
 static struct in_addr __ourip;
-
-/*! \brief RTP driver interface */
-static struct ast_rtp_protocol gtalk_rtp = {
-	type: "Gtalk",
-	get_rtp_info: gtalk_get_rtp_peer,
-	set_rtp_peer: gtalk_set_rtp_peer,
-	get_codec: gtalk_get_codec,
-};
 
 static struct ast_cli_entry gtalk_cli[] = {
 	AST_CLI_DEFINE(gtalk_do_reload, "Reload GoogleTalk configuration"),
@@ -371,7 +359,7 @@
 		iks_insert_node(dcodecs, payload_gsm);
 		res++;
 	}
-	ast_rtp_lookup_code(p->rtp, 1, codec);
+
 	return res;
 }
 
@@ -523,18 +511,18 @@
 	return res;
 }
 
-static enum ast_rtp_get_result gtalk_get_rtp_peer(struct ast_channel *chan, struct ast_rtp **rtp)
+static enum ast_rtp_glue_result gtalk_get_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance **instance)
 {
 	struct gtalk_pvt *p = chan->tech_pvt;
-	enum ast_rtp_get_result res = AST_RTP_GET_FAILED;
+	enum ast_rtp_glue_result res = AST_RTP_GLUE_RESULT_FORBID;
 
 	if (!p)
 		return res;
 
 	ast_mutex_lock(&p->lock);
 	if (p->rtp){
-		*rtp = p->rtp;
-		res = AST_RTP_TRY_PARTIAL;
+		*instance = p->rtp;
+		res = AST_RTP_GLUE_RESULT_LOCAL;
 	}
 	ast_mutex_unlock(&p->lock);
 
@@ -547,7 +535,7 @@
 	return p->peercapability;
 }
 
-static int gtalk_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, struct ast_rtp *trtp, int codecs, int nat_active)
+static int gtalk_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp, struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, int codecs, int nat_active)
 {
 	struct gtalk_pvt *p;
 
@@ -566,6 +554,13 @@
 	ast_mutex_unlock(&p->lock);
 	return 0;
 }
+
+static struct ast_rtp_glue gtalk_rtp_glue = {
+	.type = "Gtalk",
+	.get_rtp_info = gtalk_get_rtp_peer,
+	.get_codec = gtalk_get_codec,
+	.update_peer = gtalk_set_rtp_peer,
+};
 
 static int gtalk_response(struct gtalk *client, char *from, ikspak *pak, const char *reasonstr, const char *reasonstr2)
 {
@@ -617,13 +612,13 @@
 	/* codec points to the first <payload-type/> tag */
 	codec = iks_child(iks_child(iks_child(pak->x)));
 	while (codec) {
-		ast_rtp_set_m_type(tmp->rtp, atoi(iks_find_attrib(codec, "id")));
-		ast_rtp_set_rtpmap_type(tmp->rtp, atoi(iks_find_attrib(codec, "id")), "audio", iks_find_attrib(codec, "name"), 0);
+		ast_rtp_codecs_payloads_set_m_type(&tmp->rtp->codecs, tmp->rtp, atoi(iks_find_attrib(codec, "id")));
+		ast_rtp_codecs_payloads_set_rtpmap_type(&tmp->rtp->codecs, tmp->rtp, atoi(iks_find_attrib(codec, "id")), "audio", iks_find_attrib(codec, "name"), 0);
 		codec = iks_next(codec);
 	}
 	
 	/* Now gather all of the codecs that we are asked for */
-	ast_rtp_get_current_formats(tmp->rtp, &tmp->peercapability, &peernoncodeccapability);
+	ast_rtp_codecs_payload_formats(&tmp->rtp->codecs, &tmp->peercapability, &peernoncodeccapability);
 	
 	/* at this point, we received an awser from the remote Gtalk client,
 	   which allows us to compare capabilities */
@@ -810,7 +805,7 @@
 		goto safeout;
 	}
 
-	ast_rtp_get_us(p->rtp, &sin);
+	memcpy(&sin, &p->rtp->local_address, sizeof(sin));
 	ast_find_ourip(&us, bindaddr);
 	if (!strcmp(ast_inet_ntoa(us), "127.0.0.1")) {
 		ast_log(LOG_WARNING, "Found a loopback IP on the system, check your network configuration or set the bindaddr attribute.");
@@ -951,8 +946,9 @@
 		tmp->initiator = 1;
 	}
 	/* clear codecs */
-	tmp->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
-	ast_rtp_pt_clear(tmp->rtp);
+	tmp->rtp = ast_rtp_instance_new(NULL, sched, &bindaddr, NULL);
+	ast_rtp_instance_set_prop(tmp->rtp, AST_RTP_PROPERTY_RTCP, 1);
+	ast_rtp_codecs_payloads_clear(&tmp->rtp->codecs, tmp->rtp);
 
 	/* add user configured codec capabilites */
 	if (client->capability)
@@ -1014,20 +1010,20 @@
 
 	/* Set Frame packetization */
 	if (i->rtp)
-		ast_rtp_codec_setpref(i->rtp, &i->prefs);
+		ast_rtp_codecs_packetization_set(&i->rtp->codecs, i->rtp, &i->prefs);
 
 	tmp->nativeformats = ast_codec_choose(&i->prefs, what, 1) | (i->jointcapability & AST_FORMAT_VIDEO_MASK);
 	fmt = ast_best_codec(tmp->nativeformats);
 
 	if (i->rtp) {
-		ast_rtp_setstun(i->rtp, 1);
-		ast_channel_set_fd(tmp, 0, ast_rtp_fd(i->rtp));
-		ast_channel_set_fd(tmp, 1, ast_rtcp_fd(i->rtp));
+		ast_rtp_instance_set_prop(i->rtp, AST_RTP_PROPERTY_STUN, 1);
+		ast_channel_set_fd(tmp, 0, ast_rtp_instance_fd(i->rtp, 0));
+		ast_channel_set_fd(tmp, 1, ast_rtp_instance_fd(i->rtp, 1));
 	}
 	if (i->vrtp) {
-		ast_rtp_setstun(i->rtp, 1);
-		ast_channel_set_fd(tmp, 2, ast_rtp_fd(i->vrtp));
-		ast_channel_set_fd(tmp, 3, ast_rtcp_fd(i->vrtp));
+		ast_rtp_instance_set_prop(i->vrtp, AST_RTP_PROPERTY_STUN, 1);
+		ast_channel_set_fd(tmp, 2, ast_rtp_instance_fd(i->vrtp, 0));
+		ast_channel_set_fd(tmp, 3, ast_rtp_instance_fd(i->vrtp, 1));
 	}
 	if (state == AST_STATE_RING)
 		tmp->rings = 1;
@@ -1142,9 +1138,9 @@
 	if (p->owner)
 		ast_log(LOG_WARNING, "Uh oh, there's an owner, this is going to be messy.\n");
 	if (p->rtp)
-		ast_rtp_destroy(p->rtp);
+		ast_rtp_instance_destroy(p->rtp);
 	if (p->vrtp)
-		ast_rtp_destroy(p->vrtp);
+		ast_rtp_instance_destroy(p->vrtp);
 	gtalk_free_candidates(p->theircandidates);
 	ast_free(p);
 }
@@ -1207,13 +1203,13 @@
 	codec = iks_child(iks_child(iks_child(pak->x)));
 	
 	while (codec) {
-		ast_rtp_set_m_type(p->rtp, atoi(iks_find_attrib(codec, "id")));
-		ast_rtp_set_rtpmap_type(p->rtp, atoi(iks_find_attrib(codec, "id")), "audio", iks_find_attrib(codec, "name"), 0);
+		ast_rtp_codecs_payloads_set_m_type(&p->rtp->codecs, p->rtp, atoi(iks_find_attrib(codec, "id")));
+		ast_rtp_codecs_payloads_set_rtpmap_type(&p->rtp->codecs, p->rtp, atoi(iks_find_attrib(codec, "id")), "audio", iks_find_attrib(codec, "name"), 0);
 		codec = iks_next(codec);
 	}
 	
 	/* Now gather all of the codecs that we are asked for */
-	ast_rtp_get_current_formats(p->rtp, &p->peercapability, &peernoncodeccapability);
+	ast_rtp_codecs_payload_formats(&p->rtp->codecs, &p->peercapability, &peernoncodeccapability);
 	p->jointcapability = p->capability & p->peercapability;
 	ast_mutex_unlock(&p->lock);
 		
@@ -1277,16 +1273,16 @@
 			 p->ourcandidates->username);
 		
 		/* Find out the result of the STUN */
-		ast_rtp_get_peer(p->rtp, &aux);
+		memcpy(&aux, &p->rtp->remote_address, sizeof(aux));
 
 		/* If the STUN result is different from the IP of the hostname,
 			lock on the stun IP of the hostname advertised by the
 			remote client */
 		if (aux.sin_addr.s_addr && 
 		    aux.sin_addr.s_addr != sin.sin_addr.s_addr)
-			ast_rtp_stun_request(p->rtp, &aux, username);
+			ast_rtp_instance_stun_request(p->rtp, &aux, username);
 		else 
-			ast_rtp_stun_request(p->rtp, &sin, username);
+			ast_rtp_instance_stun_request(p->rtp, &sin, username);
 		
 		if (aux.sin_addr.s_addr) {
 			ast_debug(4, "Receiving RTP traffic from IP %s, matches with remote candidate's IP %s\n", ast_inet_ntoa(aux.sin_addr), tmp->ip);
@@ -1387,7 +1383,7 @@
 
 	if (!p->rtp)
 		return &ast_null_frame;
-	f = ast_rtp_read(p->rtp);
+	f = ast_rtp_instance_read(p->rtp, 0);
 	gtalk_update_stun(p->parent, p);
 	if (p->owner) {
 		/* We already hold the channel lock */
@@ -1438,7 +1434,7 @@
 		if (p) {
 			ast_mutex_lock(&p->lock);
 			if (p->rtp) {
-				res = ast_rtp_write(p->rtp, frame);
+				res = ast_rtp_instance_write(p->rtp, frame);
 			}
 			ast_mutex_unlock(&p->lock);
 		}
@@ -1447,7 +1443,7 @@
 		if (p) {
 			ast_mutex_lock(&p->lock);
 			if (p->vrtp) {
-				res = ast_rtp_write(p->vrtp, frame);
+				res = ast_rtp_instance_write(p->vrtp, frame);
 			}
 			ast_mutex_unlock(&p->lock);
 		}
@@ -2062,7 +2058,7 @@
 		return 0;
 	}
 
-	ast_rtp_proto_register(&gtalk_rtp);
+	ast_rtp_glue_register(&gtalk_rtp_glue);
 	ast_cli_register_multiple(gtalk_cli, ARRAY_LEN(gtalk_cli));
 
 	/* Make sure we can register our channel type */
@@ -2086,7 +2082,7 @@
 	ast_cli_unregister_multiple(gtalk_cli, ARRAY_LEN(gtalk_cli));
 	/* First, take us out of the channel loop */
 	ast_channel_unregister(&gtalk_tech);
-	ast_rtp_proto_unregister(&gtalk_rtp);
+	ast_rtp_glue_unregister(&gtalk_rtp_glue);
 
 	if (!ast_mutex_lock(&gtalklock)) {
 		/* Hangup all interfaces if they have an owner */

Modified: team/file/rtp_engine-mark2/include/asterisk/rtp_engine.h
URL: http://svn.digium.com/svn-view/asterisk/team/file/rtp_engine-mark2/include/asterisk/rtp_engine.h?view=diff&rev=183697&r1=183696&r2=183697
==============================================================================
--- team/file/rtp_engine-mark2/include/asterisk/rtp_engine.h (original)
+++ team/file/rtp_engine-mark2/include/asterisk/rtp_engine.h Mon Mar 23 12:07:49 2009
@@ -346,6 +346,8 @@
 	int (*dtmf_compatible)(struct ast_channel *chan0, struct ast_rtp_instance *instance0, struct ast_channel *chan1, struct ast_rtp_instance *instance1);
 	/*! Callback to indicate that packets will now flow */
 	int (*activate)(struct ast_rtp_instance *instance);
+	/*! Callback to request that the RTP engine send a STUN BIND request */
+	void (*stun_request)(struct ast_rtp_instance *instance, struct sockaddr_in *suggestion, const char *username);
 	/*! Linked list information */
 	AST_RWLIST_ENTRY(ast_rtp_engine) entry;
 };
@@ -1213,6 +1215,23 @@
  */
 int ast_rtp_instance_activate(struct ast_rtp_instance *instance);
 
+/*! \brief Request that the underlying RTP engine send a STUN BIND request
+ *
+ * \param instance The RTP instance
+ * \param suggestion The suggested destination
+ * \param username Optionally a username for the request
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_instance_stun_request(instance, NULL, NULL);
+ * \endcode
+ *
+ * This requests that the RTP engine send a STUN BIND request on the session pointed to by
+ * 'instance'.
+ */
+void ast_rtp_instance_stun_request(struct ast_rtp_instance *instance, struct sockaddr_in *suggestion, const char *username);
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif

Modified: team/file/rtp_engine-mark2/main/rtp_engine.c
URL: http://svn.digium.com/svn-view/asterisk/team/file/rtp_engine-mark2/main/rtp_engine.c?view=diff&rev=183697&r1=183696&r2=183697
==============================================================================
--- team/file/rtp_engine-mark2/main/rtp_engine.c (original)
+++ team/file/rtp_engine-mark2/main/rtp_engine.c Mon Mar 23 12:07:49 2009
@@ -1448,3 +1448,10 @@
 {
 	return instance->engine->activate ? instance->engine->activate(instance) : 0;
 }
+
+void ast_rtp_instance_stun_request(struct ast_rtp_instance *instance, struct sockaddr_in *suggestion, const char *username)
+{
+	if (instance->engine->stun_request) {
+		instance->engine->stun_request(instance, suggestion, username);
+	}
+}

Modified: team/file/rtp_engine-mark2/res/res_rtp_asterisk.c
URL: http://svn.digium.com/svn-view/asterisk/team/file/rtp_engine-mark2/res/res_rtp_asterisk.c?view=diff&rev=183697&r1=183696&r2=183697
==============================================================================
--- team/file/rtp_engine-mark2/res/res_rtp_asterisk.c (original)
+++ team/file/rtp_engine-mark2/res/res_rtp_asterisk.c Mon Mar 23 12:07:49 2009
@@ -255,6 +255,7 @@
 static int ast_rtp_local_bridge(struct ast_rtp_instance *instance0, struct ast_rtp_instance *instance1);
 static int ast_rtp_get_stat(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat);
 static int ast_rtp_dtmf_compatible(struct ast_channel *chan0, struct ast_rtp_instance *instance0, struct ast_channel *chan1, struct ast_rtp_instance *instance1);
+static void ast_rtp_stun_request(struct ast_rtp_instance *instance, struct sockaddr_in *suggestion, const char *username);
 
 /* RTP Engine Declaration */
 static struct ast_rtp_engine asterisk_rtp_engine = {
@@ -274,6 +275,7 @@
 	.local_bridge = ast_rtp_local_bridge,
 	.get_stat = ast_rtp_get_stat,
 	.dtmf_compatible = ast_rtp_dtmf_compatible,
+	.stun_request = ast_rtp_stun_request,
 };
 
 static inline int rtp_debug_test_addr(struct sockaddr_in *addr)
@@ -2236,6 +2238,13 @@
 	return (((instance0->properties[AST_RTP_PROPERTY_DTMF] != instance1->properties[AST_RTP_PROPERTY_DTMF]) || (!chan0->tech->send_digit_begin != !chan1->tech->send_digit_begin)) ? 0 : 1);
 }
 
+static void ast_rtp_stun_request(struct ast_rtp_instance *instance, struct sockaddr_in *suggestion, const char *username)
+{
+	struct ast_rtp *rtp = instance->data;
+
+	ast_stun_request(rtp->s, suggestion, username, NULL);
+}
+
 static char *rtp_do_debug_ip(struct ast_cli_args *a)
 {
 	struct hostent *hp;




More information about the asterisk-commits mailing list