[svn-commits] file: branch group/media_formats r408293 - /team/group/media_formats/channels/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Feb 18 06:33:29 CST 2014


Author: file
Date: Tue Feb 18 06:32:17 2014
New Revision: 408293

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=408293
Log:
Move chan_gtalk over.

Modified:
    team/group/media_formats/channels/chan_gtalk.c

Modified: team/group/media_formats/channels/chan_gtalk.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/channels/chan_gtalk.c?view=diff&rev=408293&r1=408292&r2=408293
==============================================================================
--- team/group/media_formats/channels/chan_gtalk.c (original)
+++ team/group/media_formats/channels/chan_gtalk.c Tue Feb 18 06:32:17 2014
@@ -87,6 +87,7 @@
 #include "asterisk/jingle.h"
 #include "asterisk/parking.h"
 #include "asterisk/stasis_channels.h"
+#include "asterisk/format_cache.h"
 
 #define GOOGLE_CONFIG		"gtalk.conf"
 
@@ -123,7 +124,6 @@
 	iksrule *ringrule;               /*!< Rule for matching RING request */
 	int initiator;                   /*!< If we're the initiator */
 	int alreadygone;
-	struct ast_codec_pref prefs;
 	struct gtalk_candidate *theircandidates;
 	struct gtalk_candidate *ourcandidates;
 	char cid_num[80];                /*!< Caller ID num */
@@ -158,7 +158,6 @@
 	struct aji_client *connection;
 	struct aji_buddy *buddy;
 	struct gtalk_pvt *p;
-	struct ast_codec_pref prefs;
 	int amaflags;			/*!< AMA Flags */
 	char user[AJI_MAX_JIDLEN];
 	char context[AST_MAX_CONTEXT];
