[svn-commits] file: branch group/media_formats-reviewed r414047 - in /team/group/media_form...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri May 16 07:24:55 CDT 2014


Author: file
Date: Fri May 16 07:24:43 2014
New Revision: 414047

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=414047
Log:
Move chan_unistim, chan_mgcp, and chan_skinny to media formats.

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

Modified:
    team/group/media_formats-reviewed/channels/chan_mgcp.c
    team/group/media_formats-reviewed/channels/chan_skinny.c
    team/group/media_formats-reviewed/channels/chan_unistim.c
    team/group/media_formats-reviewed/include/asterisk/format_cache.h

Modified: team/group/media_formats-reviewed/channels/chan_mgcp.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/channels/chan_mgcp.c?view=diff&rev=414047&r1=414046&r2=414047
==============================================================================
--- team/group/media_formats-reviewed/channels/chan_mgcp.c (original)
+++ team/group/media_formats-reviewed/channels/chan_mgcp.c Fri May 16 07:24:43 2014
@@ -86,6 +86,7 @@
 #include "asterisk/features_config.h"
 #include "asterisk/parking.h"
 #include "asterisk/stasis_channels.h"
+#include "asterisk/format_cache.h"
 
 /*
  * Define to work around buggy dlink MGCP phone firmware which
@@ -1199,9 +1200,20 @@
 	if (sub->owner) {
 		/* We already hold the channel lock */
 		if (f->frametype == AST_FRAME_VOICE) {
-			if (!ast_format_cap_iscompatible(ast_channel_nativeformats(sub->owner), &f->subclass.format)) {
-				ast_debug(1, "Oooh, format changed to %s\n", ast_getformatname(&f->subclass.format));
-				ast_format_cap_set(ast_channel_nativeformats(sub->owner), &f->subclass.format);
+			if (!ast_format_cap_iscompatible_format(ast_channel_nativeformats(sub->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_add(caps, f->subclass.format, 0);
+					ast_channel_nativeformats_set(sub->owner, caps);
+					ao2_ref(caps, -1);
+				} else {
+					return &ast_null_frame;
+				}
+
 				ast_set_read_format(sub->owner, ast_channel_readformat(sub->owner));
 				ast_set_write_format(sub->owner, ast_channel_writeformat(sub->owner));
 			}
@@ -1249,12 +1261,12 @@
 			return 0;
 		}
 	} else {
-		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 -1; */
 		}
 	}
@@ -1490,90 +1502,101 @@
 
 static struct ast_channel *mgcp_new(struct mgcp_subchannel *sub, int state, const char *linkedid)
 {
+	struct ast_format_cap *caps = NULL;
 	struct ast_channel *tmp;
 	struct ast_variable *v = NULL;
 	struct mgcp_endpoint *i = sub->parent;
-	struct ast_format tmpfmt;
-
+	struct ast_format *tmpfmt;
+
+	caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	if (!caps) {
+		ast_log(LOG_ERROR, "Format capabilities could not be created\n");
+		return NULL;
+	}
 	tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, linkedid, i->accountcode, i->exten, i->context, i->amaflags, "MGCP/%s@%s-%d", i->name, i->parent->name, sub->id);
-	if (tmp) {
-		ast_channel_stage_snapshot(tmp);
-		ast_channel_tech_set(tmp, &mgcp_tech);
-		ast_format_cap_copy(ast_channel_nativeformats(tmp), i->cap);
-		if (ast_format_cap_is_empty(ast_channel_nativeformats(tmp))) {
-			ast_format_cap_copy(ast_channel_nativeformats(tmp), global_capability);
-		}
-		if (sub->rtp) {
-			ast_channel_set_fd(tmp, 0, ast_rtp_instance_fd(sub->rtp, 0));
-		}
-		if (i->dtmfmode & (MGCP_DTMF_INBAND | MGCP_DTMF_HYBRID)) {
-			i->dsp = ast_dsp_new();
-			ast_dsp_set_features(i->dsp, DSP_FEATURE_DIGIT_DETECT);
-			/* this is to prevent clipping of dtmf tones during dsp processing */
-			ast_dsp_set_digitmode(i->dsp, DSP_DIGITMODE_NOQUELCH);
-		} else {
-			i->dsp = NULL;
-		}
-		if (state == AST_STATE_RING)
-			ast_channel_rings_set(tmp, 1);
-
+	if (!tmp) {
+		ast_log(LOG_WARNING, "Channel could not be created\n");
+		ao2_ref(caps, -1);
+		return NULL;
+	}
+
+	ast_channel_stage_snapshot(tmp);
+	ast_channel_tech_set(tmp, &mgcp_tech);
+	if (ast_format_cap_count(i->cap)) {
+		ast_format_cap_append_by_type(caps, i->cap, AST_MEDIA_TYPE_UNKNOWN);
+	} else {
+		ast_format_cap_append_by_type(caps, global_capability, AST_MEDIA_TYPE_UNKNOWN);
+	}
+	ast_channel_nativeformats_set(tmp, caps);
+	ao2_ref(caps, -1);
+	if (sub->rtp) {
+		ast_channel_set_fd(tmp, 0, ast_rtp_instance_fd(sub->rtp, 0));
+	}
+	if (i->dtmfmode & (MGCP_DTMF_INBAND | MGCP_DTMF_HYBRID)) {
+		i->dsp = ast_dsp_new();
+		ast_dsp_set_features(i->dsp, DSP_FEATURE_DIGIT_DETECT);
+		/* this is to prevent clipping of dtmf tones during dsp processing */
+		ast_dsp_set_digitmode(i->dsp, DSP_DIGITMODE_NOQUELCH);
+	} else {
+		i->dsp = NULL;
+	}
+	if (state == AST_STATE_RING)
+		ast_channel_rings_set(tmp, 1);
 		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, sub);
