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

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Feb 17 13:14:31 CST 2014


Author: file
Date: Mon Feb 17 13:14:27 2014
New Revision: 408288

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=408288
Log:
It builds!

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

Modified: team/group/media_formats/channels/chan_skinny.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/channels/chan_skinny.c?view=diff&rev=408288&r1=408287&r2=408288
==============================================================================
--- team/group/media_formats/channels/chan_skinny.c (original)
+++ team/group/media_formats/channels/chan_skinny.c Mon Feb 17 13:14:27 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,
@@ -1455,8 +1455,6 @@
 	int amaflags;					\
 	int instance;					\
 	int group;					\
-	struct ast_codec_pref confprefs;		\
-	struct ast_codec_pref prefs;			\
 	int nonCodecCapability;				\
 	int immediate;					\
 	int nat;					\
@@ -1569,7 +1567,6 @@
 	int hookstate;					\
 	int lastlineinstance;					\
 	int lastcallreference;					\
-	struct ast_codec_pref confprefs;			\
 	int earlyrtp;						\
 	int transfer;						\
 	int callwaiting;					\
@@ -1680,11 +1677,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;
 	}
@@ -1692,8 +1689,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);
@@ -1707,12 +1704,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;
 	}
@@ -1723,8 +1720,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;
@@ -2104,51 +2101,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;
 	}
 }
@@ -2313,13 +2308,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);
@@ -2657,23 +2647,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);
 }
 
@@ -3034,7 +3028,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;
 
@@ -3045,8 +3040,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);
@@ -3058,8 +3053,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);
@@ -3067,7 +3062,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);
 }
 
@@ -3644,7 +3639,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;
@@ -3663,7 +3657,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);
 
@@ -3673,18 +3668,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", tmpfmt->codec->name, 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;
 	}
@@ -4068,25 +4065,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;
@@ -4469,8 +4447,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];
@@ -4543,9 +4519,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) {
@@ -4595,17 +4568,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");
 			}
 		}
@@ -4835,8 +4797,8 @@
 		ast_rtp_instance_set_prop(sub->vrtp, AST_RTP_PROPERTY_NAT, l->nat);
 	}
 	/* Set Frame packetization */
-	if (sub->rtp)
-		ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(sub->rtp), sub->rtp, &l->prefs);
+//	if (sub->rtp)
+//		ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(sub->rtp), sub->rtp, &l->prefs);
 
 	/* Create the RTP connection */
 	transmit_connect(d, sub);
@@ -5100,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", f->subclass.format->codec->name);
+
+				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));
 			}
@@ -5133,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),
+				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 -1;
 		}
 	}
@@ -5406,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));
@@ -5423,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 {
 			ast_mutex_init(&sub->lock);
@@ -5457,25 +5435,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);
+		} else {
+			ast_format_cap_append_by_type(caps, default_cap, AST_MEDIA_TYPE_UNKNOWN);
+		}
+		ast_channel_nativeformats_set(tmp, caps);
+		ao2_ref(caps, -1);
 		ast_best_codec(ast_channel_nativeformats(tmp), &tmpfmt);
 		SKINNY_DEBUG(DEBUG_SUB, 3, "skinny_new: tmp->nativeformats=%s fmt=%s\n",
 			ast_getformatname_multiple(dbgsub_buf, sizeof(dbgsub_buf), ast_channel_nativeformats(tmp)),
-			ast_getformatname(&tmpfmt));
+			tmpfmt->codec->name);
 		if (sub->rtp) {
 			ast_channel_set_fd(tmp, 0, ast_rtp_instance_fd(sub->rtp, 0));
 		}
 		if (state == AST_STATE_RING) {
 			ast_channel_rings_set(tmp, 1);
 		}
-		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);
 
 		if (!ast_strlen_zero(l->language))
 			ast_channel_language_set(tmp, l->language);
@@ -6680,7 +6661,7 @@
 	struct skinny_device *d = s->device;
 	struct skinny_line *l;
 	uint32_t count = 0;
