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

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


Author: file
Date: Sun Mar 30 07:15:09 2014
New Revision: 411575

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

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

Modified:
    team/group/media_formats-reviewed/channels/chan_dahdi.c
    team/group/media_formats-reviewed/channels/dahdi/bridge_native_dahdi.c

Modified: team/group/media_formats-reviewed/channels/chan_dahdi.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/channels/chan_dahdi.c?view=diff&rev=411575&r1=411574&r2=411575
==============================================================================
--- team/group/media_formats-reviewed/channels/chan_dahdi.c (original)
+++ team/group/media_formats-reviewed/channels/chan_dahdi.c Sun Mar 30 07:15:09 2014
@@ -127,6 +127,7 @@
 #include "asterisk/bridge.h"
 #include "asterisk/stasis_channels.h"
 #include "asterisk/parking.h"
+#include "asterisk/format_cache.h"
 #include "chan_dahdi.h"
 #include "dahdi/bridge_native_dahdi.h"
 
@@ -414,7 +415,7 @@
 /*! \brief Typically, how many rings before we should send Caller*ID */
 #define DEFAULT_CIDRINGS 1
 
-#define AST_LAW(p) (((p)->law == DAHDI_LAW_ALAW) ? AST_FORMAT_ALAW : AST_FORMAT_ULAW)
+#define AST_LAW(p) (((p)->law == DAHDI_LAW_ALAW) ? ast_format_alaw : ast_format_ulaw)
 
 
 /*! \brief Signaling types that need to use MF detection should be placed in this macro */
@@ -1198,7 +1199,6 @@
 	int res;
 	unsigned char buf[256];
 	int flags;
-	struct ast_format tmpfmt;
 
 	poller.fd = p->subs[SUB_REAL].dfd;
 	poller.events = POLLPRI | POLLIN;
@@ -1231,9 +1231,9 @@
 		}
 
 		if (p->cid_signalling == CID_SIG_V23_JP) {
-			res = callerid_feed_jp(p->cs, buf, res, ast_format_set(&tmpfmt, AST_LAW(p), 0));
+			res = callerid_feed_jp(p->cs, buf, res, AST_LAW(p));
 		} else {
-			res = callerid_feed(p->cs, buf, res, ast_format_set(&tmpfmt, AST_LAW(p), 0));
+			res = callerid_feed(p->cs, buf, res, AST_LAW(p));
 		}
 		if (res < 0) {
 			/*
@@ -1402,7 +1402,7 @@
 static int my_callwait(void *pvt)
 {
 	struct dahdi_pvt *p = pvt;
-	struct ast_format tmpfmt;
+
 	p->callwaitingrepeat = CALLWAITING_REPEAT_SAMPLES;
 	if (p->cidspill) {
 		ast_log(LOG_WARNING, "Spill already exists?!?\n");
@@ -1419,11 +1419,11 @@
 	/* Silence */
 	memset(p->cidspill, 0x7f, 2400 + 600 + READ_SIZE * 4);
 	if (!p->callwaitrings && p->callwaitingcallerid) {
-		ast_gen_cas(p->cidspill, 1, 2400 + 680, ast_format_set(&tmpfmt, AST_LAW(p), 0));
+		ast_gen_cas(p->cidspill, 1, 2400 + 680, AST_LAW(p));
 		p->callwaitcas = 1;
 		p->cidlen = 2400 + 680 + READ_SIZE * 4;
 	} else {
-		ast_gen_cas(p->cidspill, 1, 2400, ast_format_set(&tmpfmt, AST_LAW(p), 0));
+		ast_gen_cas(p->cidspill, 1, 2400, AST_LAW(p));
 		p->callwaitcas = 0;
 		p->cidlen = 2400 + READ_SIZE * 4;
 	}
@@ -1436,7 +1436,6 @@
 static int my_send_callerid(void *pvt, int cwcid, struct ast_party_caller *caller)
 {
 	struct dahdi_pvt *p = pvt;
-	struct ast_format tmpfmt;
 
 	ast_debug(2, "Starting cid spill\n");
 
@@ -1450,7 +1449,7 @@
 			p->cidlen = ast_callerid_generate(p->cidspill,
 				caller->id.name.str,
 				caller->id.number.str,
-				ast_format_set(&tmpfmt, AST_LAW(p), 0));
+				AST_LAW(p));
 		} else {
 			ast_verb(3, "CPE supports Call Waiting Caller*ID.  Sending '%s/%s'\n",
 				caller->id.name.str, caller->id.number.str);
@@ -1459,7 +1458,7 @@
 			p->cidlen = ast_callerid_callwaiting_generate(p->cidspill,
 				caller->id.name.str,
 				caller->id.number.str,
-				ast_format_set(&tmpfmt, AST_LAW(p), 0));
+				AST_LAW(p));
 			p->cidlen += READ_SIZE * 4;
 		}
 		p->cidpos = 0;