-		if (!ast_strlen_zero(i->language))
-			ast_channel_language_set(tmp, i->language);
-		if (!ast_strlen_zero(i->accountcode))
-			ast_channel_accountcode_set(tmp, i->accountcode);
-		if (i->amaflags)
-			ast_channel_amaflags_set(tmp, i->amaflags);
-		mgcp_set_owner(sub, tmp);
-		ast_module_ref(ast_module_info->self);
-		ast_channel_callgroup_set(tmp, i->callgroup);
-		ast_channel_pickupgroup_set(tmp, i->pickupgroup);
-		ast_channel_call_forward_set(tmp, i->call_forward);
-		ast_channel_context_set(tmp, i->context);
-		ast_channel_exten_set(tmp, i->exten);
-
-		/* Don't use ast_set_callerid() here because it will
-		 * generate a needless NewCallerID event */
-		if (!ast_strlen_zero(i->cid_num)) {
-			ast_channel_caller(tmp)->ani.number.valid = 1;
-			ast_channel_caller(tmp)->ani.number.str = ast_strdup(i->cid_num);
-		}
-
-		if (!i->adsi) {
-			ast_channel_adsicpe_set(tmp, AST_ADSI_UNAVAILABLE);
-		}
-		ast_channel_priority_set(tmp, 1);
-
-		/* Set channel variables for this call from configuration */
-		for (v = i->chanvars ; v ; v = v->next) {
-			char valuebuf[1024];
-			pbx_builtin_setvar_helper(tmp, v->name, ast_get_encoded_str(v->value, valuebuf, sizeof(valuebuf)));
-		}
-
-		if (sub->rtp) {
-			ast_jb_configure(tmp, &global_jbconf);
-		}
-
-		ast_channel_stage_snapshot_done(tmp);
-		ast_channel_unlock(tmp);
-
-		if (state != AST_STATE_DOWN) {
-			if (ast_pbx_start(tmp)) {
-				ast_log(LOG_WARNING, "Unable to start PBX on %s\n", ast_channel_name(tmp));
-				ast_hangup(tmp);
-				tmp = NULL;
-			}
-		}
-		ast_verb(3, "MGCP mgcp_new(%s) created in state: %s\n",
-				ast_channel_name(tmp), ast_state2str(state));
-	} else {
-		ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
-	}
+	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, sub);
+	if (!ast_strlen_zero(i->language))
+		ast_channel_language_set(tmp, i->language);
+	if (!ast_strlen_zero(i->accountcode))
+		ast_channel_accountcode_set(tmp, i->accountcode);
+	if (i->amaflags)
+		ast_channel_amaflags_set(tmp, i->amaflags);
+	mgcp_set_owner(sub, tmp);
+	ast_module_ref(ast_module_info->self);
+	ast_channel_callgroup_set(tmp, i->callgroup);
+	ast_channel_pickupgroup_set(tmp, i->pickupgroup);
+	ast_channel_call_forward_set(tmp, i->call_forward);
+	ast_channel_context_set(tmp, i->context);
+	ast_channel_exten_set(tmp, i->exten);
+	/* Don't use ast_set_callerid() here because it will
+	 * generate a needless NewCallerID event */
+	if (!ast_strlen_zero(i->cid_num)) {
+		ast_channel_caller(tmp)->ani.number.valid = 1;
+		ast_channel_caller(tmp)->ani.number.str = ast_strdup(i->cid_num);
+	}
+
+	if (!i->adsi) {
+		ast_channel_adsicpe_set(tmp, AST_ADSI_UNAVAILABLE);
+	}
+	ast_channel_priority_set(tmp, 1);
+
+	/* Set channel variables for this call from configuration */
+	for (v = i->chanvars ; v ; v = v->next) {
+		char valuebuf[1024];
+		pbx_builtin_setvar_helper(tmp, v->name, ast_get_encoded_str(v->value, valuebuf, sizeof(valuebuf)));
+	}
+
+	if (sub->rtp) {
+		ast_jb_configure(tmp, &global_jbconf);
+	}
+
+	ast_channel_stage_snapshot_done(tmp);
+	ast_channel_unlock(tmp);
+
+	if (state != AST_STATE_DOWN) {
+		if (ast_pbx_start(tmp)) {
+			ast_log(LOG_WARNING, "Unable to start PBX on %s\n", ast_channel_name(tmp));
+			ast_hangup(tmp);
+			tmp = NULL;
+		}
+	}
+	ast_verb(3, "MGCP mgcp_new(%s) created in state: %s\n",
+			ast_channel_name(tmp), ast_state2str(state));
+
 	return tmp;
 }
 
@@ -2030,20 +2053,20 @@
 	}
 
 	/* Now gather all of the codecs that were asked for: */
