[asterisk-commits] phsultan: branch phsultan/jingle-support r260339 - /team/phsultan/jingle-supp...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Apr 30 08:22:32 CDT 2010


Author: phsultan
Date: Fri Apr 30 08:22:29 2010
New Revision: 260339

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=260339
Log:
Place Jingle calls.

Up to now, Asterisk was only able to receive Jingle calls. This code adds the
ability to place outgoing calls to Jingle clients.

Tested with Pigin (2.6.2 on Linux).

Modified:
    team/phsultan/jingle-support/channels/chan_jingle.c

Modified: team/phsultan/jingle-support/channels/chan_jingle.c
URL: http://svnview.digium.com/svn/asterisk/team/phsultan/jingle-support/channels/chan_jingle.c?view=diff&rev=260339&r1=260338&r2=260339
==============================================================================
--- team/phsultan/jingle-support/channels/chan_jingle.c (original)
+++ team/phsultan/jingle-support/channels/chan_jingle.c Fri Apr 30 08:22:29 2010
@@ -332,7 +332,7 @@
 	transport = iks_new("transport");
 	candidates[0] = iks_new("candidate");
 	candidates[1] = iks_new("candidate");
-	if (!iq || !jingle || !content || !transport || !candidates[0] || !candidates[1]) {
+	if (!iq || !jingle || !content || !dcodecs || !transport || !candidates[0] || !candidates[1]) {
 		ast_log(LOG_ERROR, "Memory allocation error\n");
 		goto safeout;
 	}
@@ -1452,22 +1452,83 @@
 
 static int jingle_transmit_invite(struct jingle_pvt *p)
 {
-	struct jingle *aux = NULL;
+	struct jingle *tmp = NULL;
 	struct aji_client *client = NULL;
 	iks *iq, *jingle, *content, *description, *transport;
-	iks *payload_eg711u, *payload_pcmu;
-
-	aux = p->parent;
-	client = aux->connection;
+	iks *candidates[2];
+	struct jingle_candidate *aux = NULL;
+	int num = 0;
+	char component[16], foundation[16], generation[16], network[16], port[7], priority[16];
+	format_t pref_codec = 0;
+	int alreadysent = 0;
+
+	tmp = p->parent;
+	client = tmp->connection;
 	iq = iks_new("iq");
 	jingle = iks_new(JINGLE_NODE);
 	content = iks_new("content");
 	description = iks_new("description");
 	transport = iks_new("transport");
-	payload_pcmu = iks_new("payload-type");
-	payload_eg711u = iks_new("payload-type");
+	candidates[0] = iks_new("candidate");
+	candidates[1] = iks_new("candidate");
+	if (!iq || !jingle || !content || !description || !transport || !candidates[0] || !candidates[1]) {
+		ast_log(LOG_ERROR, "Memory allocation error\n");
+		goto safeout;
+	}
 
 	ast_copy_string(p->audio_content_name, "asterisk-audio-content", sizeof(p->audio_content_name));
+
+	/* Build our candidates list */
+	for (aux = p->ourcandidates; aux; aux = aux->next) {
+		snprintf(component, sizeof(component), "%u", aux->component);
+		snprintf(foundation, sizeof(foundation), "%u", aux->foundation);
+		snprintf(generation, sizeof(generation), "%u", aux->generation);
+		snprintf(network, sizeof(network), "%u", aux->network);
+		snprintf(port, sizeof(port), "%u", aux->port);
+		snprintf(priority, sizeof(priority), "%u", aux->priority);
+
+		iks_insert_attrib(candidates[num], "id", aux->id);
+		iks_insert_attrib(candidates[num], "component", component);
+		iks_insert_attrib(candidates[num], "foundation", foundation);
+		iks_insert_attrib(candidates[num], "generation", generation);
+		iks_insert_attrib(candidates[num], "ip", aux->ip);
+		iks_insert_attrib(candidates[num], "network", network);
+		iks_insert_attrib(candidates[num], "port", port);
+		iks_insert_attrib(candidates[num], "priority", priority);
+		switch (aux->protocol) {
+		case AJI_PROTOCOL_UDP:
+			iks_insert_attrib(candidates[num], "protocol", "udp");
+			break;
+		case AJI_PROTOCOL_SSLTCP:
+			iks_insert_attrib(candidates[num], "protocol", "ssltcp");
+			break;
+		}
+		switch (aux->type) {
+		case AJI_CONNECT_HOST:
+			iks_insert_attrib(candidates[num], "type", "host");
+			break;
+		case AJI_CONNECT_PRFLX:
+			iks_insert_attrib(candidates[num], "type", "prflx");
+			break;
+		case AJI_CONNECT_RELAY:
+			iks_insert_attrib(candidates[num], "type", "relay");
+			break;
+		case AJI_CONNECT_SRFLX:
+			iks_insert_attrib(candidates[num], "type", "srflx");
+			break;
+		}
+		num ++;
+	}
+
+	/* Add codecs */
+	for (num = 0; num < 64; num++) {
+		if (!(pref_codec = ast_codec_pref_index(&tmp->prefs, num)))
+			break;
+		if (alreadysent & pref_codec)
+			continue;
+		add_codec_to_answer(p, pref_codec, description);
+		alreadysent |= pref_codec;
+	}
 
 	iks_insert_attrib(iq, "type", "set");
 	iks_insert_attrib(iq, "to", p->them);
@@ -1479,19 +1540,19 @@
 	iks_insert_attrib(jingle, "initiator", client->jid->full);
 	iks_insert_attrib(jingle, "xmlns", JINGLE_NS);
 
-	/* For now, we only send one audio based content */
 	iks_insert_attrib(content, "creator", "initiator");
 	iks_insert_attrib(content, "name", p->audio_content_name);
-	iks_insert_attrib(content, "profile", "RTP/AVP");
+	iks_insert_attrib(content, "senders", "both");
+
 	iks_insert_attrib(description, "xmlns", JINGLE_RTP_NS);
 	iks_insert_attrib(description, "media", "audio");
+
 	iks_insert_attrib(transport, "xmlns", JINGLE_ICE_UDP_NS);
-	iks_insert_attrib(payload_pcmu, "id", "0");
-	iks_insert_attrib(payload_pcmu, "name", "PCMU");
-	iks_insert_attrib(payload_eg711u, "id", "100");
-	iks_insert_attrib(payload_eg711u, "name", "EG711U");
-	iks_insert_node(description, payload_pcmu);
-	iks_insert_node(description, payload_eg711u);
+	iks_insert_attrib(transport, "ufrag", p->local_ufrag);
+	iks_insert_attrib(transport, "pwd", p->local_password);
+
+	iks_insert_node(transport, candidates[0]);
+	iks_insert_node(transport, candidates[1]);
 	iks_insert_node(content, description);
 	iks_insert_node(content, transport);
 	iks_insert_node(jingle, content);
@@ -1499,13 +1560,14 @@
 
 	ast_aji_send(client, iq);
 
+safeout:
 	iks_delete(iq);
 	iks_delete(jingle);
 	iks_delete(content);
 	iks_delete(description);
 	iks_delete(transport);
-	iks_delete(payload_eg711u);
-	iks_delete(payload_pcmu);
+	iks_delete(candidates[0]);
+	iks_delete(candidates[1]);
 	return 0;
 }
 




More information about the asterisk-commits mailing list