-	struct ast_format_cap *codecs = ast_format_cap_alloc(0);
+	struct ast_format_cap *codecs = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
 	int i;
 
 	if (!codecs) {
@@ -6694,23 +6675,23 @@
 	}
 
 	for (i = 0; i < count; i++) {
-		struct ast_format acodec;
+		struct ast_format *acodec;
 		int scodec = 0;
 		scodec = letohl(req->data.caps.caps[i].codec);
-		codec_skinny2ast(scodec, &acodec);
-		SKINNY_DEBUG(DEBUG_AUDIO, 4, "Adding codec capability %s (%d)\n", ast_getformatname(&acodec), scodec);
-		ast_format_cap_add(codecs, &acodec);
-	}
-
-	ast_format_cap_joint_copy(d->confcap, codecs, d->cap);
+		acodec = codec_skinny2ast(scodec);
+		SKINNY_DEBUG(DEBUG_AUDIO, 4, "Adding codec capability %s (%d)\n", acodec->codec->name, scodec);
+		ast_format_cap_add(codecs, acodec, 0);
+	}
+
+	ast_format_cap_get_compatible(d->confcap, codecs, d->cap);
 	SKINNY_DEBUG(DEBUG_AUDIO, 4, "Device capability set to '%s'\n", ast_getformatname_multiple(dbgreg_buf, sizeof(dbgreg_buf), d->cap));
 	AST_LIST_TRAVERSE(&d->lines, l, list) {
 		ast_mutex_lock(&l->lock);
-		ast_format_cap_joint_copy(l->confcap, d->cap, l->cap);
+		ast_format_cap_get_compatible(l->confcap, d->cap, l->cap);
 		ast_mutex_unlock(&l->lock);
 	}
 
-	codecs = ast_format_cap_destroy(codecs);
+	ao2_ref(codecs, -1);
 	return 1;
 }
 
@@ -6881,16 +6862,16 @@
 	struct skinny_device *d = s->device;
 	struct skinny_line *l;
 	struct skinny_subchannel *sub;
-	struct ast_format_list fmt;
 	struct sockaddr_in sin = { 0, };
 	struct sockaddr_in us = { 0, };
 	struct ast_sockaddr sin_tmp;
 	struct ast_sockaddr us_tmp;
-	struct ast_format tmpfmt;
+	struct ast_format *tmpfmt;
 	uint32_t addr;
 	int port;
 	int status;
 	int callid;
+	unsigned int framing;
 
 	status = (d->protocolversion<17) ? letohl(req->data.openreceivechannelack_ip4.status) : letohl(req->data.openreceivechannelack_ip6.status);
 
@@ -6942,11 +6923,13 @@
 	SKINNY_DEBUG(DEBUG_PACKET, 4, "asterisk ipaddr = %s:%d\n", ast_inet_ntoa(us.sin_addr), ntohs(us.sin_port));
 
 	ast_best_codec(l->cap, &tmpfmt);
-	fmt = ast_codec_pref_getsize(&l->prefs, &tmpfmt);
-
-	SKINNY_DEBUG(DEBUG_PACKET, 4, "Setting payloadType to '%s' (%d ms)\n", ast_getformatname(&fmt.format), fmt.cur_ms);
-
-	transmit_startmediatransmission(d, sub, us, fmt);
+	framing = ast_format_cap_get_framing(l->cap, tmpfmt);
+
+	SKINNY_DEBUG(DEBUG_PACKET, 4, "Setting payloadType to '%s' (%d ms)\n", tmpfmt->codec->name, framing);
+
+	transmit_startmediatransmission(d, sub, us, tmpfmt, framing);
+
+	ao2_ref(tmpfmt, -1);
 
 	return 1;
 }
@@ -7497,7 +7480,7 @@
 				continue;
 			}
 			ast_format_cap_remove_all(l->cap);
-			ast_parse_allow_disallow(&l->prefs, l->cap, "all", 0);
+			ast_parse_allow_disallow(l->cap, "all", 0);
 			l->instance = 0;
 			unregister_exten(l);
 			ast_devstate_changed(AST_DEVICE_UNAVAILABLE, AST_DEVSTATE_CACHABLE, "Skinny/%s", l->name);
@@ -7713,7 +7696,7 @@
 	struct ast_channel *tmpc = NULL;
 	char tmp[256];
 
-	if (!(ast_format_cap_has_type(cap, AST_FORMAT_TYPE_AUDIO))) {
+	if (!(ast_format_cap_has_type(cap, AST_MEDIA_TYPE_AUDIO))) {
 		ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%s'\n", ast_getformatname_multiple(tmp, sizeof(tmp), cap));
 		return NULL;
 	}
@@ -7870,10 +7853,10 @@
 				}
 				continue;
 			} else if (!strcasecmp(v->name, "allow")) {
-				ast_parse_allow_disallow(&default_prefs, default_cap, v->value, 1);
+				ast_parse_allow_disallow(default_cap, v->value, 1);
 				continue;
 			} else if (!strcasecmp(v->name, "disallow")) {
-				ast_parse_allow_disallow(&default_prefs, default_cap, v->value, 0);
+				ast_parse_allow_disallow(default_cap, v->value, 0);
 				continue;
 			}
 		}