-	if (!(peercap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK))) {
+	if (!(peercap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
 		return -1;
 	}
 	ast_rtp_codecs_payload_formats(ast_rtp_instance_get_codecs(sub->rtp), peercap, &peerNonCodecCapability);
-	ast_format_cap_joint_copy(global_capability, peercap, p->cap);
+	ast_format_cap_get_compatible(global_capability, peercap, p->cap);
 	ast_debug(1, "Capabilities: us - %s, them - %s, combined - %s\n",
 		ast_getformatname_multiple(tmp1, sizeof(tmp1), global_capability),
 		ast_getformatname_multiple(tmp2, sizeof(tmp2), peercap),
 		ast_getformatname_multiple(tmp3, sizeof(tmp3), p->cap));
-	peercap = ast_format_cap_destroy(peercap);
+	ao2_ref(peercap, -1);
 
 	ast_debug(1, "Non-codec capabilities: us - %d, them - %d, combined - %d\n",
 		nonCodecCapability, peerNonCodecCapability, p->nonCodecCapability);
-	if (ast_format_cap_is_empty(p->cap)) {
+	if (!ast_format_cap_count(p->cap)) {
 		ast_log(LOG_WARNING, "No compatible codecs!\n");
 		return -1;
 	}
@@ -2201,7 +2224,6 @@
 	char m[256] = "";
 	char a[1024] = "";
 	int x;
-	struct ast_format tmpfmt;
 	struct sockaddr_in dest = { 0, };
 	struct ast_sockaddr dest_tmp;
 	struct mgcp_endpoint *p = sub->parent;
@@ -2236,24 +2258,25 @@
 	ast_copy_string(t, "t=0 0\r\n", sizeof(t));
 	snprintf(m, sizeof(m), "m=audio %d RTP/AVP", ntohs(dest.sin_port));
 
-	ast_format_cap_iter_start(p->cap);
-	while (!(ast_format_cap_iter_next(p->cap, &tmpfmt))) {
-		if (AST_FORMAT_GET_TYPE(tmpfmt.id) != AST_FORMAT_TYPE_AUDIO) {
-			/* Audio is now discontiguous */
+	for (x = 0; x < ast_format_cap_count(p->cap); x++) {
+		struct ast_format *format = ast_format_cap_get_format(p->cap, x);
+
+		if (ast_format_get_type(format) != AST_MEDIA_TYPE_AUDIO) {
+			ao2_ref(format, -1);
 			continue;
 		}
-		if (ast_format_cap_iscompatible(p->cap, &tmpfmt)) {
-			ast_debug(1, "Answering with capability %s\n", ast_getformatname(&tmpfmt));
-			codec = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(sub->rtp), 1, &tmpfmt, 0);
-			if (codec > -1) {
-				snprintf(costr, sizeof(costr), " %d", codec);
-				strncat(m, costr, sizeof(m) - strlen(m) - 1);
-				snprintf(costr, sizeof(costr), "a=rtpmap:%d %s/8000\r\n", codec, ast_rtp_lookup_mime_subtype2(1, &tmpfmt, 0, 0));
-				strncat(a, costr, sizeof(a) - strlen(a) - 1);
-			}
-		}
-	}
-	ast_format_cap_iter_end(p->cap);
+
+		ast_debug(1, "Answering with capability %s\n", ast_format_get_name(format));
+		codec = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(sub->rtp), 1, format, 0);
+		if (codec > -1) {
+			snprintf(costr, sizeof(costr), " %d", codec);
+			strncat(m, costr, sizeof(m) - strlen(m) - 1);
+			snprintf(costr, sizeof(costr), "a=rtpmap:%d %s/8000\r\n", codec, ast_rtp_lookup_mime_subtype2(1, format, 0, 0));
+			strncat(a, costr, sizeof(a) - strlen(a) - 1);
+		}
+
+		ao2_ref(format, -1);
+	}
 
 	for (x = 1LL; x <= AST_RTP_MAX; x <<= 1) {
 		if (p->nonCodecCapability & x) {
@@ -2292,7 +2315,7 @@
 	char local[256];
 	char tmp[80];
 	struct mgcp_endpoint *p = sub->parent;
-	struct ast_format tmpfmt;
+	int i;
 	struct ast_sockaddr sub_tmpdest_tmp;
 	unsigned int oseq;
 
@@ -2304,18 +2327,20 @@
 		return 0;
 	}
 	ast_copy_string(local, "e:on, s:off, p:20", sizeof(local));
-	ast_format_cap_iter_start(p->cap);
-	while (!(ast_format_cap_iter_next(p->cap, &tmpfmt))) {
-		if (AST_FORMAT_GET_TYPE(tmpfmt.id) != AST_FORMAT_TYPE_AUDIO) {
-			/* Audio is now discontiguous */
+
+	for (i = 0; i < ast_format_cap_count(p->cap); i++) {
+		struct ast_format *format = ast_format_cap_get_format(p->cap, i);
+
+		if (ast_format_get_type(format) != AST_MEDIA_TYPE_AUDIO) {
+			ao2_ref(format, -1);
 			continue;
 		}
-		if (ast_format_cap_iscompatible(p->cap, &tmpfmt)) {
-			snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype2(1, &tmpfmt, 0, 0));
-			strncat(local, tmp, sizeof(local) - strlen(local) - 1);
-		}
-	}
-	ast_format_cap_iter_end(p->cap);
+
+		snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype2(1, format, 0, 0));
+		strncat(local, tmp, sizeof(local) - strlen(local) - 1);
+
+		ao2_ref(format, -1);
+	}
 
 	if (sub->gate) {
 		if (sub->gate->state == GATE_ALLOCATED || sub->gate->state == GATE_OPEN) {
@@ -2351,7 +2376,7 @@
 	struct mgcp_request resp;
 	char local[256];
 	char tmp[80];
-	struct ast_format tmpfmt;
+	int i;
 	struct mgcp_endpoint *p = sub->parent;
 	unsigned int oseq;
 
@@ -2360,18 +2385,19 @@
 
 	ast_copy_string(local, "e:on, s:off, p:20", sizeof(local));
 
-	ast_format_cap_iter_start(p->cap);
-	while (!(ast_format_cap_iter_next(p->cap, &tmpfmt))) {
-		if (AST_FORMAT_GET_TYPE(tmpfmt.id) != AST_FORMAT_TYPE_AUDIO) {
-			/* Audio is now discontiguous */
+	for (i = 0; i < ast_format_cap_count(p->cap); i++) {
+		struct ast_format *format = ast_format_cap_get_format(p->cap, i);
+
+		if (ast_format_get_type(format) != AST_MEDIA_TYPE_AUDIO) {
+			ao2_ref(format, -1);
 			continue;
 		}
-		if (ast_format_cap_iscompatible(p->cap, &tmpfmt)) {
-			snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype2(1, &tmpfmt, 0, 0));
-			strncat(local, tmp, sizeof(local) - strlen(local) - 1);
-		}
-	}
-	ast_format_cap_iter_end(p->cap);
+
+		snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype2(1, format, 0, 0));
+		strncat(local, tmp, sizeof(local) - strlen(local) - 1);
+
+		ao2_ref(format, -1);
+	}
 
 	if (sub->gate) {
 		if(sub->gate->state == GATE_ALLOCATED) {
@@ -2447,22 +2473,23 @@
 static int transmit_connect(struct mgcp_subchannel *sub)
 {
 	struct mgcp_request resp;
+	int x;
 	char local[256];
 	char tmp[80];
-	struct ast_format tmpfmt;
+	struct ast_format *tmpfmt;
 	struct mgcp_endpoint *p = sub->parent;
 	unsigned int oseq;
 
 	ast_copy_string(local, "p:20, s:off, e:on", sizeof(local));
 
-	ast_format_cap_iter_start(p->cap);
-	while (!(ast_format_cap_iter_next(p->cap, &tmpfmt))) {
-		if (ast_format_cap_iscompatible(p->cap, &tmpfmt)) {
-			snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype2(1, &tmpfmt, 0, 0));
-			strncat(local, tmp, sizeof(local) - strlen(local) - 1);
-		}
-	}
-	ast_format_cap_iter_end(p->cap);
+	for (x = 0; x < ast_format_cap_count(p->cap); x++) {
+		tmpfmt = ast_format_cap_get_format(p->cap, x);
+
+		snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype2(1, tmpfmt, 0, 0));
+		strncat(local, tmp, sizeof(local) - strlen(local) - 1);
+
+		ao2_ref(tmpfmt, -1);
+	}
 
 	ast_debug(3, "Creating connection for %s@%s-%d in cxmode: %s callid: %s\n",
 		    p->name, p->parent->name, sub->id, mgcp_cxmodes[sub->cxmode], sub->callid);
@@ -2557,7 +2584,7 @@
 {
 	struct mgcp_request resp;
 	struct mgcp_endpoint *p = sub->parent;
-	struct ast_format tmpfmt;
+	int i;
 	int fc = 1;
 	char local[256];
 	char tmp[80];
@@ -2572,18 +2599,22 @@
 		p->name, p->parent->name, sub->id, mgcp_cxmodes[sub->cxmode], sub->callid);
 
 	ast_copy_string(local, "", sizeof(local));
-	ast_format_cap_iter_start(p->cap);
-	while (!(ast_format_cap_iter_next(p->cap, &tmpfmt))) {
+	for (i = 0; i < ast_format_cap_count(p->cap); i++) {
+		struct ast_format *format = ast_format_cap_get_format(p->cap, i);
+
 		if (p->ncs && !fc) {
-			ast_format_cap_set(p->cap, &tmpfmt); /* sb5120e bug */
+			ast_format_cap_remove_bytype(p->cap, AST_MEDIA_TYPE_UNKNOWN);
+			ast_format_cap_add(p->cap, format, 0); /* sb5120e bug */
+			ao2_ref(format, -1);
 			break;
 		} else {
 			fc = 0;
-			snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype2(1, &tmpfmt, 0, 0));
+			snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype2(1, format, 0, 0));
 		}
 		strncat(local, tmp, sizeof(local) - strlen(local) - 1);
-	}
-	ast_format_cap_iter_end(p->cap);
+
+		ao2_ref(format, -1);
+	}
 
 	if (!sub->sdpsent) {
 		if (sub->gate) {
@@ -3948,7 +3979,7 @@
 	struct ast_channel *tmpc = NULL;
 	char tmp[256];
 
-	if (!(ast_format_cap_has_joint(cap, global_capability))) {
+	if (!(ast_format_cap_iscompatible(cap, global_capability))) {
 		ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%s'\n", ast_getformatname_multiple(tmp, sizeof(tmp), cap));
 		/*return NULL;*/
 	}
@@ -4185,7 +4216,7 @@
 					ast_mutex_init(&e->lock);
 					ast_mutex_init(&e->rqnt_queue_lock);
 					ast_mutex_init(&e->cmd_queue_lock);
-					e->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+					e->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
 					ast_copy_string(e->name, v->value, sizeof(e->name));
 					e->needaudit = 1;
 				}
@@ -4210,7 +4241,7 @@
 				snprintf(e->rqnt_ident, sizeof(e->rqnt_ident), "%08lx", ast_random());
 				e->msgstate = -1;
 				e->amaflags = amaflags;
-				ast_format_cap_copy(e->cap, global_capability);
+				ast_format_cap_append_by_type(e->cap, global_capability, AST_MEDIA_TYPE_UNKNOWN);
 				e->parent = gw;
 				e->ncs = ncs;
 				e->dtmfmode = dtmfmode;
@@ -4292,7 +4323,7 @@
 					ast_mutex_init(&e->lock);
 					ast_mutex_init(&e->rqnt_queue_lock);
 					ast_mutex_init(&e->cmd_queue_lock);
-					e->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+					e->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
 					ast_copy_string(e->name, v->value, sizeof(e->name));
 					e->needaudit = 1;
 				}
@@ -4314,7 +4345,7 @@
 					e->parent = gw;
 				}
 				e->amaflags = amaflags;
-				ast_format_cap_copy(e->cap, global_capability);
+				ast_format_cap_append_by_type(e->cap, global_capability, AST_MEDIA_TYPE_UNKNOWN);
 				e->dtmfmode = dtmfmode;
 				e->ncs = ncs;
 				e->pktcgatealloc = pktcgatealloc;
@@ -4470,7 +4501,8 @@
 {
 	struct mgcp_subchannel *sub = ast_channel_tech_pvt(chan);
 	struct mgcp_endpoint *p = sub->parent;
-	ast_format_cap_copy(result, p->cap);
+
+	ast_format_cap_append_by_type(result, p->cap, AST_MEDIA_TYPE_UNKNOWN);
 }
 
 static struct ast_rtp_glue mgcp_rtp_glue = {
@@ -4556,7 +4588,7 @@
 	ast_mutex_destroy(&e->lock);
 	ast_mutex_destroy(&e->rqnt_queue_lock);
 	ast_mutex_destroy(&e->cmd_queue_lock);
-	e->cap = ast_format_cap_destroy(e->cap);
+	ao2_ref(e->cap, -1);
 	ast_free(e);
 }
 
@@ -4654,7 +4686,6 @@
 	char *cat;
 	struct ast_hostent ahp;
 	struct hostent *hp;
-	struct ast_format format;
 	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 
 	if (gethostname(ourhost, sizeof(ourhost)-1)) {
@@ -4694,19 +4725,9 @@
 				memcpy(&bindaddr.sin_addr, hp->h_addr, sizeof(bindaddr.sin_addr));
 			}
 		} else if (!strcasecmp(v->name, "allow")) {
-			ast_getformatbyname(v->value, &format);
-			if (!format.id) {
-				ast_log(LOG_WARNING, "Cannot allow unknown format '%s'\n", v->value);
-			} else {
-				ast_format_cap_add(global_capability, &format);
-			}
+			ast_parse_allow_disallow(global_capability, v->value, 1);
 		} else if (!strcasecmp(v->name, "disallow")) {
-			ast_getformatbyname(v->value, &format);
-			if (!format.id) {
-				ast_log(LOG_WARNING, "Cannot allow unknown format '%s'\n", v->value);
-			} else {
-				ast_format_cap_remove(global_capability, &format);
-			}
+			ast_parse_allow_disallow(global_capability, v->value, 0);
 		} else if (!strcasecmp(v->name, "tos")) {
 			if (ast_str2tos(v->value, &qos.tos)) {
 			    ast_log(LOG_WARNING, "Invalid tos value at line %d, refer to QoS documentation\n", v->lineno);
@@ -4831,36 +4852,44 @@
  */
 static int load_module(void)
 {
-	struct ast_format tmpfmt;
-
-	if (!(global_capability = ast_format_cap_alloc(0))) {
+	if (!(global_capability = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
 		return AST_MODULE_LOAD_FAILURE;
 	}
-	if (!(mgcp_tech.capabilities = ast_format_cap_alloc(0))) {
+	if (!(mgcp_tech.capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
+		ao2_ref(global_capability, -1);
 		return AST_MODULE_LOAD_FAILURE;
 	}
-	ast_format_cap_add(global_capability, ast_format_set(&tmpfmt, AST_FORMAT_ULAW, 0));
-	ast_format_cap_add(mgcp_tech.capabilities, ast_format_set(&tmpfmt, AST_FORMAT_ULAW, 0));
-	ast_format_cap_add(mgcp_tech.capabilities, ast_format_set(&tmpfmt, AST_FORMAT_ALAW, 0));
+	ast_format_cap_add(global_capability, ast_format_ulaw, 0);
+	ast_format_cap_add(mgcp_tech.capabilities, ast_format_ulaw, 0);
+	ast_format_cap_add(mgcp_tech.capabilities, ast_format_alaw, 0);
 	if (!(sched = ast_sched_context_create())) {
 		ast_log(LOG_WARNING, "Unable to create schedule context\n");
+		ao2_ref(global_capability, -1);
+		ao2_ref(mgcp_tech.capabilities, -1);
 		return AST_MODULE_LOAD_FAILURE;
 	}
 
 	if (!(io = io_context_create())) {
 		ast_log(LOG_WARNING, "Unable to create I/O context\n");
 		ast_sched_context_destroy(sched);
+		ao2_ref(global_capability, -1);
+		ao2_ref(mgcp_tech.capabilities, -1);
 		return AST_MODULE_LOAD_FAILURE;
 	}
 
-	if (reload_config(0))
+	if (reload_config(0)) {
+		ao2_ref(global_capability, -1);
+		ao2_ref(mgcp_tech.capabilities, -1);
 		return AST_MODULE_LOAD_DECLINE;
+	}
 
 	/* Make sure we can register our mgcp channel type */
 	if (ast_channel_register(&mgcp_tech)) {
 		ast_log(LOG_ERROR, "Unable to register channel class 'MGCP'\n");
 		io_context_destroy(io);
 		ast_sched_context_destroy(sched);
+		ao2_ref(global_capability, -1);
+		ao2_ref(mgcp_tech.capabilities, -1);
 		return AST_MODULE_LOAD_FAILURE;
 	}
 
@@ -4973,8 +5002,10 @@
 	ast_cli_unregister_multiple(cli_mgcp, sizeof(cli_mgcp) / sizeof(struct ast_cli_entry));
 	ast_sched_context_destroy(sched);
 
-	global_capability = ast_format_cap_destroy(global_capability);
-	mgcp_tech.capabilities = ast_format_cap_destroy(mgcp_tech.capabilities);
+	ao2_ref(global_capability, -1);
+	global_capability = NULL;
+	ao2_ref(mgcp_tech.capabilities, -1);
+	mgcp_tech.capabilities = NULL;
 
 	return 0;
 }

Modified: team/group/media_formats-reviewed/channels/chan_skinny.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/channels/chan_skinny.c?view=diff&rev=414047&r1=414046&r2=414047
==============================================================================
--- team/group/media_formats-reviewed/channels/chan_skinny.c (original)
+++ team/group/media_formats-reviewed/channels/chan_skinny.c Fri May 16 07:24:43 2014
@@ -84,6 +84,7 @@
 #include "asterisk/bridge.h"
 #include "asterisk/parking.h"
 #include "asterisk/stasis_channels.h"
+#include "asterisk/format_cache.h"
 
 /*** DOCUMENTATION
 	<manager name="SKINNYdevices" language="en_US">
@@ -174,7 +175,6 @@
 static const char config[] = "skinny.conf";
 
 static struct ast_format_cap *default_cap;
-static struct ast_codec_pref default_prefs;
 
 enum skinny_codecs {
 	SKINNY_CODEC_ALAW = 2,
@@ -1454,8 +1454,6 @@
 	int amaflags;					\
 	int instance;					\
 	int group;					\
-	struct ast_codec_pref confprefs;		\
-	struct ast_codec_pref prefs;			\
 	int nonCodecCapability;				\
 	int immediate;					\
 	int nat;					\
@@ -1568,7 +1566,6 @@
 	int hookstate;					\
 	int lastlineinstance;					\
 	int lastcallreference;					\
-	struct ast_codec_pref confprefs;			\
 	int earlyrtp;						\
 	int transfer;						\
 	int callwaiting;					\
@@ -1679,11 +1676,11 @@
 		return NULL;
 	}
 
-	l->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
-	l->confcap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+	l->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	l->confcap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
 	if (!l->cap || !l->confcap) {
-		l->cap = ast_format_cap_destroy(l->cap);
-		l->confcap = ast_format_cap_destroy(l->confcap);
+		ao2_cleanup(l->cap);
+		ao2_cleanup(l->confcap);
 		ast_free(l);
 		return NULL;
 	}
@@ -1691,8 +1688,8 @@
 }
 static struct skinny_line *skinny_line_destroy(struct skinny_line *l)
 {
-	l->cap = ast_format_cap_destroy(l->cap);
-	l->confcap = ast_format_cap_destroy(l->confcap);
+	ao2_ref(l->cap, -1);
+	ao2_ref(l->confcap, -1);
 	l->named_callgroups = ast_unref_namedgroups(l->named_callgroups);
 	l->named_pickupgroups = ast_unref_namedgroups(l->named_pickupgroups);
 	ast_free(l->container);
@@ -1706,12 +1703,12 @@
 		return NULL;
 	}
 
-	d->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
-	d->confcap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+	d->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	d->confcap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
 	d->endpoint = ast_endpoint_create("Skinny", dname);
 	if (!d->cap || !d->confcap || !d->endpoint) {
-		d->cap = ast_format_cap_destroy(d->cap);
-		d->confcap = ast_format_cap_destroy(d->confcap);
+		ao2_cleanup(d->cap);
+		ao2_cleanup(d->confcap);
 		ast_free(d);
 		return NULL;
 	}
@@ -1722,8 +1719,8 @@
 }
 static struct skinny_device *skinny_device_destroy(struct skinny_device *d)
 {
-	d->cap = ast_format_cap_destroy(d->cap);
-	d->confcap = ast_format_cap_destroy(d->confcap);
+	ao2_ref(d->cap, -1);
+	ao2_ref(d->confcap, -1);
 	ast_endpoint_shutdown(d->endpoint);
 	ast_free(d);
 	return NULL;
@@ -2103,51 +2100,49 @@
 	return sd;
 }
 
-static struct ast_format *codec_skinny2ast(enum skinny_codecs skinnycodec, struct ast_format *result)
+static struct ast_format *codec_skinny2ast(enum skinny_codecs skinnycodec)
 {
 	switch (skinnycodec) {
 	case SKINNY_CODEC_ALAW:
-		return ast_format_set(result, AST_FORMAT_ALAW, 0);
+		return ast_format_alaw;
 	case SKINNY_CODEC_ULAW:
-		return ast_format_set(result, AST_FORMAT_ULAW, 0);
+		return ast_format_ulaw;
 	case SKINNY_CODEC_G722:
-		return ast_format_set(result, AST_FORMAT_G722, 0);
+		return ast_format_g722;
 	case SKINNY_CODEC_G723_1:
-		return ast_format_set(result, AST_FORMAT_G723_1, 0);
+		return ast_format_g723;
 	case SKINNY_CODEC_G729A:
-		return ast_format_set(result, AST_FORMAT_G729A, 0);
+		return ast_format_g729;
 	case SKINNY_CODEC_G726_32:
-		return ast_format_set(result, AST_FORMAT_G726_AAL2, 0); /* XXX Is this right? */
+		return ast_format_g726; /* XXX Is this right? */
 	case SKINNY_CODEC_H261:
-		return ast_format_set(result, AST_FORMAT_H261, 0);
+		return ast_format_h261;
 	case SKINNY_CODEC_H263:
-		return ast_format_set(result, AST_FORMAT_H263 ,0);
+		return ast_format_h263;
 	default:
-		ast_format_clear(result);
-		return result;
+		return NULL;
 	}
 }
 
 static int codec_ast2skinny(const struct ast_format *astcodec)
 {
-	switch (astcodec->id) {
-	case AST_FORMAT_ALAW:
+	if (ast_format_cmp(astcodec, ast_format_alaw) == AST_FORMAT_CMP_EQUAL) {
 		return SKINNY_CODEC_ALAW;
-	case AST_FORMAT_ULAW:
+	} else if (ast_format_cmp(astcodec, ast_format_ulaw) == AST_FORMAT_CMP_EQUAL) {
 		return SKINNY_CODEC_ULAW;
-	case AST_FORMAT_G722:
+	} else if (ast_format_cmp(astcodec, ast_format_g722) == AST_FORMAT_CMP_EQUAL) {
 		return SKINNY_CODEC_G722;
-	case AST_FORMAT_G723_1:
+	} else if (ast_format_cmp(astcodec, ast_format_g723) == AST_FORMAT_CMP_EQUAL) {
 		return SKINNY_CODEC_G723_1;
-	case AST_FORMAT_G729A:
+	} else if (ast_format_cmp(astcodec, ast_format_g729) == AST_FORMAT_CMP_EQUAL) {
 		return SKINNY_CODEC_G729A;
-	case AST_FORMAT_G726_AAL2: /* XXX Is this right? */
+	} else if (ast_format_cmp(astcodec, ast_format_g726) == AST_FORMAT_CMP_EQUAL) {
 		return SKINNY_CODEC_G726_32;
-	case AST_FORMAT_H261:
+	} else if (ast_format_cmp(astcodec, ast_format_h261) == AST_FORMAT_CMP_EQUAL) {
 		return SKINNY_CODEC_H261;
-	case AST_FORMAT_H263:
+	} else if (ast_format_cmp(astcodec, ast_format_h263) == AST_FORMAT_CMP_EQUAL) {
 		return SKINNY_CODEC_H263;
-	default:
+	} else {
 		return 0;
 	}
 }
@@ -2312,13 +2307,8 @@
 				instance++;
 			}
 			AST_LIST_TRAVERSE(&d->lines, l, list) {
-				ast_format_cap_joint_copy(l->confcap, d->cap, l->cap);
-				l->prefs = l->confprefs;
-				if (!l->prefs.order[0]) {
-					l->prefs = d->confprefs;
-				}
-				/* l->capability = d->capability;
-				l->prefs = d->prefs; */
+				ast_format_cap_get_compatible(l->confcap, d->cap, l->cap);
+				/* l->capability = d->capability; */
 				l->instance = instance;
 				l->newmsgs = ast_app_has_voicemail(l->mailbox, NULL);
 				set_callforwards(l, NULL, SKINNY_CFWD_ALL|SKINNY_CFWD_BUSY|SKINNY_CFWD_NOANSWER);
@@ -2656,23 +2646,27 @@
 {
 	struct skinny_req *req;
 	struct skinny_line *l = sub->line;
-	struct ast_format_list fmt;
-	struct ast_format tmpfmt;
+	struct ast_format *tmpfmt;
+	unsigned int framing;
 
 	if (!(req = req_alloc(sizeof(struct open_receive_channel_message), OPEN_RECEIVE_CHANNEL_MESSAGE)))
 		return;
+
 	ast_best_codec(l->cap, &tmpfmt);
-	fmt = ast_codec_pref_getsize(&l->prefs, &tmpfmt);
+	framing = ast_format_cap_get_framing(l->cap, tmpfmt);
 
 	req->data.openreceivechannel.conferenceId = htolel(sub->callid);
 	req->data.openreceivechannel.partyId = htolel(sub->callid);
-	req->data.openreceivechannel.packets = htolel(fmt.cur_ms);
-	req->data.openreceivechannel.capability = htolel(codec_ast2skinny(&fmt.format));
+	req->data.openreceivechannel.packets = htolel(framing);
+	req->data.openreceivechannel.capability = htolel(codec_ast2skinny(tmpfmt));
 	req->data.openreceivechannel.echo = htolel(0);
 	req->data.openreceivechannel.bitrate = htolel(0);
 
 	SKINNY_DEBUG(DEBUG_PACKET, 3, "Transmitting OPEN_RECEIVE_CHANNEL_MESSAGE to %s, confid %d, partyid %d, ms %d, fmt %d, echo %d, brate %d\n",
-		d->name, sub->callid, sub->callid, fmt.cur_ms, codec_ast2skinny(&fmt.format), 0, 0);
+		d->name, sub->callid, sub->callid, framing, codec_ast2skinny(tmpfmt), 0, 0);
+
+	ao2_ref(tmpfmt, -1);
+
 	transmit_response(d, req);
 }
 
@@ -3033,7 +3027,8 @@
 	transmit_response(d, req);
 }
 
-static void transmit_startmediatransmission(struct skinny_device *d, struct skinny_subchannel *sub, struct sockaddr_in dest, struct ast_format_list fmt)
+static void transmit_startmediatransmission(struct skinny_device *d, struct skinny_subchannel *sub, struct sockaddr_in dest,
+	struct ast_format *format, unsigned int framing)
 {
 	struct skinny_req *req;
 
@@ -3044,8 +3039,8 @@
 		req->data.startmedia_ip4.passThruPartyId = htolel(sub->callid);
 		req->data.startmedia_ip4.remoteIp = dest.sin_addr.s_addr;
 		req->data.startmedia_ip4.remotePort = htolel(ntohs(dest.sin_port));
-		req->data.startmedia_ip4.packetSize = htolel(fmt.cur_ms);
-		req->data.startmedia_ip4.payloadType = htolel(codec_ast2skinny(&fmt.format));
+		req->data.startmedia_ip4.packetSize = htolel(framing);
+		req->data.startmedia_ip4.payloadType = htolel(codec_ast2skinny(format));
 		req->data.startmedia_ip4.qualifier.precedence = htolel(127);
 		req->data.startmedia_ip4.qualifier.vad = htolel(0);
 		req->data.startmedia_ip4.qualifier.packets = htolel(0);
@@ -3057,8 +3052,8 @@
 		req->data.startmedia_ip6.passThruPartyId = htolel(sub->callid);
 		memcpy(req->data.startmedia_ip6.remoteIp, &dest.sin_addr.s_addr, sizeof(dest.sin_addr.s_addr));
 		req->data.startmedia_ip6.remotePort = htolel(ntohs(dest.sin_port));
-		req->data.startmedia_ip6.packetSize = htolel(fmt.cur_ms);
-		req->data.startmedia_ip6.payloadType = htolel(codec_ast2skinny(&fmt.format));
+		req->data.startmedia_ip6.packetSize = htolel(framing);
+		req->data.startmedia_ip6.payloadType = htolel(codec_ast2skinny(format));
 		req->data.startmedia_ip6.qualifier.precedence = htolel(127);
 		req->data.startmedia_ip6.qualifier.vad = htolel(0);
 		req->data.startmedia_ip6.qualifier.packets = htolel(0);
@@ -3066,7 +3061,7 @@
 	}
 
 	SKINNY_DEBUG(DEBUG_PACKET, 3, "Transmitting START_MEDIA_TRANSMISSION_MESSAGE to %s, callid %d, passthrupartyid %d, ip %s:%d, ms %d, fmt %d, prec 127\n",
-		d->name, sub->callid, sub->callid, ast_inet_ntoa(dest.sin_addr), dest.sin_port, fmt.cur_ms, codec_ast2skinny(&fmt.format));
+		d->name, sub->callid, sub->callid, ast_inet_ntoa(dest.sin_addr), dest.sin_port, framing, codec_ast2skinny(format));
 	transmit_response(d, req);
 }
 
@@ -3643,7 +3638,6 @@
 	struct skinny_subchannel *sub;
 	struct skinny_line *l;
 	struct skinny_device *d;
-	struct ast_format_list fmt;
 	struct sockaddr_in us = { 0, };
 	struct sockaddr_in them = { 0, };
 	struct ast_sockaddr them_tmp;
@@ -3662,7 +3656,8 @@
 	d = l->device;
 
 	if (rtp){
-		struct ast_format tmpfmt;
+		struct ast_format *tmpfmt;
+		unsigned int framing;
 		ast_rtp_instance_get_remote_address(rtp, &them_tmp);
 		ast_sockaddr_to_sin(&them_tmp, &them);
 
@@ -3672,18 +3667,20 @@
 		SKINNY_DEBUG(DEBUG_AUDIO, 4, "Peerip = %s:%d\n", ast_inet_ntoa(them.sin_addr), ntohs(them.sin_port));
 
 		ast_best_codec(l->cap, &tmpfmt);
-		fmt = ast_codec_pref_getsize(&l->prefs, &tmpfmt);
-
-		SKINNY_DEBUG(DEBUG_AUDIO, 4, "Setting payloadType to '%s' (%d ms)\n", ast_getformatname(&fmt.format), fmt.cur_ms);
+		framing = ast_format_cap_get_framing(l->cap, tmpfmt);
+
+		SKINNY_DEBUG(DEBUG_AUDIO, 4, "Setting payloadType to '%s' (%d ms)\n", ast_format_get_name(tmpfmt), framing);
 
 		if (!(l->directmedia) || (l->nat)){
 			ast_rtp_instance_get_local_address(rtp, &us_tmp);
 			ast_sockaddr_to_sin(&us_tmp, &us);
 			us.sin_addr.s_addr = us.sin_addr.s_addr ? us.sin_addr.s_addr : d->ourip.s_addr;
-			transmit_startmediatransmission(d, sub, us, fmt);
+			transmit_startmediatransmission(d, sub, us, tmpfmt, framing);
 		} else {
-			transmit_startmediatransmission(d, sub, them, fmt);
-		}
+			transmit_startmediatransmission(d, sub, them, tmpfmt, framing);
+		}
+
+		ao2_ref(tmpfmt, -1);
 
 		return 0;
 	}
@@ -4067,25 +4064,6 @@
 	}
 }
 
