[asterisk-commits] dvossel: branch dvossel/fixtheworld_phase1_step3 r303096 - /team/dvossel/fixt...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jan 20 11:40:59 CST 2011


Author: dvossel
Date: Thu Jan 20 11:40:56 2011
New Revision: 303096

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=303096
Log:
conversion of chan_vpb to ast_format api

Modified:
    team/dvossel/fixtheworld_phase1_step3/channels/chan_vpb.cc

Modified: team/dvossel/fixtheworld_phase1_step3/channels/chan_vpb.cc
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/channels/chan_vpb.cc?view=diff&rev=303096&r1=303095&r2=303096
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/channels/chan_vpb.cc (original)
+++ team/dvossel/fixtheworld_phase1_step3/channels/chan_vpb.cc Thu Jan 20 11:40:56 2011
@@ -101,8 +101,6 @@
 
 static int gruntdetect_timeout = 3600000; /* Grunt detect timeout is 1hr. */
 
-static const int prefformat = AST_FORMAT_SLINEAR;
-
 /* Protect the interface list (of vpb_pvt's) */
 AST_MUTEX_DEFINE_STATIC(iflock);
 
@@ -331,7 +329,7 @@
 
 static struct ast_channel *vpb_new(struct vpb_pvt *i, enum ast_channel_state state, const char *context, const char *linkedid);
 static void *do_chanreads(void *pvt);
-static struct ast_channel *vpb_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause);
+static struct ast_channel *vpb_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause);
 static int vpb_digit_begin(struct ast_channel *ast, char digit);
 static int vpb_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
 static int vpb_call(struct ast_channel *ast, char *dest, int timeout);