@@ -259,7 +258,7 @@
 
 static void gtalk_member_destroy(struct gtalk *obj)
 {
-	obj->cap = ast_format_cap_destroy(obj->cap);
+	ao2_cleanup(obj->cap);
 	if (obj->connection) {
 		ASTOBJ_UNREF(obj->connection, ast_aji_client_destroy);
 	}
@@ -306,7 +305,7 @@
 static int add_codec_to_answer(const struct gtalk_pvt *p, struct ast_format *codec, iks *dcodecs)
 {
 	int res = 0;
-	const char *format = ast_getformatname(codec);
+	const char *format = codec->codec->name;
 
 	if (!strcasecmp("ulaw", format)) {
 		iks *payload_eg711u, *payload_pcmu;
@@ -413,10 +412,8 @@
 	struct gtalk *client = p->parent;
 	iks *iq, *gtalk, *dcodecs, *payload_telephone, *transport;
 	int x;
-	struct ast_format_cap *alreadysent;
 	int codecs_num = 0;
 	char *lowerto = NULL;
-	struct ast_format tmpfmt;
 
 	iq = iks_new("iq");
 	gtalk = iks_new("session");
@@ -436,23 +433,12 @@
 	iks_insert_attrib(dcodecs, "xmlns", GOOGLE_AUDIO_NS);
 	iks_insert_attrib(dcodecs, "xml:lang", "en");
 
-	if (!(alreadysent = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK))) {
-		return 0;
-	}
-	for (x = 0; x < AST_CODEC_PREF_SIZE; x++) {
-		if (!(ast_codec_pref_index(&client->prefs, x, &tmpfmt))) {
-			break;
-		}
-		if (!(ast_format_cap_iscompatible(client->cap, &tmpfmt))) {
-			continue;
-		}
-		if (ast_format_cap_iscompatible(alreadysent, &tmpfmt)) {
-			continue;
-		}
-		codecs_num = add_codec_to_answer(p, &tmpfmt, dcodecs);
-		ast_format_cap_add(alreadysent, &tmpfmt);
-	}
-	alreadysent = ast_format_cap_destroy(alreadysent);
+	for (x = 0; x < ast_format_cap_count(client->cap); x++) {
+		struct ast_format *format = ast_format_cap_get_format(client->cap, x);
+
+		codecs_num = add_codec_to_answer(p, format, dcodecs);
+		ao2_ref(format, -1);
+	}
 
 	if (codecs_num) {
 		/* only propose DTMF within an audio session */
@@ -575,7 +561,7 @@
 {
 	struct gtalk_pvt *p = ast_channel_tech_pvt(chan);
 	ast_mutex_lock(&p->lock);
-	ast_format_cap_copy(result, p->peercap);
+	ast_format_cap_append_by_type(result, p->peercap, AST_MEDIA_TYPE_UNKNOWN);
 	ast_mutex_unlock(&p->lock);
 }
 
@@ -691,8 +677,8 @@
 
 	/* at this point, we received an answer from the remote Gtalk client,
 	   which allows us to compare capabilities */
-	ast_format_cap_joint_copy(tmp->cap, tmp->peercap, tmp->jointcap);
-	if (ast_format_cap_is_empty(tmp->jointcap)) {
+	ast_format_cap_get_compatible(tmp->cap, tmp->peercap, tmp->jointcap);
+	if (!ast_format_cap_count(tmp->jointcap)) {
 		ast_log(LOG_WARNING, "Capabilities don't match : us - %s, peer - %s, combined - %s \n", ast_getformatname_multiple(s1, BUFSIZ, tmp->cap),
 			ast_getformatname_multiple(s2, BUFSIZ, tmp->peercap),
 			ast_getformatname_multiple(s3, BUFSIZ, tmp->jointcap));
@@ -1063,18 +1049,16 @@
 	if (!(tmp = ast_calloc(1, sizeof(*tmp)))) {
 		return NULL;
 	}
-	tmp->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
-	tmp->jointcap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
-	tmp->peercap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+	tmp->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	tmp->jointcap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	tmp->peercap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
 	if (!tmp->jointcap || !tmp->peercap || !tmp->cap) {
-		tmp->cap = ast_format_cap_destroy(tmp->cap);
-		tmp->jointcap = ast_format_cap_destroy(tmp->jointcap);
-		tmp->peercap = ast_format_cap_destroy(tmp->peercap);
+		ao2_cleanup(tmp->cap);
+		ao2_cleanup(tmp->jointcap);
+		ao2_cleanup(tmp->peercap);
 		ast_free(tmp);
 		return NULL;
 	}
-
-	memcpy(&tmp->prefs, &client->prefs, sizeof(struct ast_codec_pref));
 
 	if (sid) {
 		ast_copy_string(tmp->sid, sid, sizeof(tmp->sid));
@@ -1101,10 +1085,10 @@
 	ast_rtp_codecs_payloads_clear(ast_rtp_instance_get_codecs(tmp->rtp), tmp->rtp);
 
 	/* add user configured codec capabilites */
-	if (!(ast_format_cap_is_empty(client->cap))) {
-		ast_format_cap_copy(tmp->cap, client->cap);
-	} else if (!(ast_format_cap_is_empty(global_capability))) {
-		ast_format_cap_copy(tmp->cap, global_capability);
+	if (ast_format_cap_count(client->cap)) {
+		ast_format_cap_append_by_type(tmp->cap, client->cap, AST_MEDIA_TYPE_UNKNOWN);
+	} else if (ast_format_cap_count(global_capability)) {
+		ast_format_cap_append_by_type(tmp->cap, global_capability, AST_MEDIA_TYPE_UNKNOWN);
 	}
 
 	tmp->parent = client;
@@ -1135,10 +1119,17 @@
 /*! \brief Start new gtalk channel */
 static struct ast_channel *gtalk_new(struct gtalk *client, struct gtalk_pvt *i, int state, const char *title, const char *linkedid)
 {
+	struct ast_format_cap *caps;
 	struct ast_channel *tmp;
 	const char *n2;
 	struct ast_format_cap *what; /* used as SHALLOW COPY DO NOT DESTROY */
-	struct ast_format tmpfmt;
+	struct ast_format *tmpfmt;
+
+	caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	if (!caps) {
+		ast_log(LOG_WARNING, "Unable to allocate Gtalk capabilities structure!\n");
+		return NULL;
+	}
 
 	if (title)
 		n2 = title;
@@ -1147,6 +1138,7 @@
 	tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, linkedid, client->accountcode, i->exten, client->context, client->amaflags, "Gtalk/%s-%04lx", n2, ast_random() & 0xffff);
 	if (!tmp) {
 		ast_log(LOG_WARNING, "Unable to allocate Gtalk channel structure!\n");
+		ao2_ref(caps, -1);
 		return NULL;
 	}
 
@@ -1156,29 +1148,24 @@
 
 	/* Select our native format based on codec preference until we receive
 	   something from another device to the contrary. */
-	if (!(ast_format_cap_is_empty(i->jointcap))) {
+	if (ast_format_cap_count(i->jointcap)) {
 		what = i->jointcap;
-	} else if (i->cap) {
+	} else if (ast_format_cap_count(i->cap)) {
 		what = i->cap;
 	} else {
 		what = global_capability;
 	}
 
 	/* Set Frame packetization */
-	if (i->rtp) {
-		ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(i->rtp), i->rtp, &i->prefs);
-	}
-
-	ast_codec_choose(&i->prefs, what, 1, &tmpfmt);
-	ast_format_cap_add(ast_channel_nativeformats(tmp), &tmpfmt);
-
-	ast_format_cap_iter_start(i->jointcap);
-	while (!(ast_format_cap_iter_next(i->jointcap, &tmpfmt))) {
-		if (AST_FORMAT_GET_TYPE(tmpfmt.id) == AST_FORMAT_TYPE_VIDEO) {
-			ast_format_cap_add(ast_channel_nativeformats(tmp), &tmpfmt);
-		}
-	}
-	ast_format_cap_iter_end(i->jointcap);
+//	if (i->rtp) {
+//		ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(i->rtp), i->rtp, &i->prefs);
+//	}
+
+	ast_best_codec(what, &tmpfmt);
+	ast_format_cap_add(caps, tmpfmt, 0);
+	ast_format_cap_append_by_type(caps, i->jointcap, AST_MEDIA_TYPE_VIDEO);
+	ast_channel_nativeformats_set(tmp, caps);
+	ao2_ref(caps, -1);
 
 	if (i->rtp) {
 		ast_channel_set_fd(tmp, 0, ast_rtp_instance_fd(i->rtp, 0));
@@ -1192,12 +1179,11 @@
 		ast_channel_rings_set(tmp, 1);
 	ast_channel_adsicpe_set(tmp, AST_ADSI_UNAVAILABLE);
 
-	ast_best_codec(ast_channel_nativeformats(tmp), &tmpfmt);
-	ast_format_copy(ast_channel_writeformat(tmp), &tmpfmt);
-	ast_format_copy(ast_channel_rawwriteformat(tmp), &tmpfmt);
-	ast_format_copy(ast_channel_readformat(tmp), &tmpfmt);
-	ast_format_copy(ast_channel_rawreadformat(tmp), &tmpfmt);
-	ast_channel_tech_pvt_set(tmp, i);
+	ast_channel_set_writeformat(tmp, tmpfmt);
+	ast_channel_set_rawwriteformat(tmp, tmpfmt);
+	ast_channel_set_readformat(tmp, tmpfmt);
+	ast_channel_set_rawreadformat(tmp, tmpfmt);
+	ao2_ref(tmpfmt, -1);
 
 	ast_channel_callgroup_set(tmp, client->callgroup);
 	ast_channel_pickupgroup_set(tmp, client->pickupgroup);
@@ -1309,9 +1295,9 @@
 	if (p->vrtp)
 		ast_rtp_instance_destroy(p->vrtp);
 	gtalk_free_candidates(p->theircandidates);
-	p->cap = ast_format_cap_destroy(p->cap);
-	p->jointcap = ast_format_cap_destroy(p->jointcap);
-	p->peercap = ast_format_cap_destroy(p->peercap);
+	ao2_cleanup(p->cap);
+	ao2_cleanup(p->jointcap);
+	ao2_cleanup(p->peercap);
 	ast_free(p);
 }
 
@@ -1417,13 +1403,13 @@
 
 	/* Now gather all of the codecs that we are asked for */
 	ast_rtp_codecs_payload_formats(ast_rtp_instance_get_codecs(p->rtp), p->peercap, &peernoncodeccapability);
-	ast_format_cap_joint_copy(p->cap, p->peercap, p->jointcap);
+	ast_format_cap_get_compatible(p->cap, p->peercap, p->jointcap);
 	ast_mutex_unlock(&p->lock);
 
 	ast_channel_lock(chan);
 	ast_setstate(chan, AST_STATE_RING);
 	ast_channel_unlock(chan);
-	if (ast_format_cap_is_empty(p->jointcap)) {
+	if (!ast_format_cap_count(p->jointcap)) {
 		ast_log(LOG_WARNING, "Capabilities don't match : us - %s, peer - %s, combined - %s \n", ast_getformatname_multiple(s1, BUFSIZ, p->cap),
 			ast_getformatname_multiple(s2, BUFSIZ, p->peercap),
 			ast_getformatname_multiple(s3, BUFSIZ, p->jointcap));
@@ -1649,10 +1635,19 @@
 	if (p->owner) {
 		/* We already hold the channel lock */
 		if (f->frametype == AST_FRAME_VOICE) {
-			if (!ast_format_cap_iscompatible(ast_channel_nativeformats(p->owner), &f->subclass.format)) {
-				ast_debug(1, "Oooh, format changed to %s\n", ast_getformatname(&f->subclass.format));
-				ast_format_cap_remove_bytype(ast_channel_nativeformats(p->owner), AST_FORMAT_TYPE_AUDIO);
-				ast_format_cap_add(ast_channel_nativeformats(p->owner), &f->subclass.format);
+			if (!ast_format_cap_iscompatible_format(ast_channel_nativeformats(p->owner), f->subclass.format)) {
+				struct ast_format_cap *caps;
+
+				ast_debug(1, "Oooh, format changed to %s\n", f->subclass.format->codec->name);
+
+				caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+				if (caps) {
+					ast_format_cap_append_by_type(caps, ast_channel_nativeformats(p->owner), AST_MEDIA_TYPE_UNKNOWN);
+					ast_format_cap_remove_bytype(caps, AST_MEDIA_TYPE_AUDIO);
+					ast_format_cap_add(caps, f->subclass.format, 0);
+					ast_channel_nativeformats_set(p->owner, caps);
+					ao2_ref(caps, -1);
+				}
 				ast_set_read_format(p->owner, ast_channel_readformat(p->owner));
 				ast_set_write_format(p->owner, ast_channel_writeformat(p->owner));
 			}
@@ -1686,13 +1681,13 @@
 
 	switch (frame->frametype) {
 	case AST_FRAME_VOICE:
-		if (!(ast_format_cap_iscompatible(ast_channel_nativeformats(ast), &frame->subclass.format))) {
+		if (!(ast_format_cap_iscompatible_format(ast_channel_nativeformats(ast), frame->subclass.format))) {
 			ast_log(LOG_WARNING,
 					"Asked to transmit frame type %s, while native formats is %s (read/write = %s/%s)\n",
-					ast_getformatname(&frame->subclass.format),
+					frame->subclass.format->codec->name,
 					ast_getformatname_multiple(buf, sizeof(buf), ast_channel_nativeformats(ast)),
-					ast_getformatname(ast_channel_readformat(ast)),
-					ast_getformatname(ast_channel_writeformat(ast)));
+					ast_channel_readformat(ast)->codec->name,
+					ast_channel_writeformat(ast)->codec->name);
 			return 0;
 		}
 		if (p) {
@@ -2022,8 +2017,8 @@
 					ast_channel_name(chan),
 					jid,
 					resource,
-					ast_getformatname(ast_channel_readformat(chan)),
-					ast_getformatname(ast_channel_writeformat(chan))
+					ast_channel_readformat(chan)->codec->name,
+					ast_channel_writeformat(chan)->codec->name
 					);
 			else
 				ast_log(LOG_WARNING, "No available channel\n");
@@ -2141,7 +2136,7 @@
 }
 
 static int gtalk_create_member(char *label, struct ast_variable *var, int allowguest,
-								struct ast_codec_pref prefs, char *context,
+								char *context,
 								struct gtalk *member)
 {
 	struct aji_client *client;
@@ -2153,14 +2148,13 @@
 	ast_copy_string(member->user, label, sizeof(member->user));
 	ast_copy_string(member->context, context, sizeof(member->context));
 	member->allowguest = allowguest;
-	member->prefs = prefs;
 	while (var) {
 		if (!strcasecmp(var->name, "username"))
 			ast_copy_string(member->user, var->value, sizeof(member->user));
 		else if (!strcasecmp(var->name, "disallow"))
-			ast_parse_allow_disallow(&member->prefs, member->cap, var->value, 0);
+			ast_parse_allow_disallow(member->cap, var->value, 0);
 		else if (!strcasecmp(var->name, "allow"))
-			ast_parse_allow_disallow(&member->prefs, member->cap, var->value, 1);
+			ast_parse_allow_disallow(member->cap, var->value, 1);
 		else if (!strcasecmp(var->name, "context"))
 			ast_copy_string(member->context, var->value, sizeof(member->context));
 		else if (!strcasecmp(var->name, "parkinglot"))
@@ -2194,7 +2188,6 @@
 	struct ast_config *cfg = NULL;
 	struct ast_variable *var;
 	struct gtalk *member;
-	struct ast_codec_pref prefs;
 	struct aji_client_container *clients;
 	struct gtalk_candidate *global_candidates = NULL;
 	struct hostent *hp;
@@ -2213,7 +2206,6 @@
 	memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
 
 	/* set defaults */
-	memset(&prefs, 0, sizeof(prefs));
 	memset(&stunaddr, 0, sizeof(stunaddr));
 	global_stunaddr = 0;
 	global_allowguest = DEFAULT_ALLOWGUEST;
@@ -2230,9 +2222,9 @@
 		if (!strcasecmp(var->name, "allowguest")) {
 			global_allowguest = (ast_true(ast_variable_retrieve(cfg, "general", "allowguest"))) ? 1 : 0;
 		} else if (!strcasecmp(var->name, "disallow")) {
-			ast_parse_allow_disallow(&prefs, global_capability, var->value, 0);
+			ast_parse_allow_disallow(global_capability, var->value, 0);
 		} else if (!strcasecmp(var->name, "allow")) {
-			ast_parse_allow_disallow(&prefs, global_capability, var->value, 1);
+			ast_parse_allow_disallow(global_capability, var->value, 1);
 		} else if (!strcasecmp(var->name, "context")) {
 			ast_copy_string(global_context, var->value, sizeof(global_context));
 		} else if (!strcasecmp(var->name, "externip")) {
@@ -2259,20 +2251,19 @@
 			member = ast_calloc(1, sizeof(*member));
 			ASTOBJ_INIT(member);
 			ASTOBJ_WRLOCK(member);
-			member->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+			member->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
 			if (!strcasecmp(cat, "guest")) {
 				ast_copy_string(member->name, "guest", sizeof(member->name));
 				ast_copy_string(member->user, "guest", sizeof(member->user));
 				ast_copy_string(member->context, global_context, sizeof(member->context));
 				ast_copy_string(member->parkinglot, global_parkinglot, sizeof(member->parkinglot));
 				member->allowguest = global_allowguest;
-				member->prefs = prefs;
 				while (var) {
 					if (!strcasecmp(var->name, "disallow")) {
-						ast_parse_allow_disallow(&member->prefs, member->cap,
+						ast_parse_allow_disallow(member->cap,
 												 var->value, 0);
 					} else if (!strcasecmp(var->name, "allow")) {
-						ast_parse_allow_disallow(&member->prefs, member->cap,
+						ast_parse_allow_disallow(member->cap,
 												 var->value, 1);
 					} else if (!strcasecmp(var->name, "context")) {
 						ast_copy_string(member->context, var->value,
@@ -2307,7 +2298,7 @@
 				}
 			} else {
 				ASTOBJ_UNLOCK(member);
-				if (gtalk_create_member(cat, var, global_allowguest, prefs, global_context, member)) {
+				if (gtalk_create_member(cat, var, global_allowguest, global_context, member)) {
 					ASTOBJ_CONTAINER_LINK(&gtalk_list, member);
 				}
 				ASTOBJ_UNREF(member, gtalk_member_destroy);
@@ -2337,20 +2328,19 @@
 	struct ast_sockaddr bindaddr_tmp;
 	struct ast_sockaddr ourip_tmp;
 	char *jabber_loaded = ast_module_helper("", "res_jabber.so", 0, 0, 0, 0);
-	struct ast_format tmpfmt;
-
-	if (!(gtalk_tech.capabilities = ast_format_cap_alloc(0))) {
+
+	if (!(gtalk_tech.capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
 		return AST_MODULE_LOAD_DECLINE;
 	}
-	if (!(global_capability = ast_format_cap_alloc(0))) {
+	if (!(global_capability = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
-	ast_format_cap_add_all_by_type(gtalk_tech.capabilities, AST_FORMAT_TYPE_AUDIO);
-	ast_format_cap_add(global_capability, ast_format_set(&tmpfmt, AST_FORMAT_ULAW, 0));
-	ast_format_cap_add(global_capability, ast_format_set(&tmpfmt, AST_FORMAT_GSM, 0));
-	ast_format_cap_add(global_capability, ast_format_set(&tmpfmt, AST_FORMAT_ALAW, 0));
-	ast_format_cap_add(global_capability, ast_format_set(&tmpfmt, AST_FORMAT_H263, 0));
+	ast_format_cap_add_all_by_type(gtalk_tech.capabilities, AST_MEDIA_TYPE_AUDIO);
+	ast_format_cap_add(global_capability, ast_format_ulaw, 0);
+	ast_format_cap_add(global_capability, ast_format_gsm, 0);
+	ast_format_cap_add(global_capability, ast_format_alaw, 0);
+	ast_format_cap_add(global_capability, ast_format_h263, 0);
 
 	free(jabber_loaded);
 	if (!jabber_loaded) {
@@ -2434,8 +2424,10 @@
 	}
 	ASTOBJ_CONTAINER_DESTROYALL(&gtalk_list, gtalk_member_destroy);
 	ASTOBJ_CONTAINER_DESTROY(&gtalk_list);
-	global_capability = ast_format_cap_destroy(global_capability);
-	gtalk_tech.capabilities = ast_format_cap_destroy(gtalk_tech.capabilities);
+	ao2_ref(global_capability, -1);
+	global_capability = NULL;
+	ao2_ref(gtalk_tech.capabilities, -1);
+	gtalk_tech.capabilities = NULL;
 	return 0;
 }
 




More information about the svn-commits mailing list