-/*! \brief Print codec list from preference to CLI/manager */
-static void print_codec_to_cli(int fd, struct ast_codec_pref *pref)
-{
-	int x;
-	struct ast_format tmpfmt;
-
-	for(x = 0; x < 32 ; x++) {
-		ast_codec_pref_index(pref, x, &tmpfmt);
-		if (!tmpfmt.id)
-			break;
-		ast_cli(fd, "%s", ast_getformatname(&tmpfmt));
-		ast_cli(fd, ":%d", pref->framing[x]);
-		if (x < 31 && ast_codec_pref_index(pref, x + 1, &tmpfmt))
-			ast_cli(fd, ",");
-	}
-	if (!x)
-		ast_cli(fd, "none");
-}
-
 static char *_skinny_show_devices(int fd, int *total, struct mansession *s, const struct message *m, int argc, const char * const *argv)
 {
 	struct skinny_device *d;
@@ -4468,8 +4446,6 @@
 	struct skinny_device *d;
 	struct skinny_line *l;
 	struct skinny_subline *subline;
-	struct ast_codec_pref *pref;
-	int x = 0;
 	char codec_buf[512];
 	char group_buf[256];
 	char cbuf[256];
@@ -4542,9 +4518,6 @@
 				ast_cli(fd, "Neg Codecs:       ");
 				ast_getformatname_multiple(codec_buf, sizeof(codec_buf) - 1, l->cap);
 				ast_cli(fd, "%s\n", codec_buf);
-				ast_cli(fd, "Codec Order:      (");
-				print_codec_to_cli(fd, &l->prefs);
-				ast_cli(fd, ")\n");
 				if  (AST_LIST_FIRST(&l->sublines)) {
 					ast_cli(fd, "Sublines:\n");
 					AST_LIST_TRAVERSE(&l->sublines, subline, list) {
@@ -4594,17 +4567,6 @@
 				astman_append(s, "Parkinglot: %s\r\n", S_OR(l->parkinglot, "<not set>"));
 				ast_getformatname_multiple(codec_buf, sizeof(codec_buf) - 1, l->confcap);
 				astman_append(s, "Codecs: %s\r\n", codec_buf);
-				astman_append(s, "CodecOrder: ");
-				pref = &l->prefs;
-				for(x = 0; x < 32 ; x++) {
-					struct ast_format tmpfmt;
-					ast_codec_pref_index(pref, x, &tmpfmt);
-					if (!tmpfmt.id)
-						break;
-					astman_append(s, "%s", ast_getformatname(&tmpfmt));
-					if (x < 31 && ast_codec_pref_index(pref, x+1, &tmpfmt))
-						astman_append(s, ",");
-				}
 				astman_append(s, "\r\n");
 			}
 		}
@@ -4834,8 +4796,11 @@
 		ast_rtp_instance_set_prop(sub->vrtp, AST_RTP_PROPERTY_NAT, l->nat);
 	}
 	/* Set Frame packetization */