@@ -8080,20 +8063,20 @@
 			}
 		} else if (!strcasecmp(v->name, "allow")) {
 			if (type & (TYPE_DEF_DEVICE | TYPE_DEVICE)) {
-				ast_parse_allow_disallow(&CDEV->confprefs, CDEV->confcap, v->value, 1);
+				ast_parse_allow_disallow(CDEV->confcap, v->value, 1);
 				continue;
 			}
 			if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
-				ast_parse_allow_disallow(&CLINE->confprefs, CLINE->confcap, v->value, 1);
+				ast_parse_allow_disallow(CLINE->confcap, v->value, 1);
 				continue;
 			}
 		} else if (!strcasecmp(v->name, "disallow")) {
 			if (type & (TYPE_DEF_DEVICE | TYPE_DEVICE)) {
-				ast_parse_allow_disallow(&CDEV->confprefs, CDEV->confcap, v->value, 0);
+				ast_parse_allow_disallow(CDEV->confcap, v->value, 0);
 				continue;
 			}
 			if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
-				ast_parse_allow_disallow(&CLINE->confprefs, CLINE->confcap, v->value, 0);
+				ast_parse_allow_disallow(CLINE->confcap, v->value, 0);
 				continue;
 			}
 		} else if (!strcasecmp(v->name, "version")) {
@@ -8303,7 +8286,7 @@
 	memcpy(l, default_line, sizeof(*default_line));
 	ast_mutex_init(&l->lock);
 	ast_copy_string(l->name, lname, sizeof(l->name));
-	ast_format_cap_copy(l->confcap, default_cap);
+	ast_format_cap_append_by_type(l->confcap, default_cap, AST_MEDIA_TYPE_UNKNOWN);
 	AST_LIST_INSERT_TAIL(&lines, l, all);
 
 	ast_mutex_lock(&l->lock);
@@ -8362,7 +8345,7 @@
 	memcpy(d, default_device, sizeof(*default_device));
 	ast_mutex_init(&d->lock);
 	ast_copy_string(d->name, dname, sizeof(d->name));
-	ast_format_cap_copy(d->confcap, default_cap);
+	ast_format_cap_append_by_type(d->confcap, default_cap, AST_MEDIA_TYPE_UNKNOWN);
 	AST_LIST_INSERT_TAIL(&devices, d, list);
 
 	ast_mutex_lock(&d->lock);
@@ -8453,7 +8436,6 @@
 	}
 
 	memset(&bindaddr, 0, sizeof(bindaddr));
-	memset(&default_prefs, 0, sizeof(default_prefs));
 	immed_dialchar = '\0';
 	memset(&vmexten, '\0', sizeof(vmexten));
 
@@ -8482,7 +8464,6 @@
 	bindaddr.sin_family = AF_INET;
 
 	/* load the lines sections */
-	default_line->confprefs = default_prefs;
 	config_parse_variables(TYPE_DEF_LINE, default_line, ast_variable_browse(cfg, "lines"));
 	cat = ast_category_browse(cfg, "lines");
 	while (cat && strcasecmp(cat, "general") && strcasecmp(cat, "devices")) {
@@ -8491,7 +8472,6 @@
 	}
 
 	/* load the devices sections */
-	default_device->confprefs = default_prefs;
 	config_parse_variables(TYPE_DEF_DEVICE, default_device, ast_variable_browse(cfg, "devices"));
 	cat = ast_category_browse(cfg, "devices");
 	while (cat && strcasecmp(cat, "general") && strcasecmp(cat, "lines")) {
@@ -8678,17 +8658,17 @@
 static int load_module(void)
 {
 	int res = 0;
-	struct ast_format tmpfmt;
-	if (!(default_cap = ast_format_cap_alloc(0))) {
+
+	if (!(default_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
 		return AST_MODULE_LOAD_DECLINE;
 	}
-	if (!(skinny_tech.capabilities = ast_format_cap_alloc(0))) {
+	if (!(skinny_tech.capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
-	ast_format_cap_add_all_by_type(skinny_tech.capabilities, AST_FORMAT_TYPE_AUDIO);
-	ast_format_cap_add(default_cap, ast_format_set(&tmpfmt, AST_FORMAT_ULAW, 0));
-	ast_format_cap_add(default_cap, ast_format_set(&tmpfmt, AST_FORMAT_ALAW, 0));
+	ast_format_cap_add_all_by_type(skinny_tech.capabilities, AST_MEDIA_TYPE_AUDIO);
+	ast_format_cap_add(default_cap, ast_format_ulaw, 0);
+	ast_format_cap_add(default_cap, ast_format_alaw, 0);
 
 	for (; res < ARRAY_LEN(soft_key_template_default); res++) {
 		soft_key_template_default[res].softKeyEvent = htolel(soft_key_template_default[res].softKeyEvent);
@@ -8797,8 +8777,8 @@
 	if (con)
 		ast_context_destroy(con, "Skinny");
 
-	default_cap = ast_format_cap_destroy(default_cap);
-	skinny_tech.capabilities = ast_format_cap_destroy(skinny_tech.capabilities);
+	ao2_ref(default_cap, -1);
+	ao2_ref(skinny_tech.capabilities, -1);
 	return 0;
 }
 




More information about the svn-commits mailing list