[svn-commits] dvossel: branch dvossel/fixtheworld_phase1_step3 r302598 - /team/dvossel/fixt...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jan 19 14:10:24 CST 2011


Author: dvossel
Date: Wed Jan 19 14:10:20 2011
New Revision: 302598

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=302598
Log:
conversion of chan_mgcp.c to the ast_format api

Modified:
    team/dvossel/fixtheworld_phase1_step3/channels/chan_mgcp.c

Modified: team/dvossel/fixtheworld_phase1_step3/channels/chan_mgcp.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/channels/chan_mgcp.c?view=diff&rev=302598&r1=302597&r2=302598
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/channels/chan_mgcp.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/channels/chan_mgcp.c Wed Jan 19 14:10:20 2011
@@ -222,7 +222,7 @@
 
 static int restart_monitor(void);
 
-static format_t capability = AST_FORMAT_ULAW;
+static struct ast_format_cap *global_capability;
 static int nonCodecCapability = AST_RTP_DTMF;
 
 static char ourhost[MAXHOSTNAMELEN];
@@ -361,7 +361,7 @@
 	int iseq; /*!< Not used? */
 	int lastout; /*!< tracking this on the subchannels.  Is it needed here? */
 	int needdestroy; /*!< Not used? */
-	format_t capability;
+	struct ast_format_cap *cap;
 	int nonCodecCapability;
 	int onhooktime;
 	int msgstate; /*!< voicemail message state */
@@ -429,7 +429,7 @@
 static int transmit_modify_request(struct mgcp_subchannel *sub);
 static int transmit_connect(struct mgcp_subchannel *sub);
 static int transmit_notify_request_with_callerid(struct mgcp_subchannel *sub, char *tone, char *callernum, char *callername);
-static int transmit_modify_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp_instance *rtp, format_t codecs);
+static int transmit_modify_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp_instance *rtp, const struct ast_format_cap *codecs);
 static int transmit_connection_del(struct mgcp_subchannel *sub);
 static int transmit_audit_endpoint(struct mgcp_endpoint *p);
 static void start_rtp(struct mgcp_subchannel *sub);
@@ -439,7 +439,7 @@
 static char *mgcp_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 static int reload_config(int reload);
 
-static struct ast_channel *mgcp_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause);
+static struct ast_channel *mgcp_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause);
 static int mgcp_call(struct ast_channel *ast, char *dest, int timeout);
 static int mgcp_hangup(struct ast_channel *ast);
 static int mgcp_answer(struct ast_channel *ast);
@@ -458,10 +458,9 @@
 static struct ast_variable *add_var(const char *buf, struct ast_variable *list);
 static struct ast_variable *copy_vars(struct ast_variable *src);
 