+	/* BUGBUG: RTP - Needs to be updated if API changes */
+#if 0
 	if (sub->rtp)
 		ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(sub->rtp), sub->rtp, &l->prefs);
+#endif
 
 	/* Create the RTP connection */
 	transmit_connect(d, sub);
@@ -5097,9 +5062,17 @@
 	if (ast) {
 		/* We already hold the channel lock */
 		if (f->frametype == AST_FRAME_VOICE) {
-			if (!(ast_format_cap_iscompatible(ast_channel_nativeformats(ast), &f->subclass.format))) {
-				ast_debug(1, "Oooh, format changed to %s\n", ast_getformatname(&f->subclass.format));
-				ast_format_cap_set(ast_channel_nativeformats(ast), &f->subclass.format);
+			if (!(ast_format_cap_iscompatible_format(ast_channel_nativeformats(ast), 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_add(caps, f->subclass.format, 0);
+					ast_channel_nativeformats_set(ast, caps);
+					ao2_ref(caps, -1);
+				}
 				ast_set_read_format(ast, ast_channel_readformat(ast));
 				ast_set_write_format(ast, ast_channel_writeformat(ast));
 			}
@@ -5130,13 +5103,13 @@
 			return 0;
 		}
 	} else {
-		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))) {
 			char buf[256];
 			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 -1;
 		}
 	}
