[svn-commits] file: branch group/media_formats-reviewed r411574 - /team/group/media_formats...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sun Mar 30 07:13:23 CDT 2014


Author: file
Date: Sun Mar 30 07:13:17 2014
New Revision: 411574

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=411574
Log:
Move chan_motif, chan_jingle, and chan_gtalk over.

Review: https://reviewboard.asterisk.org/r/3390/

Modified:
    team/group/media_formats-reviewed/channels/chan_gtalk.c
    team/group/media_formats-reviewed/channels/chan_jingle.c
    team/group/media_formats-reviewed/channels/chan_motif.c

Modified: team/group/media_formats-reviewed/channels/chan_gtalk.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/channels/chan_gtalk.c?view=diff&rev=411574&r1=411573&r2=411574
==============================================================================
--- team/group/media_formats-reviewed/channels/chan_gtalk.c (original)
+++ team/group/media_formats-reviewed/channels/chan_gtalk.c Sun Mar 30 07:13: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 = ast_format_get_name(codec);
 
 	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", ast_format_get_name(f->subclass.format));
+
+				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),
+					ast_format_get_name(frame->subclass.format),
 					ast_getformatname_multiple(buf, sizeof(buf), ast_channel_nativeformats(ast)),
-					ast_getformatname(ast_channel_readformat(ast)),
-					ast_getformatname(ast_channel_writeformat(ast)));
+					ast_format_get_name(ast_channel_readformat(ast)),
+					ast_format_get_name(ast_channel_writeformat(ast)));
 			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_format_get_name(ast_channel_readformat(chan)),
+					ast_format_get_name(ast_channel_writeformat(chan))
 					);
 			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;
 }
 

Modified: team/group/media_formats-reviewed/channels/chan_jingle.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/channels/chan_jingle.c?view=diff&rev=411574&r1=411573&r2=411574
==============================================================================
--- team/group/media_formats-reviewed/channels/chan_jingle.c (original)
+++ team/group/media_formats-reviewed/channels/chan_jingle.c Sun Mar 30 07:13:17 2014
@@ -80,6 +80,7 @@
 #include "asterisk/jabber.h"
 #include "asterisk/jingle.h"
 #include "asterisk/stasis_channels.h"
+#include "asterisk/format_cache.h"
 
 #define JINGLE_CONFIG "jingle.conf"
 
@@ -116,7 +117,6 @@
 	iksrule *ringrule;               /*!< Rule for matching RING request */
 	int initiator;                   /*!< If we're the initiator */
 	int alreadygone;
-	struct ast_codec_pref prefs;
 	struct jingle_candidate *theircandidates;
 	struct jingle_candidate *ourcandidates;
 	char cid_num[80];                /*!< Caller ID num */
@@ -154,7 +154,6 @@
 	struct aji_client *connection;
 	struct aji_buddy *buddy;
 	struct jingle_pvt *p;
-	struct ast_codec_pref prefs;
 	int amaflags;			/*!< AMA Flags */
 	char user[100];
 	char context[100];