-static const struct ast_channel_tech mgcp_tech = {
+static struct ast_channel_tech mgcp_tech = {
 	.type = "MGCP",
 	.description = tdesc,
-	.capabilities = AST_FORMAT_ULAW | AST_FORMAT_ALAW,
 	.properties = AST_CHAN_TP_WANTSJITTER | AST_CHAN_TP_CREATESJITTER,
 	.requester = mgcp_request,
 	.devicestate = mgcp_devicestate,
@@ -1208,11 +1207,12 @@
 	if (sub->owner) {
 		/* We already hold the channel lock */
 		if (f->frametype == AST_FRAME_VOICE) {
-			if (f->subclass.codec != sub->owner->nativeformats) {
-				ast_debug(1, "Oooh, format changed to %s\n", ast_getformatname(f->subclass.codec));
-				sub->owner->nativeformats = f->subclass.codec;
-				ast_set_read_format(sub->owner, sub->owner->readformat);
-				ast_set_write_format(sub->owner, sub->owner->writeformat);
+			if (!ast_format_cap_iscompatible(sub->owner->nativeformats, &f->subclass.format)) {
+				ast_debug(1, "Oooh, format changed to %s\n", ast_getformatname(&f->subclass.format));
+				ast_format_cap_remove_all(sub->owner->nativeformats);
+				ast_format_cap_add(sub->owner->nativeformats, &f->subclass.format);
+				ast_set_read_format(sub->owner, &sub->owner->readformat);
+				ast_set_write_format(sub->owner, &sub->owner->writeformat);
 			}
 			/* Courtesy fearnor aka alex at pilosoft.com */
 			if ((sub->parent->dtmfmode & MGCP_DTMF_INBAND) && (sub->parent->dsp)) {
@@ -1251,12 +1251,12 @@
 			return 0;
 		}
 	} else {
-		if (!(frame->subclass.codec & ast->nativeformats)) {
+		if (!(ast_format_cap_iscompatible(ast->nativeformats, &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.codec),
+				ast_getformatname(&frame->subclass.format),
 				ast_getformatname_multiple(buf, sizeof(buf), ast->nativeformats),
-				ast_getformatname(ast->readformat),
-				ast_getformatname(ast->writeformat));
+				ast_getformatname(&ast->readformat),
+				ast_getformatname(&ast->writeformat));
 			/* return -1; */
 		}
 	}
@@ -1489,16 +1489,15 @@
 	struct ast_channel *tmp;
 	struct ast_variable *v = NULL;
 	struct mgcp_endpoint *i = sub->parent;
-	int fmt;
+	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) {
 		tmp->tech = &mgcp_tech;
-		tmp->nativeformats = i->capability;
-		if (!tmp->nativeformats) {
-			tmp->nativeformats = capability;
-		}
-		fmt = ast_best_codec(tmp->nativeformats);
+		ast_format_cap_copy2(tmp->nativeformats, i->cap);
+		if (ast_format_cap_is_empty(tmp->nativeformats)) {
+			ast_format_cap_copy2(tmp->nativeformats, global_capability);
+		}
 		if (sub->rtp) {
 			ast_channel_set_fd(tmp, 0, ast_rtp_instance_fd(sub->rtp, 0));
 		}
@@ -1512,10 +1511,12 @@
 		}
 		if (state == AST_STATE_RING)
 			tmp->rings = 1;
-		tmp->writeformat = fmt;
-		tmp->rawwriteformat = fmt;
-		tmp->readformat = fmt;
-		tmp->rawreadformat = fmt;
+
+		ast_best_codec(tmp->nativeformats, &tmpfmt);
+		ast_format_copy(&tmp->writeformat, &tmpfmt);
+		ast_format_copy(&tmp->rawwriteformat, &tmpfmt);
+		ast_format_copy(&tmp->readformat, &tmpfmt);
+		ast_format_copy(&tmp->rawreadformat, &tmpfmt);
 		tmp->tech_pvt = sub;
 		if (!ast_strlen_zero(i->language))
 			ast_string_field_set(tmp, language, i->language);
@@ -1954,7 +1955,7 @@
 	char host[258];
 	int len;
 	int portno;
-	format_t peercapability;
+	struct ast_format_cap *peercap;
 	int peerNonCodecCapability;
 	struct sockaddr_in sin;
 	struct ast_sockaddr sin_tmp;
@@ -2020,15 +2021,20 @@
 	}
 
 	/* Now gather all of the codecs that were asked for: */
-	ast_rtp_codecs_payload_formats(ast_rtp_instance_get_codecs(sub->rtp), &peercapability, &peerNonCodecCapability);
-	p->capability = capability & peercapability;
+	if (!(peercap = ast_format_cap_alloc_nolock())) {
+		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_debug(1, "Capabilities: us - %s, them - %s, combined - %s\n",
-		ast_getformatname_multiple(tmp1, sizeof(tmp1), capability),
-		ast_getformatname_multiple(tmp2, sizeof(tmp2), peercapability),
-		ast_getformatname_multiple(tmp3, sizeof(tmp3), p->capability));
+		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);
+
 	ast_debug(1, "Non-codec capabilities: us - %d, them - %d, combined - %d\n",
 		nonCodecCapability, peerNonCodecCapability, p->nonCodecCapability);
-	if (!p->capability) {
+	if (ast_format_cap_is_empty(p->cap)) {
 		ast_log(LOG_WARNING, "No compatible codecs!\n");
 		return -1;
 	}
@@ -2181,7 +2187,8 @@
 	char t[256];
 	char m[256] = "";
 	char a[1024] = "";
-	format_t x;
+	int x;
+	struct ast_format tmpfmt;
 	struct sockaddr_in dest = { 0, };
 	struct ast_sockaddr dest_tmp;
 	struct mgcp_endpoint *p = sub->parent;
@@ -2215,30 +2222,35 @@
 	snprintf(c, sizeof(c), "c=IN IP4 %s\r\n", ast_inet_ntoa(dest.sin_addr));
 	ast_copy_string(t, "t=0 0\r\n", sizeof(t));
 	snprintf(m, sizeof(m), "m=audio %d RTP/AVP", ntohs(dest.sin_port));
-	for (x = 1LL; x <= AST_FORMAT_AUDIO_MASK; x <<= 1) {
-		if (!(x & AST_FORMAT_AUDIO_MASK)) {
+
+	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 */
 			continue;
 		}
-		if (p->capability & x) {
-			ast_debug(1, "Answering with capability %s\n", ast_getformatname(x));
-			codec = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(sub->rtp), 1, x);
+		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, x, 0));
+				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);
+
 	for (x = 1LL; x <= AST_RTP_MAX; x <<= 1) {
 		if (p->nonCodecCapability & x) {
 			ast_debug(1, "Answering with non-codec capability %d\n", (int) x);
-			codec = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(sub->rtp), 0, x);
+			codec = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(sub->rtp), 0, NULL, x);
 			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(0, x, 0));
