[asterisk-commits] file: branch group/media_formats r408291 - /team/group/media_formats/channels/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Feb 18 05:43:54 CST 2014


Author: file
Date: Tue Feb 18 05:43:49 2014
New Revision: 408291

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

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

Modified: team/group/media_formats/channels/chan_mgcp.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/channels/chan_mgcp.c?view=diff&rev=408291&r1=408290&r2=408291
==============================================================================
--- team/group/media_formats/channels/chan_mgcp.c (original)
+++ team/group/media_formats/channels/chan_mgcp.c Tue Feb 18 05:43:49 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
@@ -1198,9 +1199,18 @@
 	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", 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(sub->owner, caps);
+					ao2_ref(caps, -1);
+				}
+
 				ast_set_read_format(sub->owner, ast_channel_readformat(sub->owner));
 				ast_set_write_format(sub->owner, ast_channel_writeformat(sub->owner));
 			}
@@ -1248,12 +1258,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),
+				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; */
 		}
 	}
@@ -1489,19 +1499,24 @@
 
 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;
 
 	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) {
+	caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	if (tmp && caps) {
 		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 (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));
 		}
@@ -1517,10 +1532,11 @@
 			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_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);
@@ -1571,6 +1587,7 @@
 		ast_verb(3, "MGCP mgcp_new(%s) created in state: %s\n",
 				ast_channel_name(tmp), ast_state2str(state));
 	} else {
+		ao2_cleanup(caps);
 		ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
 	}
 	return tmp;
@@ -2029,20 +2046,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;
 	}
@@ -2196,7 +2213,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;
@@ -2231,24 +2247,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 (format->codec->type != 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", format->codec->name);
+		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) {
@@ -2287,7 +2304,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;
 
 	if (ast_strlen_zero(sub->cxident) && rtp) {
@@ -2298,18 +2315,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 (format->codec->type != 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) {
@@ -2345,7 +2364,7 @@
 	struct mgcp_request resp;
 	char local[256];
 	char tmp[80];
-	struct ast_format tmpfmt;
+	int i;
 	struct mgcp_endpoint *p = sub->parent;
 
 	ast_debug(3, "Creating connection for %s@%s-%d in cxmode: %s callid: %s\n",
@@ -2353,18 +2372,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 (format->codec->type != 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) {
@@ -2442,19 +2462,19 @@
 	struct mgcp_request resp;
 	char local[256];
 	char tmp[80];
-	struct ast_format tmpfmt;
+	int i;
 	struct mgcp_endpoint *p = sub->parent;
 
 	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 (i = 0; i < ast_format_cap_count(p->cap); i++) {
+		struct ast_format *format = ast_format_cap_get_format(p->cap, i);
+
+		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);
+	}
 
 	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);
@@ -2547,8 +2567,7 @@
 {
 	struct mgcp_request resp;
 	struct mgcp_endpoint *p = sub->parent;
-	struct ast_format tmpfmt;
-	int fc = 1;
+	int i, fc = 1;
 	char local[256];
 	char tmp[80];
 
@@ -2561,18 +2580,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) {
@@ -3934,7 +3957,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;*/
 	}
@@ -4171,7 +4194,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;
 				}
@@ -4196,7 +4219,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;
@@ -4278,7 +4301,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;
 				}
@@ -4300,7 +4323,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;
@@ -4456,7 +4479,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 = {
@@ -4542,7 +4566,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);
 }
 
@@ -4640,7 +4664,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)) {
@@ -4680,19 +4703,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);
@@ -4817,17 +4830,15 @@
  */
 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))) {
 		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");
 		return AST_MODULE_LOAD_FAILURE;
@@ -4959,8 +4970,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;
 }




More information about the asterisk-commits mailing list