@@ -237,7 +236,7 @@
 
 static void jingle_member_destroy(struct jingle *obj)
 {
-	obj->cap = ast_format_cap_destroy(obj->cap);
+	ao2_cleanup(obj->cap);
 	if (obj->connection) {
 		ASTOBJ_UNREF(obj->connection, ast_aji_client_destroy);
 	}
@@ -277,7 +276,7 @@
 
 static void add_codec_to_answer(const struct jingle_pvt *p, struct ast_format *codec, iks *dcodecs)
 {
-	const char *format = ast_getformatname(codec);
+	const char *format = ast_format_get_name(codec);
 
 	if (!strcasecmp("ulaw", format)) {
 		iks *payload_eg711u, *payload_pcmu;
@@ -321,10 +320,8 @@
 	struct aji_client *c = client->connection;
 	iks *iq, *jingle, *dcodecs, *payload_red, *payload_audio, *payload_cn;
 	int x;
-	struct ast_format pref_codec;
-	struct ast_format_cap *alreadysent = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
-
-	if (p->initiator || !alreadysent)
+
+	if (p->initiator)
 		return 1;
 
 	iq = iks_new("iq");
@@ -333,15 +330,11 @@
 	if (iq && jingle && dcodecs) {
 		iks_insert_attrib(dcodecs, "xmlns", JINGLE_AUDIO_RTP_NS);
 
-		for (x = 0; x < AST_CODEC_PREF_SIZE; x++) {
-			if (!(ast_codec_pref_index(&client->prefs, x, &pref_codec)))
-				break;
-			if (!(ast_format_cap_iscompatible(client->cap, &pref_codec)))
-				continue;
-			if ((ast_format_cap_iscompatible(alreadysent, &pref_codec)))
-				continue;
-			add_codec_to_answer(p, &pref_codec, dcodecs);
-			ast_format_cap_add(alreadysent, &pref_codec);
+		for (x = 0; x < ast_format_cap_count(client->cap); x++) {
+			struct ast_format *format = ast_format_cap_get_format(client->cap, x);
+
+			add_codec_to_answer(p, format, dcodecs);
+			ao2_ref(format, -1);
 		}
 		payload_red = iks_new("payload-type");
 		iks_insert_attrib(payload_red, "id", "117");
@@ -378,7 +371,6 @@
 		iks_delete(jingle);
 		iks_delete(iq);
 	}
-	alreadysent = ast_format_cap_destroy(alreadysent);
 	return 1;
 }
 
@@ -430,7 +422,7 @@
 {
 	struct jingle_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);
 }
 
@@ -798,17 +790,16 @@
 		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->cap || !tmp->jointcap || !tmp->peercap) {
-		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(tmp->prefs));
 
 	if (sid) {
 		ast_copy_string(tmp->sid, sid, sizeof(tmp->sid));
@@ -849,10 +840,17 @@
 /*! \brief Start new jingle channel */
 static struct ast_channel *jingle_new(struct jingle *client, struct jingle_pvt *i, int state, const char *title, const char *linkedid)
 {
+	struct ast_format_cap *caps;
 	struct ast_channel *tmp;
 	struct ast_format_cap *what;  /* SHALLOW COPY DO NOT DESTROY */
-	struct ast_format tmpfmt;
+	struct ast_format *tmpfmt;
 	const char *str;
+
+	caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	if (!caps) {
+		ast_log(LOG_WARNING, "Unable to allocate Jingle capabilities structure!\n");
+		return NULL;
+	}
 
 	if (title)
 		str = title;
@@ -861,6 +859,7 @@
 	tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, "", "", "", linkedid, 0, "Jingle/%s-%04lx", str, ast_random() & 0xffff);
 	if (!tmp) {
 		ast_log(LOG_WARNING, "Unable to allocate Jingle channel structure!\n");
+		ao2_ref(caps, -1);
 		return NULL;
 	}
 
@@ -870,27 +869,22 @@
 
 	/* 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 (!(ast_format_cap_is_empty(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));
@@ -904,12 +898,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_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_tech_pvt_set(tmp, i);
 
 	ast_channel_callgroup_set(tmp, client->callgroup);
@@ -1020,9 +1013,9 @@
 	if (p->vrtp)
 		ast_rtp_instance_destroy(p->vrtp);
 	jingle_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);
 }
@@ -1259,10 +1252,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", ast_format_get_name(f->subclass.format));
+
+				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));
 			}
@@ -1296,13 +1298,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),
+					ast_format_get_name(frame->subclass.format),
 					ast_getformatname_multiple(buf, sizeof(buf), ast_channel_nativeformats(ast)),
-					ast_getformatname(ast_channel_readformat(ast)),
-					ast_getformatname(ast_channel_writeformat(ast)));
+					ast_format_get_name(ast_channel_readformat(ast)),
+					ast_format_get_name(ast_channel_writeformat(ast)));
 			return 0;
 		}
 		if (p) {
@@ -1541,7 +1543,7 @@
 	}
 
 	ast_setstate(ast, AST_STATE_RING);
-	ast_format_cap_copy(p->jointcap, p->cap);
+	ast_format_cap_append_by_type(p->jointcap, p->cap, AST_MEDIA_TYPE_UNKNOWN);
 	if (!p->ringrule) {
 		ast_copy_string(p->ring, p->parent->connection->mid, sizeof(p->ring));
 		p->ringrule = iks_filter_add_rule(p->parent->connection->f, jingle_ringing_ack, p,
@@ -1670,8 +1672,8 @@
 					ast_channel_name(chan),
 					jid,
 					resource,
-					ast_getformatname(ast_channel_readformat(chan)),
-					ast_getformatname(ast_channel_writeformat(chan))
+					ast_format_get_name(ast_channel_readformat(chan)),
+					ast_format_get_name(ast_channel_writeformat(chan))
 					);
 			else 
 				ast_log(LOG_WARNING, "No available channel\n");
@@ -1779,7 +1781,7 @@
 */
 
 static int jingle_create_member(char *label, struct ast_variable *var, int allowguest,
-								struct ast_codec_pref prefs, char *context,
+								char *context,
 								struct jingle *member)
 {
 	struct aji_client *client;
@@ -1791,7 +1793,6 @@
 	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 0
 		struct jingle_candidate *candidate = NULL;
@@ -1799,9 +1800,9 @@
 		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));
 #if 0
@@ -1846,7 +1847,6 @@
 	struct jingle *member;
 	struct hostent *hp;
 	struct ast_hostent ahp;
-	struct ast_codec_pref prefs;
 	struct aji_client_container *clients;
 	struct jingle_candidate *global_candidates = NULL;
 	struct ast_flags config_flags = { 0 };
@@ -1869,9 +1869,9 @@
 			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(context, var->value, sizeof(context));
 		else if (!strcasecmp(var->name, "externip"))
@@ -1900,19 +1900,18 @@
 			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, context, sizeof(member->context));
 				member->allowguest = 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,