@@ -5403,16 +5376,23 @@
 	struct skinny_subchannel *sub;
 	struct skinny_device *d = l->device;
 	struct ast_variable *v = NULL;
-	struct ast_format tmpfmt;
+	struct ast_format *tmpfmt;
+	struct ast_format_cap *caps;
 
 	if (!l->device || !l->device->session) {
 		ast_log(LOG_WARNING, "Device for line %s is not registered.\n", l->name);
 		return NULL;
 	}
 
+	caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	if (!caps) {
+		return NULL;
+	}
+
 	tmp = ast_channel_alloc(1, state, l->cid_num, l->cid_name, l->accountcode, l->exten, l->context, linkedid, l->amaflags, "Skinny/%s@%s-%d", l->name, d->name, callnums);
 	if (!tmp) {
 		ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
+		ao2_ref(caps, -1);
 		return NULL;
 	} else {
 		sub = ast_calloc(1, sizeof(*sub));
@@ -5420,6 +5400,7 @@
 			ast_log(LOG_WARNING, "Unable to allocate Skinny subchannel\n");
 			ast_channel_unlock(tmp);
 			ast_channel_unref(tmp);
+			ao2_ref(caps, -1);
 			return NULL;
 		} else {
 			skinny_set_owner(sub, tmp);
@@ -5452,25 +5433,28 @@
 		ast_channel_stage_snapshot(tmp);
 		ast_channel_tech_set(tmp, &skinny_tech);
 		ast_channel_tech_pvt_set(tmp, sub);
-		ast_format_cap_copy(ast_channel_nativeformats(tmp), l->cap);
-		if (ast_format_cap_is_empty(ast_channel_nativeformats(tmp))) {
-			// Should throw an error
-			ast_format_cap_copy(ast_channel_nativeformats(tmp), default_cap);
-		}
+		if (!ast_format_cap_count(l->cap)) {
+			ast_format_cap_append_by_type(caps, l->cap, AST_MEDIA_TYPE_UNKNOWN);

[... 569 lines stripped ...]



More information about the svn-commits mailing list