@@ -346,7 +344,7 @@
 static struct ast_channel_tech vpb_tech = {
 	type: "vpb",
 	description: tdesc,
-	capabilities: AST_FORMAT_SLINEAR,
+	capabilities: NULL,
 	properties: 0,
 	requester: vpb_request,
 	devicestate: NULL,
@@ -380,7 +378,7 @@
 static struct ast_channel_tech vpb_tech_indicate = {
 	type: "vpb",
 	description: tdesc,
-	capabilities: AST_FORMAT_SLINEAR,
+	capabilities: NULL,
 	properties: 0,
 	requester: vpb_request,
 	devicestate: NULL,
@@ -755,10 +753,11 @@
 #endif
 		vpb_record_buf_start(p->handle, VPB_MULAW);
 		while ((rc == 0) && (sam_count < 8000 * 3)) {
+			struct ast_format tmpfmt;
 			vrc = vpb_record_buf_sync(p->handle, (char*)buf, sizeof(buf));
 			if (vrc != VPB_OK)
 				ast_log(LOG_ERROR, "%s: Caller ID couldn't read audio buffer!\n", p->dev);
-			rc = callerid_feed(cs, (unsigned char *)buf, sizeof(buf), AST_FORMAT_ULAW);
+			rc = callerid_feed(cs, (unsigned char *)buf, sizeof(buf), ast_format_set(&tmpfmt, AST_FORMAT_ULAW, 0));
 #ifdef ANALYSE_CID
 			vpb_wave_write(ws, (char *)buf, sizeof(buf)); 
 #endif
@@ -2096,9 +2095,9 @@
 	return &f;
 }
 
-static inline AudioCompress ast2vpbformat(format_t ast_format)
-{
-	switch (ast_format) {
+static inline AudioCompress ast2vpbformat(struct ast_format *format)
+{
+	switch (format->id) {
 	case AST_FORMAT_ALAW:
 		return VPB_ALAW;
 	case AST_FORMAT_SLINEAR:
@@ -2112,9 +2111,9 @@
 	}
 }
 
-static inline const char * ast2vpbformatname(format_t ast_format)
-{
-	switch(ast_format) {
+static inline const char * ast2vpbformatname(struct ast_format *format)
+{
+	switch(format->id) {
 	case AST_FORMAT_ALAW:
 		return "AST_FORMAT_ALAW:VPB_ALAW";
 	case AST_FORMAT_SLINEAR:
@@ -2128,9 +2127,9 @@
 	}
 }
 
-static inline int astformatbits(format_t ast_format)
-{
-	switch (ast_format) {
+static inline int astformatbits(struct ast_format *format)
+{
+	switch (format->id) {
 	case AST_FORMAT_SLINEAR:
 		return 16;
 	case AST_FORMAT_ADPCM:
@@ -2174,7 +2173,7 @@
 /*		ast_mutex_unlock(&p->lock); */
 		return 0;
 	} else if (ast->_state != AST_STATE_UP) {
-		ast_verb(4, "%s: vpb_write: Attempt to Write frame type[%d]subclass[%s] on not up chan(state[%d])\n", ast->name, frame->frametype, ast_getformatname(frame->subclass.codec), ast->_state);
+		ast_verb(4, "%s: vpb_write: Attempt to Write frame type[%d]subclass[%s] on not up chan(state[%d])\n", ast->name, frame->frametype, ast_getformatname(&frame->subclass.format), ast->_state);
 		p->lastoutput = -1;
 /*		ast_mutex_unlock(&p->lock); */
 		return 0;
@@ -2182,9 +2181,9 @@
 /*	ast_debug(1, "%s: vpb_write: Checked frame type..\n", p->dev); */
 
 
-	fmt = ast2vpbformat(frame->subclass.codec);
+	fmt = ast2vpbformat(&frame->subclass.format);
 	if (fmt < 0) {
-		ast_log(LOG_WARNING, "%s: vpb_write: Cannot handle frames of %s format!\n", ast->name, ast_getformatname(frame->subclass.codec));
+		ast_log(LOG_WARNING, "%s: vpb_write: Cannot handle frames of %s format!\n", ast->name, ast_getformatname(&frame->subclass.format));
 		return -1;
 	}
 
@@ -2208,7 +2207,7 @@
 	/* Check if we have set up the play_buf */
 	if (p->lastoutput == -1) {
 		vpb_play_buf_start(p->handle, fmt);
-		ast_verb(2, "%s: vpb_write: Starting play mode (codec=%d)[%s]\n", p->dev, fmt, ast2vpbformatname(frame->subclass.codec));
+		ast_verb(2, "%s: vpb_write: Starting play mode (codec=%d)[%s]\n", p->dev, fmt, ast2vpbformatname(&frame->subclass.format));
 		p->lastoutput = fmt;
 		ast_mutex_unlock(&p->play_lock);
 		return 0;
@@ -2258,7 +2257,7 @@
 	struct ast_frame *fr = &p->fr;
 	char *readbuf = ((char *)p->buf) + AST_FRIENDLY_OFFSET;
 	int bridgerec = 0;
-	format_t afmt;
+	struct ast_format tmpfmt;
 	int readlen, res, trycnt=0;
 	AudioCompress fmt;
 	int ignore_dtmf;
@@ -2353,26 +2352,23 @@
 		}
 		ast_mutex_unlock(&p->play_dtmf_lock);
 
-/*		afmt = (p->owner) ? p->owner->rawreadformat : AST_FORMAT_SLINEAR; */
 		if (p->owner) {
-			afmt = p->owner->rawreadformat;
-/*			ast_debug(1,"%s: Record using owner format [%s]\n", p->dev, ast2vpbformatname(afmt)); */
+			ast_format_copy(&tmpfmt, &p->owner->rawreadformat);
 		} else {
-			afmt = AST_FORMAT_SLINEAR;
-/*			ast_debug(1,"%s: Record using default format [%s]\n", p->dev, ast2vpbformatname(afmt)); */
-		}
-		fmt = ast2vpbformat(afmt);
+			ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0);
+		}
+		fmt = ast2vpbformat(&tmpfmt);
 		if (fmt < 0) {
-			ast_log(LOG_WARNING, "%s: Record failure (unsupported format %s)\n", p->dev, ast_getformatname(afmt));
+			ast_log(LOG_WARNING, "%s: Record failure (unsupported format %s)\n", p->dev, ast_getformatname(&tmpfmt));
 			return NULL;
 		}
-		readlen = VPB_SAMPLES * astformatbits(afmt) / 8;
+		readlen = VPB_SAMPLES * astformatbits(&tmpfmt) / 8;
 
 		if (p->lastinput == -1) {
 			vpb_record_buf_start(p->handle, fmt);
 /*			vpb_reset_record_fifo_alarm(p->handle); */
 			p->lastinput = fmt;
-			ast_verb(2, "%s: Starting record mode (codec=%d)[%s]\n", p->dev, fmt, ast2vpbformatname(afmt));
+			ast_verb(2, "%s: Starting record mode (codec=%d)[%s]\n", p->dev, fmt, ast2vpbformatname(&tmpfmt));
 			continue;
 		} else if (p->lastinput != fmt) {
 			vpb_record_buf_finish(p->handle);
@@ -2391,7 +2387,7 @@
 				a_gain_vector(p->rxswgain - MAX_VPB_GAIN, (short *)readbuf, readlen / sizeof(short));
 			ast_verb(6, "%s: chanreads: applied gain\n", p->dev);
 
-			fr->subclass.codec = afmt;
+			ast_format_copy(&fr->subclass.format, &tmpfmt);
 			fr->data.ptr = readbuf;
 			fr->datalen = readlen;
 			fr->frametype = AST_FRAME_VOICE;
@@ -2471,6 +2467,7 @@
 	struct ast_channel *tmp; 
 	char cid_num[256];
 	char cid_name[256];
+	struct ast_format tmpfmt;
 
 	if (me->owner) {
 	    ast_log(LOG_WARNING, "Called vpb_new on owned channel (%s) ?!\n", me->dev);
@@ -2493,9 +2490,9 @@
 		 * they are all converted to/from linear in the vpb code. Best for us to use
 		 * linear since we can then adjust volume in this modules.
 		 */
-		tmp->nativeformats = prefformat;
-		tmp->rawreadformat = AST_FORMAT_SLINEAR;
-		tmp->rawwriteformat =  AST_FORMAT_SLINEAR;
+		ast_format_cap_add(tmp->nativeformats, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
+		ast_format_copy(&tmp->rawreadformat, &tmpfmt);
+		ast_format_copy(&tmp->rawwriteformat, &tmpfmt);
 		if (state == AST_STATE_RING) {
 			tmp->rings = 1;
 			cid_name[0] = '\0';
@@ -2541,19 +2538,20 @@
 	return tmp;
 }
 
-static struct ast_channel *vpb_request(const char *type, format_t format, const struct ast_channel *requestor, void *vdata, int *cause) 
-{
-	format_t oldformat;
+static struct ast_channel *vpb_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *vdata, int *cause) 
+{
 	struct vpb_pvt *p;
 	struct ast_channel *tmp = NULL;
 	char *sepstr, *data = (char *)vdata, *name;
 	const char *s;
 	int group = -1;
-
-	oldformat = format;
-	format &= prefformat;
-	if (!format) {
-		ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%s'\n", ast_getformatname(oldformat));
+	struct ast_format slin;
+
+	ast_format_set(&slin, AST_FORMAT_SLINEAR, 0);
+
+	if (!(ast_format_cap_iscompatible(cap, &slin))) {
+		char tmp[256];
+		ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%s'\n", ast_getformatname_multiple(tmp, sizeof(tmp), cap));
 		return NULL;
 	}
 
@@ -2675,6 +2673,8 @@
 		ast_free(bridges);
 	}
 
+	ast_format_cap_destroy(vpb_tech.capabilities);
+	ast_format_cap_destroy(vpb_tech_indicate.capabilities);
 	return 0;
 }
 
@@ -2698,8 +2698,17 @@
 	int bal2 = -1; 
 	int bal3 = -1;
 	char * callerid = NULL;
-
+	struct ast_format tmpfmt;
 	int num_cards = 0;
+
+	if (!(vpb_tech.capabilities = ast_format_cap_alloc())) {
+		return AST_MODULE_LOAD_DECLINE;
+	}
+	if (!(vpb_tech_indicate.capabilities = ast_format_cap_alloc())) {
+		return AST_MODULE_LOAD_DECLINE;
+	}
+	ast_format_cap_add(vpb_tech.capabilities, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
+	ast_format_cap_add(vpb_tech_indicate.capabilities, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
 	try {
 		num_cards = vpb_get_num_cards();
 	} catch (std::exception e) {




More information about the asterisk-commits mailing list