@@ -1954,7 +1953,7 @@
 				}
 			} else {
 				ASTOBJ_UNLOCK(member);
-				if (jingle_create_member(cat, var, allowguest, prefs, context, member))
+				if (jingle_create_member(cat, var, allowguest, context, member))
 					ASTOBJ_CONTAINER_LINK(&jingle_list, member);
 				ASTOBJ_UNREF(member, jingle_member_destroy);
 			}
@@ -1980,22 +1979,21 @@
 {
 	struct ast_sockaddr ourip_tmp;
 	struct ast_sockaddr bindaddr_tmp;
-	struct ast_format tmpfmt;
 
 	char *jabber_loaded = ast_module_helper("", "res_jabber.so", 0, 0, 0, 0);
 
-	if (!(jingle_tech.capabilities = ast_format_cap_alloc(0))) {
+	if (!(jingle_tech.capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
-	ast_format_cap_add_all_by_type(jingle_tech.capabilities, AST_FORMAT_TYPE_AUDIO);
-	if (!(global_capability = ast_format_cap_alloc(0))) {
+	ast_format_cap_add_all_by_type(jingle_tech.capabilities, AST_MEDIA_TYPE_AUDIO);
+	if (!(global_capability = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
 		return AST_MODULE_LOAD_DECLINE;
 	}
-	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(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) {
@@ -2078,7 +2076,8 @@
 	ASTOBJ_CONTAINER_DESTROYALL(&jingle_list, jingle_member_destroy);
 	ASTOBJ_CONTAINER_DESTROY(&jingle_list);
 
-	global_capability = ast_format_cap_destroy(global_capability);
+	ao2_ref(global_capability, -1);
+	global_capability = NULL;
 	return 0;
 }
 

Modified: team/group/media_formats-reviewed/channels/chan_motif.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/channels/chan_motif.c?view=diff&rev=411574&r1=411573&r2=411574
==============================================================================
--- team/group/media_formats-reviewed/channels/chan_motif.c (original)
+++ team/group/media_formats-reviewed/channels/chan_motif.c Sun Mar 30 07:13:17 2014
@@ -77,6 +77,7 @@
 #include "asterisk/abstract_jb.h"
 #include "asterisk/xmpp.h"
 #include "asterisk/stasis_channels.h"
+#include "asterisk/format_cache.h"
 
 /*** DOCUMENTATION
 	<configInfo name="chan_motif" language="en_US">
@@ -286,7 +287,6 @@
 	iksrule *rule;                          /*!< Active matching rule */
 	unsigned int maxicecandidates;          /*!< Maximum number of ICE candidates we will offer */
 	unsigned int maxpayloads;               /*!< Maximum number of payloads we will offer */
-	struct ast_codec_pref prefs;            /*!< Codec preferences */
 	struct ast_format_cap *cap;             /*!< Formats to use */
 	ast_group_t callgroup;                  /*!< Call group */
 	ast_group_t pickupgroup;                /*!< Pickup group */
@@ -309,7 +309,6 @@
 	char remote_original[XMPP_MAX_JIDLEN];/*!< Identifier of the original remote party (remote may have changed due to redirect) */
 	char remote[XMPP_MAX_JIDLEN];         /*!< Identifier of the remote party */
 	iksrule *rule;                        /*!< Session matching rule */
-	struct ast_codec_pref prefs;          /*!< Codec preferences */
 	struct ast_channel *owner;            /*!< Master Channel */
 	struct ast_rtp_instance *rtp;         /*!< RTP audio session */
 	struct ast_rtp_instance *vrtp;        /*!< RTP video session */
@@ -454,8 +453,7 @@
 		ast_xmpp_client_unref(endpoint->connection);
 	}
 
-	ast_format_cap_destroy(endpoint->cap);
-
+	ao2_cleanup(endpoint->cap);
 	ao2_ref(endpoint->state, -1);
 
 	ast_string_field_free_memory(endpoint);
@@ -519,7 +517,7 @@
 
 	ast_string_field_set(endpoint, name, cat);
 
-	endpoint->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+	endpoint->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
 	endpoint->transport = JINGLE_TRANSPORT_ICE_UDP;
 
 	return endpoint;
@@ -583,9 +581,9 @@
 		ast_rtp_instance_destroy(session->vrtp);
 	}
 
-	ast_format_cap_destroy(session->cap);
-	ast_format_cap_destroy(session->jointcap);
-	ast_format_cap_destroy(session->peercap);
+	ao2_cleanup(session->cap);
+	ao2_cleanup(session->jointcap);
+	ao2_cleanup(session->peercap);
 
 	if (session->callid) {
 		ast_callid_unref(session->callid);
@@ -681,7 +679,7 @@
 	}
 
 	/* If there are no configured video codecs do not turn video support on, it just won't work */
-	if (!ast_format_cap_has_type(session->cap, AST_FORMAT_TYPE_VIDEO)) {
+	if (!ast_format_cap_has_type(session->cap, AST_MEDIA_TYPE_VIDEO)) {
 		return;
 	}
 
@@ -695,7 +693,7 @@
 	ast_rtp_instance_set_channel_id(session->vrtp, ast_channel_uniqueid(session->owner));
 	ast_channel_set_fd(session->owner, 2, ast_rtp_instance_fd(session->vrtp, 0));
 	ast_channel_set_fd(session->owner, 3, ast_rtp_instance_fd(session->vrtp, 1));
-	ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(session->vrtp), session->vrtp, &session->prefs);
+//	ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(session->vrtp), session->vrtp, &session->prefs);
 
 	if (session->transport == JINGLE_TRANSPORT_GOOGLE_V2 && (ice = ast_rtp_instance_get_ice(session->vrtp))) {
 		ice->stop(session->vrtp);
@@ -741,15 +739,15 @@
 	session->connection = endpoint->connection;
 	session->transport = endpoint->transport;
 
-	if (!(session->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK)) ||
-	    !(session->jointcap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK)) ||
-	    !(session->peercap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK)) ||
+	if (!(session->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT)) ||
+	    !(session->jointcap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT)) ||
+	    !(session->peercap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT)) ||
 	    !session->callid) {
 		ao2_ref(session, -1);
 		return NULL;
 	}
 
