[svn-commits] dvossel: branch dvossel/fixtheworld_phase1_step3 r302000 - in /team/dvossel/f...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Jan 14 15:47:09 CST 2011


Author: dvossel
Date: Fri Jan 14 15:47:05 2011
New Revision: 302000

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=302000
Log:
conversion of codec_dahdi

Modified:
    team/dvossel/fixtheworld_phase1_step3/codecs/codec_dahdi.c
    team/dvossel/fixtheworld_phase1_step3/include/asterisk/format.h
    team/dvossel/fixtheworld_phase1_step3/main/format.c
    team/dvossel/fixtheworld_phase1_step3/pbx/pbx_spool.c

Modified: team/dvossel/fixtheworld_phase1_step3/codecs/codec_dahdi.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/codecs/codec_dahdi.c?view=diff&rev=302000&r1=301999&r2=302000
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/codecs/codec_dahdi.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/codecs/codec_dahdi.c Fri Jan 14 15:47:05 2011
@@ -179,7 +179,7 @@
 {
 	struct codec_dahdi_pvt *dahdip = pvt->pvt;
 
-	if (!f->subclass.codec) {
+	if (!f->subclass.format.id) {
 		/* We're just faking a return for calculation purposes. */
 		dahdip->fake = 2;
 		pvt->samples = f->samples;
@@ -227,7 +227,7 @@
 	if (2 == dahdip->fake) {
 		dahdip->fake = 1;
 		pvt->f.frametype = AST_FRAME_VOICE;
-		pvt->f.subclass.codec = 0;
+		ast_format_clear(&pvt->f.subclass.format);
 		pvt->f.samples = dahdip->required_samples;
 		pvt->f.data.ptr = NULL;
 		pvt->f.offset = 0;
@@ -255,7 +255,7 @@
 		pvt->f.datalen = res;
 		pvt->f.samples = dahdip->required_samples;
 		pvt->f.frametype = AST_FRAME_VOICE;
-		pvt->f.subclass.codec = 1 <<  (pvt->t->dstfmt);
+		ast_format_copy(&pvt->f.subclass.format, &pvt->t->dst_format);
 		pvt->f.mallocd = 0;
 		pvt->f.offset = AST_FRIENDLY_OFFSET;
 		pvt->f.src = pvt->t->name;
@@ -274,7 +274,7 @@
 {
 	struct codec_dahdi_pvt *dahdip = pvt->pvt;
 
-	if (!f->subclass.codec) {
+	if (!f->subclass.format.id) {
 		/* We're just faking a return for calculation purposes. */
 		dahdip->fake = 2;
 		pvt->samples = f->samples;
@@ -300,7 +300,7 @@
 	if (2 == dahdip->fake) {
 		dahdip->fake = 1;
 		pvt->f.frametype = AST_FRAME_VOICE;
-		pvt->f.subclass.codec = 0;
+		ast_format_clear(&pvt->f.subclass.format);
 		pvt->f.samples = dahdip->required_samples;
 		pvt->f.data.ptr = NULL;
 		pvt->f.offset = 0;
@@ -338,7 +338,7 @@
 		}
 		pvt->datalen = 0;
 		pvt->f.frametype = AST_FRAME_VOICE;
-		pvt->f.subclass.codec = 1 <<  (pvt->t->dstfmt);
+		ast_format_copy(&pvt->f.subclass.format, &pvt->t->dst_format);
 		pvt->f.mallocd = 0;
 		pvt->f.offset = AST_FRIENDLY_OFFSET;
 		pvt->f.src = pvt->t->name;
@@ -371,7 +371,7 @@
 	close(dahdip->fd);
 }
 
-static int dahdi_translate(struct ast_trans_pvt *pvt, int dest, int source)
+static int dahdi_translate(struct ast_trans_pvt *pvt, struct ast_format *dst_format, struct ast_format *src_format)
 {
 	/* Request translation through zap if possible */
 	int fd;
@@ -385,10 +385,10 @@
 		return -1;
 	}
 
-	dahdip->fmts.srcfmt = (1 << source);
-	dahdip->fmts.dstfmt = (1 << dest);
-
-	ast_debug(1, "Opening transcoder channel from %d to %d.\n", source, dest);
+	dahdip->fmts.srcfmt = ast_format_to_old_bitfield(src_format);
+	dahdip->fmts.dstfmt = ast_format_to_old_bitfield(dst_format);
+
+	ast_debug(1, "Opening transcoder channel from %s to %s.\n", ast_getformatname(src_format), ast_getformatname(dst_format));
 
 retry:
 	if (ioctl(fd, DAHDI_TC_ALLOCATE, &dahdip->fmts)) {
@@ -401,14 +401,14 @@
 			 * support for ULAW instead of signed linear and then
 			 * we'll just convert from ulaw to signed linear in
 			 * software. */
-			if (AST_FORMAT_SLINEAR == dahdip->fmts.srcfmt) {
+			if (AST_FORMAT_SLINEAR == ast_format_id_from_old_bitfield(dahdip->fmts.srcfmt)) {
 				ast_debug(1, "Using soft_slin support on source\n");
 				dahdip->softslin = 1;
-				dahdip->fmts.srcfmt = AST_FORMAT_ULAW;
-			} else if (AST_FORMAT_SLINEAR == dahdip->fmts.dstfmt) {
+				dahdip->fmts.srcfmt = ast_format_id_to_old_bitfield(AST_FORMAT_ULAW);
+			} else if (AST_FORMAT_SLINEAR == ast_format_id_from_old_bitfield(dahdip->fmts.dstfmt)) {
 				ast_debug(1, "Using soft_slin support on destination\n");
 				dahdip->softslin = 1;
-				dahdip->fmts.dstfmt = AST_FORMAT_ULAW;
+				dahdip->fmts.dstfmt = ast_format_id_to_old_bitfield(AST_FORMAT_ULAW);
 			}
 			tried_once = 1;
 			goto retry;
@@ -427,9 +427,9 @@
 
 	dahdip->fd = fd;
 
-	dahdip->required_samples = ((dahdip->fmts.dstfmt|dahdip->fmts.srcfmt)&AST_FORMAT_G723_1) ? G723_SAMPLES : G729_SAMPLES;
-
-	switch (dahdip->fmts.dstfmt) {
+	dahdip->required_samples = ((dahdip->fmts.dstfmt|dahdip->fmts.srcfmt) & (ast_format_id_to_old_bitfield(AST_FORMAT_G723_1))) ? G723_SAMPLES : G729_SAMPLES;
+
+	switch (ast_format_id_from_old_bitfield(dahdip->fmts.dstfmt)) {
 	case AST_FORMAT_G729A:
 		ast_atomic_fetchadd_int(&channels.encoders, +1);
 		break;
@@ -446,7 +446,9 @@
 
 static int dahdi_new(struct ast_trans_pvt *pvt)
 {
-	return dahdi_translate(pvt, pvt->t->dstfmt, pvt->t->srcfmt);
+	return dahdi_translate(pvt,
+		&pvt->t->dst_format,
+		&pvt->t->src_format);
 }
 
 static struct ast_frame *fakesrc_sample(void)
@@ -463,7 +465,9 @@
 
 static int is_encoder(struct translator *zt)
 {
-	if (zt->t.srcfmt&(AST_FORMAT_ULAW|AST_FORMAT_ALAW|AST_FORMAT_SLINEAR)) {
+	if ((zt->t.src_format.id == AST_FORMAT_ULAW) ||
+		(zt->t.src_format.id == AST_FORMAT_ALAW) ||
+		(zt->t.src_format.id == AST_FORMAT_SLINEAR)) {
 		return 1;
 	} else {
 		return 0;
@@ -474,15 +478,20 @@
 {
 	struct translator *zt;
 	int res;
+	struct ast_format dst_format;
+	struct ast_format src_format;
+
+	ast_format_from_old_bitfield(&dst_format, (1 << dst));
+	ast_format_from_old_bitfield(&src_format, (1 << src));
 
 	if (!(zt = ast_calloc(1, sizeof(*zt)))) {
 		return -1;
 	}
 
 	snprintf((char *) (zt->t.name), sizeof(zt->t.name), "zap%sto%s",
-		 ast_getformatname((1 << src)), ast_getformatname((1 << dst)));
-	zt->t.srcfmt = (1 << src);
-	zt->t.dstfmt = (1 << dst);
+		 ast_getformatname(&src_format), ast_getformatname(&dst_format));
+	ast_format_copy(&zt->t.src_format, &src_format);
+	ast_format_copy(&zt->t.dst_format, &dst_format);
 	zt->t.buf_size = BUFFER_SIZE;
 	if (is_encoder(zt)) {
 		zt->t.framein = dahdi_encoder_framein;
@@ -518,10 +527,10 @@
 
 	AST_LIST_LOCK(&translators);
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&translators, cur, entry) {
-		if (cur->t.srcfmt != src)
+		if (cur->t.src_format.id != ast_format_id_from_old_bitfield((1 << src)))
 			continue;
 
-		if (cur->t.dstfmt != dst)
+		if (cur->t.dst_format.id != ast_format_id_from_old_bitfield((1 << dst)))
 			continue;
 
 		AST_LIST_REMOVE_CURRENT(entry);

Modified: team/dvossel/fixtheworld_phase1_step3/include/asterisk/format.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/include/asterisk/format.h?view=diff&rev=302000&r1=301999&r2=302000
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/include/asterisk/format.h (original)
+++ team/dvossel/fixtheworld_phase1_step3/include/asterisk/format.h Fri Jan 14 15:47:05 2011
@@ -234,7 +234,7 @@
 int ast_format_get_rtp_mark(const struct ast_format *format);
 
 /*!
- * \brief ast_format to iax2 bitfield format represenatation
+ * \brief ast_format to old bitfield format represenatation
  *
  * \note This is only to be used for IAX2 compatibility 
  *
@@ -244,7 +244,13 @@
 uint64_t ast_format_to_old_bitfield(struct ast_format *format);
 
 /*!
- * \brief convert iax2 bitfield format to ast_format represenatation
+ * \brief ast_format_id to old bitfield format represenatation
+ *
+ */
+uint64_t ast_format_id_to_old_bitfield(enum ast_format_id id);
+
+/*!
+ * \brief convert old bitfield format to ast_format represenatation
  * \note This is only to be used for IAX2 compatibility 
  *
  * \retval on success, pointer to the dst format in the input parameters
@@ -253,6 +259,11 @@
 struct ast_format *ast_format_from_old_bitfield(struct ast_format *dst, uint64_t src);
 
 /*!
+ * \brief convert old bitfield format to ast_format_id value
+ */
+enum ast_format_id ast_format_id_from_old_bitfield(uint64_t src);
+
+/*!
  * \brief register ast_format_attr_interface with core.
  *
  * \retval 0 success

Modified: team/dvossel/fixtheworld_phase1_step3/main/format.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/main/format.c?view=diff&rev=302000&r1=301999&r2=302000
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/format.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/main/format.c Fri Jan 14 15:47:05 2011
@@ -284,9 +284,10 @@
 	return format_joint_helper(format1, format2, result);
 }
 
-uint64_t ast_format_to_old_bitfield(struct ast_format *format)
-{
-	switch (format->id) {
+
+uint64_t ast_format_id_to_old_bitfield(enum ast_format_id id)
+{
+	switch (id) {
 	/*! G.723.1 compression */
 	case AST_FORMAT_G723_1:
 		return (1ULL << 0);
@@ -377,7 +378,13 @@
 	}
 
 	return 0;
-}
+
+}
+uint64_t ast_format_to_old_bitfield(struct ast_format *format)
+{
+	return ast_format_id_to_old_bitfield(format->id);
+}
+
 struct ast_format *ast_format_from_old_bitfield(struct ast_format *dst, uint64_t src)
 {
 	switch (src) {
@@ -473,6 +480,15 @@
 	return NULL;
 }
 
+enum ast_format_id ast_format_id_from_old_bitfield(uint64_t src)
+{
+	struct ast_format dst;
+	if (ast_format_from_old_bitfield(&dst, src), 0) {
+		return dst.id;
+	}
+	return 0;
+}
+
 int ast_format_attr_init()
 {
 	if (!(interfaces = ao2_container_alloc(256, interface_hash_cb, interface_cmp_cb))) {

Modified: team/dvossel/fixtheworld_phase1_step3/pbx/pbx_spool.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/pbx/pbx_spool.c?view=diff&rev=302000&r1=301999&r2=302000
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/pbx/pbx_spool.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/pbx/pbx_spool.c Fri Jan 14 15:47:05 2011
@@ -74,7 +74,7 @@
 	int retrytime;                            /*!< How long to wait between retries (in seconds) */
 	int waittime;                             /*!< How long to wait for an answer */
 	long callingpid;                          /*!< PID which is currently calling */
-	format_t format;                          /*!< Formats (codecs) for this call */
+	struct ast_cap *capabilities;                 /*!< Formats (codecs) for this call */
 	AST_DECLARE_STRING_FIELDS (
 		AST_STRING_FIELD(fn);                 /*!< File name of call file */
 		AST_STRING_FIELD(tech);               /*!< Which channel technology to use for outgoing call */
@@ -99,10 +99,16 @@
 
 static int init_outgoing(struct outgoing *o)
 {
+	struct ast_format tmpfmt;
 	o->priority = 1;
 	o->retrytime = 300;
 	o->waittime = 45;
-	o->format = AST_FORMAT_SLINEAR;
+
+	if (!(o->capabilities = ast_cap_alloc())) {
+		return -1;
+	}
+	ast_cap_add(o->capabilities, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
+
 	ast_set_flag(&o->options, SPOOL_FLAG_ALWAYS_DELETE);
 	if (ast_string_field_init(o, 128)) {
 		return -1;
@@ -116,6 +122,7 @@
 		ast_variables_destroy(o->vars);
 	}
 	ast_string_field_free_memory(o);
+	o->capabilities = ast_cap_destroy(o->capabilities);
 	ast_free(o);
 }
 
@@ -189,7 +196,7 @@
 						o->maxretries = 0;
 					}
 				} else if (!strcasecmp(buf, "codecs")) {
-					ast_parse_allow_disallow(NULL, &o->format, c, 1);
+					ast_parse_allow_disallow(NULL, o->capabilities, c, 1);
 				} else if (!strcasecmp(buf, "context")) {
 					ast_string_field_set(o, context, c);
 				} else if (!strcasecmp(buf, "extension")) {
@@ -338,11 +345,11 @@
 	int res, reason;
 	if (!ast_strlen_zero(o->app)) {
 		ast_verb(3, "Attempting call on %s/%s for application %s(%s) (Retry %d)\n", o->tech, o->dest, o->app, o->data, o->retries);
-		res = ast_pbx_outgoing_app(o->tech, o->format, (void *) o->dest, o->waittime * 1000, o->app, o->data, &reason, 2 /* wait to finish */, o->cid_num, o->cid_name, o->vars, o->account, NULL);
+		res = ast_pbx_outgoing_app(o->tech, o->capabilities, (void *) o->dest, o->waittime * 1000, o->app, o->data, &reason, 2 /* wait to finish */, o->cid_num, o->cid_name, o->vars, o->account, NULL);
 		o->vars = NULL;
 	} else {
 		ast_verb(3, "Attempting call on %s/%s for %s@%s:%d (Retry %d)\n", o->tech, o->dest, o->exten, o->context,o->priority, o->retries);
-		res = ast_pbx_outgoing_exten(o->tech, o->format, (void *) o->dest, o->waittime * 1000, o->context, o->exten, o->priority, &reason, 2 /* wait to finish */, o->cid_num, o->cid_name, o->vars, o->account, NULL);
+		res = ast_pbx_outgoing_exten(o->tech, o->capabilities, (void *) o->dest, o->waittime * 1000, o->context, o->exten, o->priority, &reason, 2 /* wait to finish */, o->cid_num, o->cid_name, o->vars, o->account, NULL);
 		o->vars = NULL;
 	}
 	if (res) {




More information about the svn-commits mailing list