@@ -4803,14 +4802,12 @@
 
 static int send_cwcidspill(struct dahdi_pvt *p)
 {
-	struct ast_format tmpfmt;
-
 	p->callwaitcas = 0;
 	p->cidcwexpire = 0;
 	p->cid_suppress_expire = 0;
 	if (!(p->cidspill = ast_malloc(MAX_CALLERID_SIZE)))
 		return -1;
-	p->cidlen = ast_callerid_callwaiting_generate(p->cidspill, p->callwait_name, p->callwait_num, ast_format_set(&tmpfmt, AST_LAW(p), 0));
+	p->cidlen = ast_callerid_callwaiting_generate(p->cidspill, p->callwait_name, p->callwait_num, AST_LAW(p));
 	/* Make sure we account for the end */
 	p->cidlen += READ_SIZE * 4;
 	p->cidpos = 0;
@@ -4876,7 +4873,7 @@
 static int dahdi_callwait(struct ast_channel *ast)
 {
 	struct dahdi_pvt *p = ast_channel_tech_pvt(ast);
-	struct ast_format tmpfmt;
+
 	p->callwaitingrepeat = CALLWAITING_REPEAT_SAMPLES;
 	if (p->cidspill) {
 		ast_log(LOG_WARNING, "Spill already exists?!?\n");
@@ -4893,11 +4890,11 @@
 	/* Silence */
 	memset(p->cidspill, 0x7f, 2400 + 600 + READ_SIZE * 4);
 	if (!p->callwaitrings && p->callwaitingcallerid) {
-		ast_gen_cas(p->cidspill, 1, 2400 + 680, ast_format_set(&tmpfmt, AST_LAW(p), 0));
+		ast_gen_cas(p->cidspill, 1, 2400 + 680, AST_LAW(p));
 		p->callwaitcas = 1;
 		p->cidlen = 2400 + 680 + READ_SIZE * 4;
 	} else {
-		ast_gen_cas(p->cidspill, 1, 2400, ast_format_set(&tmpfmt, AST_LAW(p), 0));
+		ast_gen_cas(p->cidspill, 1, 2400, AST_LAW(p));
 		p->callwaitcas = 0;
 		p->cidlen = 2400 + READ_SIZE * 4;
 	}
@@ -8342,25 +8339,20 @@
 		return f;
 	}
 
-	if (ast_channel_rawreadformat(ast)->id == AST_FORMAT_SLINEAR) {
+	if (ast_format_cmp(ast_channel_rawreadformat(ast), ast_format_slin) == AST_FORMAT_CMP_EQUAL) {
 		if (!p->subs[idx].linear) {
 			p->subs[idx].linear = 1;
 			res = dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear);
 			if (res)
 				ast_log(LOG_WARNING, "Unable to set channel %d (index %d) to linear mode.\n", p->channel, idx);
 		}
-	} else if ((ast_channel_rawreadformat(ast)->id == AST_FORMAT_ULAW) ||
-		(ast_channel_rawreadformat(ast)->id == AST_FORMAT_ALAW)) {
+	} else {
 		if (p->subs[idx].linear) {
 			p->subs[idx].linear = 0;
 			res = dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear);
 			if (res)
 				ast_log(LOG_WARNING, "Unable to set channel %d (index %d) to companded mode.\n", p->channel, idx);
 		}
-	} else {
-		ast_log(LOG_WARNING, "Don't know how to read frames in format %s\n", ast_getformatname(ast_channel_rawreadformat(ast)));
-		ast_mutex_unlock(&p->lock);
-		return NULL;
 	}
 	readbuf = ((unsigned char *)p->subs[idx].buffer) + AST_FRIENDLY_OFFSET;
 	CHECK_BLOCKING(ast);
@@ -8450,7 +8442,7 @@
 	}
 
 	p->subs[idx].f.frametype = AST_FRAME_VOICE;
-	ast_format_copy(&p->subs[idx].f.subclass.format, ast_channel_rawreadformat(ast));
+	p->subs[idx].f.subclass.format = ast_format_copy(ast_channel_rawreadformat(ast));
 	p->subs[idx].f.samples = READ_SIZE;
 	p->subs[idx].f.mallocd = 0;
 	p->subs[idx].f.offset = AST_FRIENDLY_OFFSET;