-	ast_format_cap_copy(session->cap, endpoint->cap);
+	ast_format_cap_append_by_type(session->cap, endpoint->cap, AST_MEDIA_TYPE_UNKNOWN);
 
 	/* While we rely on res_xmpp for communication we still need a temporary ast_sockaddr to tell the RTP engine
 	 * that we want IPv4 */
@@ -763,8 +761,6 @@
 	ast_rtp_instance_set_prop(session->rtp, AST_RTP_PROPERTY_RTCP, 1);
 	ast_rtp_instance_set_prop(session->rtp, AST_RTP_PROPERTY_DTMF, 1);
 
-	memcpy(&session->prefs, &endpoint->prefs, sizeof(session->prefs));
-
 	session->maxicecandidates = endpoint->maxicecandidates;
 	session->maxpayloads = endpoint->maxpayloads;
 
@@ -776,13 +772,20 @@
 {
 	struct ast_channel *chan;
 	const char *str = S_OR(title, session->remote);
-	struct ast_format tmpfmt;
-
-	if (ast_format_cap_is_empty(session->cap)) {
+	struct ast_format_cap *caps;
+	struct ast_format *tmpfmt;
+
+	if (!ast_format_cap_count(session->cap)) {
 		return NULL;
 	}
 
+	caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	if (!caps) {
+		return NULL;
+	}
+
 	if (!(chan = ast_channel_alloc(1, state, S_OR(title, ""), S_OR(cid_name, ""), "", "", "", linkedid, 0, "Motif/%s-%04lx", str, ast_random() & 0xffff))) {
+		ao2_ref(caps, -1);
 		return NULL;
 	}
 
@@ -794,15 +797,18 @@
 
 	ast_channel_callid_set(chan, session->callid);
 
-	ast_format_cap_copy(ast_channel_nativeformats(chan), session->cap);
-	ast_codec_choose(&session->prefs, session->cap, 1, &tmpfmt);
+	ast_format_cap_append_by_type(caps, session->cap, AST_MEDIA_TYPE_UNKNOWN);
+	ast_channel_nativeformats_set(chan, caps);
+	ao2_ref(caps, -1);
+
+	tmpfmt = ast_format_cap_get_format(session->cap, 0);
 
 	if (session->rtp) {
 		struct ast_rtp_engine_ice *ice;
 
 		ast_channel_set_fd(chan, 0, ast_rtp_instance_fd(session->rtp, 0));
 		ast_channel_set_fd(chan, 1, ast_rtp_instance_fd(session->rtp, 1));
-		ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(session->rtp), session->rtp, &session->prefs);

[... 313 lines stripped ...]



More information about the svn-commits mailing list