+				snprintf(costr, sizeof(costr), "a=rtpmap:%d %s/8000\r\n", codec, ast_rtp_lookup_mime_subtype2(0, NULL, x, 0));
 				strncat(a, costr, sizeof(a) - strlen(a) - 1);
 				if (x == AST_RTP_DTMF) {
 					/* Indicate we support DTMF...  Not sure about 16,
@@ -2262,13 +2274,13 @@
 	return 0;
 }
 
-static int transmit_modify_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp_instance *rtp, format_t codecs)
+static int transmit_modify_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp_instance *rtp, const struct ast_format_cap *codecs)
 {
 	struct mgcp_request resp;
 	char local[256];
 	char tmp[80];
 	struct mgcp_endpoint *p = sub->parent;
-	format_t x;
+	struct ast_format tmpfmt;
 	struct ast_sockaddr sub_tmpdest_tmp;
 
 	if (ast_strlen_zero(sub->cxident) && rtp) {
@@ -2279,16 +2291,18 @@
 		return 0;
 	}
 	ast_copy_string(local, "e:on, s:off, p:20", sizeof(local));
-	for (x = 1; x <= AST_FORMAT_AUDIO_MASK; x <<= 1) {
-		if (!(x & AST_FORMAT_AUDIO_MASK)) {
-			/* No longer contiguous */
+	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 */
 			continue;
 		}