@@ -8627,18 +8619,6 @@
 		return -1;
 	}
 
-	/* Write a frame of (presumably voice) data */
-	if (frame->frametype != AST_FRAME_VOICE) {
-		if (frame->frametype != AST_FRAME_IMAGE)
-			ast_log(LOG_WARNING, "Don't know what to do with frame type '%d'\n", frame->frametype);
-		return 0;
-	}
-	if ((frame->subclass.format.id != AST_FORMAT_SLINEAR) &&
-		(frame->subclass.format.id != AST_FORMAT_ULAW) &&
-		(frame->subclass.format.id != AST_FORMAT_ALAW)) {
-		ast_log(LOG_WARNING, "Cannot handle frames in %s format\n", ast_getformatname(&frame->subclass.format));
-		return -1;
-	}
 	if (p->dialing) {
 		ast_debug(5, "Dropping frame since I'm still dialing on %s...\n",ast_channel_name(ast));
 		return 0;
@@ -8656,7 +8636,7 @@
 	if (!frame->data.ptr || !frame->datalen)
 		return 0;
 
-	if (frame->subclass.format.id == AST_FORMAT_SLINEAR) {
+	if (ast_format_cmp(frame->subclass.format, ast_format_slin) == AST_FORMAT_CMP_EQUAL) {
 		if (!p->subs[idx].linear) {
 			p->subs[idx].linear = 1;
 			res = dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear);
@@ -8862,7 +8842,8 @@
 static struct ast_channel *dahdi_new(struct dahdi_pvt *i, int state, int startpbx, int idx, int law, const char *linkedid, struct ast_callid *callid)
 {
 	struct ast_channel *tmp;
-	struct ast_format deflaw;
+	struct ast_format_cap *caps;
+	struct ast_format *deflaw;
 	int x;
 	int features;
 	struct ast_str *chan_name;
@@ -8875,7 +8856,6 @@
 		return NULL;
 	}
 
-	ast_format_clear(&deflaw);
 #if defined(HAVE_PRI)
 	/*
 	 * The dnid has been stuffed with the called-number[:subaddress]
@@ -8889,9 +8869,16 @@
 		return NULL;
 	}
 
+	caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	if (!caps) {
+		ast_free(chan_name);
+		return NULL;
+	}
+
 	tmp = ast_channel_alloc(0, state, i->cid_num, i->cid_name, i->accountcode, i->exten, i->context, linkedid, i->amaflags, "DAHDI/%s", ast_str_buffer(chan_name));
 	ast_free(chan_name);
 	if (!tmp) {
+		ao2_ref(caps, -1);
 		return NULL;
 	}
 
@@ -8911,9 +8898,9 @@
 	if (law) {
 		i->law = law;
 		if (law == DAHDI_LAW_ALAW) {
-			ast_format_set(&deflaw, AST_FORMAT_ALAW, 0);
+			deflaw = ast_format_alaw;
 		} else {
-			ast_format_set(&deflaw, AST_FORMAT_ULAW, 0);
+			deflaw = ast_format_ulaw;
 		}
 	} else {
 		switch (i->sig) {
@@ -8927,18 +8914,20 @@
 			break;
 		}
 		if (i->law_default == DAHDI_LAW_ALAW) {
-			ast_format_set(&deflaw, AST_FORMAT_ALAW, 0);
+			deflaw = ast_format_alaw;
 		} else {
-			ast_format_set(&deflaw, AST_FORMAT_ULAW, 0);
+			deflaw = ast_format_ulaw;
 		}
 	}
 	ast_channel_set_fd(tmp, 0, i->subs[idx].dfd);
-	ast_format_cap_add(ast_channel_nativeformats(tmp), &deflaw);
+	ast_format_cap_add(caps, deflaw, 0);
+	ast_channel_nativeformats_set(tmp, caps);
+	ao2_ref(caps, -1);
 	/* Start out assuming ulaw since it's smaller :) */
-	ast_format_copy(ast_channel_rawreadformat(tmp), &deflaw);
-	ast_format_copy(ast_channel_readformat(tmp), &deflaw);
-	ast_format_copy(ast_channel_rawwriteformat(tmp), &deflaw);
-	ast_format_copy(ast_channel_writeformat(tmp), &deflaw);
+	ast_channel_set_rawreadformat(tmp, deflaw);
+	ast_channel_set_readformat(tmp, deflaw);
+	ast_channel_set_rawwriteformat(tmp, deflaw);
+	ast_channel_set_writeformat(tmp, deflaw);
 	i->subs[idx].linear = 0;
 	dahdi_setlinear(i->subs[idx].dfd, i->subs[idx].linear);
 	features = 0;
@@ -9235,7 +9224,6 @@
 	int len = 0;
 	int res;
 	int idx;
-	struct ast_format tmpfmt;
 	RAII_VAR(struct ast_features_pickup_config *, pickup_cfg, NULL, ao2_cleanup);
 	const char *pickupexten;
 
@@ -9952,9 +9940,9 @@
 							samples += res;
 
 							if (p->cid_signalling == CID_SIG_V23_JP) {
-								res = callerid_feed_jp(cs, buf, res, ast_format_set(&tmpfmt, AST_LAW(p), 0));
+								res = callerid_feed_jp(cs, buf, res, AST_LAW(p));
 							} else {
-								res = callerid_feed(cs, buf, res, ast_format_set(&tmpfmt, AST_LAW(p), 0));
+								res = callerid_feed(cs, buf, res, AST_LAW(p));
 							}
 							if (res < 0) {
 								/*
@@ -10237,7 +10225,7 @@
 								}
 							}
 							samples += res;
-							res = callerid_feed(cs, buf, res, ast_format_set(&tmpfmt, AST_LAW(p), 0));
+							res = callerid_feed(cs, buf, res, AST_LAW(p));
 							if (res < 0) {
 								/*
 								 * The previous diagnostic message output likely
@@ -10407,7 +10395,7 @@
 	size_t len;
 };
 
-static int calc_energy(const unsigned char *buf, int len, enum ast_format_id law)
+static int calc_energy(const unsigned char *buf, int len, struct ast_format *law)
 {
 	int x;
 	int sum = 0;
@@ -10416,7 +10404,7 @@
 		return 0;
 
 	for (x = 0; x < len; x++)
-		sum += abs(law == AST_FORMAT_ULAW ? AST_MULAW(buf[x]) : AST_ALAW(buf[x]));
+		sum += abs(law == ast_format_ulaw ? AST_MULAW(buf[x]) : AST_ALAW(buf[x]));
 
 	return sum / len;
 }
@@ -10432,13 +10420,12 @@
 	int i, res;
 	unsigned int spill_done = 0;
 	int spill_result = -1;
-	struct ast_format tmpfmt;
 
 	if (!(cs = callerid_new(mtd->pvt->cid_signalling))) {
 		goto quit_no_clean;
 	}
 
-	callerid_feed(cs, mtd->buf, mtd->len, ast_format_set(&tmpfmt, AST_LAW(mtd->pvt), 0));
+	callerid_feed(cs, mtd->buf, mtd->len, AST_LAW(mtd->pvt));
 
 	bump_gains(mtd->pvt);
 
@@ -10524,7 +10511,7 @@
 			}
 			samples += res;
 			if (!spill_done) {
-				if ((spill_result = callerid_feed(cs, mtd->buf, res, ast_format_set(&tmpfmt, AST_LAW(mtd->pvt), 0))) < 0) {
+				if ((spill_result = callerid_feed(cs, mtd->buf, res, AST_LAW(mtd->pvt))) < 0) {
 					/*
 					 * The previous diagnostic message output likely
 					 * explains why it failed.
@@ -10582,7 +10569,6 @@
 static int mwi_send_init(struct dahdi_pvt * pvt)
 {
 	int x;
-	struct ast_format tmpfmt;
 
 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
 	/* Determine how this spill is to be sent */
@@ -10625,7 +10611,7 @@
 	if (pvt->mwisend_fsk) {
 #endif
 		pvt->cidlen = ast_callerid_vmwi_generate(pvt->cidspill, has_voicemail(pvt), CID_MWI_TYPE_MDMF_FULL,
-							 ast_format_set(&tmpfmt, AST_LAW(pvt), 0), pvt->cid_name, pvt->cid_num, 0);
+							 AST_LAW(pvt), pvt->cid_name, pvt->cid_num, 0);
 		pvt->cidpos = 0;
 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
 	}
@@ -16543,7 +16529,8 @@
 
 	dahdi_native_unload();
 
-	dahdi_tech.capabilities = ast_format_cap_destroy(dahdi_tech.capabilities);
+	ao2_ref(dahdi_tech.capabilities, -1);
+	dahdi_tech.capabilities = NULL;
 	STASIS_MESSAGE_TYPE_CLEANUP(dahdichannel_type);
 	return 0;
 }
@@ -18559,7 +18546,6 @@
 static int load_module(void)
 {
 	int res;
-	struct ast_format tmpfmt;
 #if defined(HAVE_PRI) || defined(HAVE_SS7)
 	int y;
 #endif	/* defined(HAVE_PRI) || defined(HAVE_SS7) */
@@ -18568,12 +18554,12 @@
 		return AST_MODULE_LOAD_FAILURE;
 	}
 
-	if (!(dahdi_tech.capabilities = ast_format_cap_alloc(0))) {
+	if (!(dahdi_tech.capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
 		return AST_MODULE_LOAD_FAILURE;
 	}
-	ast_format_cap_add(dahdi_tech.capabilities, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
-	ast_format_cap_add(dahdi_tech.capabilities, ast_format_set(&tmpfmt, AST_FORMAT_ULAW, 0));
-	ast_format_cap_add(dahdi_tech.capabilities, ast_format_set(&tmpfmt, AST_FORMAT_ALAW, 0));
+	ast_format_cap_add(dahdi_tech.capabilities, ast_format_slin, 0);
+	ast_format_cap_add(dahdi_tech.capabilities, ast_format_ulaw, 0);
+	ast_format_cap_add(dahdi_tech.capabilities, ast_format_alaw, 0);
 
 	if (dahdi_native_load(ast_module_info->self, &dahdi_tech)) {
 		return AST_MODULE_LOAD_FAILURE;
@@ -18709,10 +18695,9 @@
 		return -1;
 	mybuf = buf;
 	if (p->mate) {
-		struct ast_format tmp;
 		/* PUT_CLI_MARKMS is a macro and requires a format ptr called codec to be present */
-		struct ast_format *codec = &tmp;
-		ast_format_set(codec, AST_LAW(p), 0);
+		struct ast_format *codec = AST_LAW(p);
+
 		for (x = 0; x < HEADER_MS; x++) {	/* 50 ms of Mark */
 			PUT_CLID_MARKMS;
 		}

Modified: team/group/media_formats-reviewed/channels/dahdi/bridge_native_dahdi.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/channels/dahdi/bridge_native_dahdi.c?view=diff&rev=411575&r1=411574&r2=411575
==============================================================================
--- team/group/media_formats-reviewed/channels/dahdi/bridge_native_dahdi.c (original)
+++ team/group/media_formats-reviewed/channels/dahdi/bridge_native_dahdi.c Sun Mar 30 07:15:09 2014
@@ -45,6 +45,7 @@
 #include "asterisk/bridge.h"
 #include "asterisk/bridge_technology.h"
 #include "asterisk/frame.h"
+#include "asterisk/format_cache.h"
 
 /* ------------------------------------------------------------------- */
 
@@ -893,7 +894,7 @@
 void dahdi_native_unload(void)
 {
 	ast_bridge_technology_unregister(&native_bridge);
-	ast_format_cap_destroy(native_bridge.format_capabilities);
+	ao2_cleanup(native_bridge.format_capabilities);
 }
 
 /*!
@@ -906,11 +907,9 @@
  */
 int dahdi_native_load(struct ast_module *mod, const struct ast_channel_tech *tech)
 {
-	struct ast_format format;
-
 	dahdi_tech = tech;
 
-	native_bridge.format_capabilities = ast_format_cap_alloc(0);
+	native_bridge.format_capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
 	if (!native_bridge.format_capabilities) {
 		return -1;
 	}
@@ -919,9 +918,9 @@
 	 * This is used to make channels compatible with the bridge
 	 * itself not with each other.
 	 */
-	ast_format_cap_add(native_bridge.format_capabilities, ast_format_set(&format, AST_FORMAT_SLINEAR, 0));
-	ast_format_cap_add(native_bridge.format_capabilities, ast_format_set(&format, AST_FORMAT_ULAW, 0));
-	ast_format_cap_add(native_bridge.format_capabilities, ast_format_set(&format, AST_FORMAT_ALAW, 0));
+	ast_format_cap_add(native_bridge.format_capabilities, ast_format_slin, 0);
+	ast_format_cap_add(native_bridge.format_capabilities, ast_format_ulaw, 0);
+	ast_format_cap_add(native_bridge.format_capabilities, ast_format_alaw, 0);
 
 	return __ast_bridge_technology_register(&native_bridge, mod);
 }




More information about the svn-commits mailing list