-		if (p->capability & x) {
-			snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype2(1, x, 0));
+		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);
 
 	if (sub->gate) {
 		if (sub->gate->state == GATE_ALLOCATED || sub->gate->state == GATE_OPEN) {
@@ -2324,7 +2338,7 @@
 	struct mgcp_request resp;
 	char local[256];
 	char tmp[80];
-	int x;
+	struct ast_format tmpfmt;
 	struct mgcp_endpoint *p = sub->parent;
 
 	ast_debug(3, "Creating connection for %s@%s-%d in cxmode: %s callid: %s\n",
@@ -2332,16 +2346,18 @@
 
 	ast_copy_string(local, "e:on, s:off, p:20", sizeof(local));
 
-	for (x = 1; x <= AST_FORMAT_AUDIO_MASK; x <<= 1) {
-		if (!(x & AST_FORMAT_AUDIO_MASK)) {
-			/* No longer contiguous */
+	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 */
 			continue;
 		}
-		if (p->capability & x) {
-			snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype2(1, x, 0));
+		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);
 
 	if (sub->gate) {
 		if(sub->gate->state == GATE_ALLOCATED) {
@@ -2419,17 +2435,19 @@
 	struct mgcp_request resp;
 	char local[256];
 	char tmp[80];
-	format_t x;
+	struct ast_format tmpfmt;
 	struct mgcp_endpoint *p = sub->parent;
 
 	ast_copy_string(local, "p:20, s:off, e:on", sizeof(local));
 
-	for (x = 1LL; x <= AST_FORMAT_AUDIO_MASK; x <<= 1) {
-		if (p->capability & x) {
-			snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype2(1, x, 0));
+	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);
 
 	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);
@@ -2522,7 +2540,7 @@
 {
 	struct mgcp_request resp;
 	struct mgcp_endpoint *p = sub->parent;
-	format_t x;
+	struct ast_format tmpfmt;
 	int fc = 1;
 	char local[256];
 	char tmp[80];
@@ -2536,18 +2554,19 @@
 		p->name, p->parent->name, sub->id, mgcp_cxmodes[sub->cxmode], sub->callid);
 
 	ast_copy_string(local, "", sizeof(local));
-	for (x = 1; x <= AST_FORMAT_AUDIO_MASK; x <<= 1) {
-		if (p->capability & x) {
-			if (p->ncs && !fc) {
-				p->capability = x; /* sb5120e bug */
-				break;
-			} else {
-				fc = 0;
-				snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype2(1, x, 0));
-			}
-			strncat(local, tmp, sizeof(local) - strlen(local) - 1);
-		}
-	}
+	ast_format_cap_iter_start(p->cap);
+	while (!(ast_format_cap_iter_next(p->cap, &tmpfmt))) {
+		if (p->ncs && !fc) {
+			ast_format_cap_remove_all(p->cap);
+			ast_format_cap_add(p->cap, &tmpfmt); /* sb5120e bug */
+			break;
+		} else {
+			fc = 0;
+			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);
 
 	if (!sub->sdpsent) {
 		if (sub->gate) {
@@ -3899,18 +3918,15 @@
 	return 0;
 }
 
-static struct ast_channel *mgcp_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause)
-{
-	format_t oldformat;
+static struct ast_channel *mgcp_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause)
+{
 	struct mgcp_subchannel *sub;
 	struct ast_channel *tmpc = NULL;
 	char tmp[256];
 	char *dest = data;
 
-	oldformat = format;
-	format &= capability;
-	if (!format) {
-		ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%s'\n", ast_getformatname_multiple(tmp, sizeof(tmp), format));
+	if (!(ast_format_cap_has_joint(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;*/
 	}
 	ast_copy_string(tmp, dest, sizeof(tmp));
@@ -4138,6 +4154,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_nolock();
 					ast_copy_string(e->name, v->value, sizeof(e->name));
 					e->needaudit = 1;
 				}
@@ -4167,7 +4184,7 @@
 				snprintf(e->rqnt_ident, sizeof(e->rqnt_ident), "%08lx", ast_random());
 				e->msgstate = -1;
 				e->amaflags = amaflags;
-				e->capability = capability;
+				ast_format_cap_copy2(e->cap, global_capability);
 				e->parent = gw;
 				e->ncs = ncs;
 				e->dtmfmode = dtmfmode;
@@ -4249,6 +4266,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_nolock();
 					ast_copy_string(e->name, v->value, sizeof(e->name));
 					e->needaudit = 1;
 				}
@@ -4270,7 +4288,7 @@
 					e->parent = gw;
 				}
 				e->amaflags = amaflags;
-				e->capability = capability;
+				ast_format_cap_copy2(e->cap, global_capability);
 				e->dtmfmode = dtmfmode;
 				e->ncs = ncs;
 				e->pktcgatealloc = pktcgatealloc;
@@ -4410,23 +4428,23 @@
 		return AST_RTP_GLUE_RESULT_LOCAL;
 }
 
-static int mgcp_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp, struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, format_t codecs, int nat_active)
+static int mgcp_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp, struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, const struct ast_format_cap *cap, int nat_active)
 {
 	/* XXX Is there such thing as video support with MGCP? XXX */
 	struct mgcp_subchannel *sub;
 	sub = chan->tech_pvt;
 	if (sub && !sub->alreadygone) {
-		transmit_modify_with_sdp(sub, rtp, codecs);
+		transmit_modify_with_sdp(sub, rtp, cap);
 		return 0;
 	}
 	return -1;
 }
 
-static format_t mgcp_get_codec(struct ast_channel *chan)
+static void mgcp_get_codec(struct ast_channel *chan, struct ast_format_cap *result)
 {
 	struct mgcp_subchannel *sub = chan->tech_pvt;
 	struct mgcp_endpoint *p = sub->parent;
-	return p->capability;
+	ast_format_cap_copy2(result, p->cap);
 }
 
 static struct ast_rtp_glue mgcp_rtp_glue = {
@@ -4511,6 +4529,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);
 	ast_free(e);
 }
 
@@ -4608,7 +4627,7 @@
 	char *cat;
 	struct ast_hostent ahp;
 	struct hostent *hp;
-	int format;
+	struct ast_format format;
 	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 	
 	if (gethostname(ourhost, sizeof(ourhost)-1)) {
@@ -4648,18 +4667,18 @@
 				memcpy(&bindaddr.sin_addr, hp->h_addr, sizeof(bindaddr.sin_addr));
 			}
 		} else if (!strcasecmp(v->name, "allow")) {
-			format = ast_getformatbyname(v->value);
-			if (format < 1) {
+			ast_getformatbyname(v->value, &format);
+			if (!format.id) {
 				ast_log(LOG_WARNING, "Cannot allow unknown format '%s'\n", v->value);
 			} else {
-				capability |= format;
+				ast_format_cap_add(global_capability, &format);
 			}
 		} else if (!strcasecmp(v->name, "disallow")) {
-			format = ast_getformatbyname(v->value);
-			if (format < 1) {
-				ast_log(LOG_WARNING, "Cannot disallow unknown format '%s'\n", v->value);
+			ast_getformatbyname(v->value, &format);
+			if (!format.id) {
+				ast_log(LOG_WARNING, "Cannot allow unknown format '%s'\n", v->value);
 			} else {
-				capability &= ~format;
+				ast_format_cap_remove(global_capability, &format);
 			}
 		} else if (!strcasecmp(v->name, "tos")) {
 			if (ast_str2tos(v->value, &qos.tos)) {
@@ -4776,6 +4795,17 @@
 /*! \brief  load_module: PBX load module - initialization ---*/
 static int load_module(void)
 {
+	struct ast_format tmpfmt;
+
+	if (!(global_capability = ast_format_cap_alloc())) {
+		return AST_MODULE_LOAD_FAILURE;
+	}
+	if (!(mgcp_tech.capabilities = ast_format_cap_alloc())) {
+		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));
 	if (!(sched = ast_sched_context_create())) {
 		ast_log(LOG_WARNING, "Unable to create schedule context\n");
 		return AST_MODULE_LOAD_FAILURE;
@@ -4907,6 +4937,9 @@
 	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);
+
 	return 0;
 }
 




More information about the svn-commits mailing list