[asterisk-commits] dvossel: branch dvossel/fixtheworld_phase1_step3 r300880 - in /team/dvossel/f...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jan 6 22:53:51 UTC 2011


Author: dvossel
Date: Thu Jan  6 16:53:47 2011
New Revision: 300880

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=300880
Log:
updates to format.c indications.c frame.c and image.c for ast_format conversion

Modified:
    team/dvossel/fixtheworld_phase1_step3/include/asterisk/format.h
    team/dvossel/fixtheworld_phase1_step3/include/asterisk/image.h
    team/dvossel/fixtheworld_phase1_step3/main/format.c
    team/dvossel/fixtheworld_phase1_step3/main/frame.c
    team/dvossel/fixtheworld_phase1_step3/main/image.c
    team/dvossel/fixtheworld_phase1_step3/main/indications.c

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=300880&r1=300879&r2=300880
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/include/asterisk/format.h (original)
+++ team/dvossel/fixtheworld_phase1_step3/include/asterisk/format.h Thu Jan  6 16:53:47 2011
@@ -208,7 +208,7 @@
 /*!
  * \brief copy format src into format dst.
  */
-void ast_format_copy(struct ast_format *src, struct ast_format *dst);
+void ast_format_copy(const struct ast_format *src, struct ast_format *dst);
 
 /*!
  * \brief ast_format to iax2 bitfield format represenatation

Modified: team/dvossel/fixtheworld_phase1_step3/include/asterisk/image.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/include/asterisk/image.h?view=diff&rev=300880&r1=300879&r2=300880
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/include/asterisk/image.h (original)
+++ team/dvossel/fixtheworld_phase1_step3/include/asterisk/image.h Thu Jan  6 16:53:47 2011
@@ -28,7 +28,7 @@
 	char *name;			/*!< Name */
 	char *desc;			/*!< Description */
 	char *exts;			/*!< Extension(s) (separated by '|' ) */
-	int format;			/*!< Image format */
+	struct ast_format format; /*!< Image format */
 	struct ast_frame *(*read_image)(int fd, int len);	/*!< Read an image from a file descriptor */
 	int (*identify)(int fd);				/*!< Identify if this is that type of file */
 	int (*write_image)(int fd, struct ast_frame *frame);	/*!< Returns length written */
@@ -57,12 +57,12 @@
  * \brief Make an image 
  * \param filename filename of image to prepare
  * \param preflang preferred language to get the image...?
- * \param format the format of the file
+ * \param format the format of the file, NULL for any image format
  * Make an image from a filename ??? No estoy positivo
  * \retval an ast_frame on success
  * \retval NULL on failure
  */
-struct ast_frame *ast_read_image(const char *filename, const char *preflang, int format);
+struct ast_frame *ast_read_image(const char *filename, const char *preflang, struct ast_format *format);
 
 /*! 
  * \brief Register image format

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=300880&r1=300879&r2=300880
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/format.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/main/format.c Thu Jan  6 16:53:47 2011
@@ -71,7 +71,7 @@
 	ast_rwlock_destroy(&wrapper->wraplock);
 }
 
-void ast_format_copy(struct ast_format *src, struct ast_format *dst)
+void ast_format_copy(const struct ast_format *src, struct ast_format *dst)
 {
 	memcpy(dst, src, sizeof(struct ast_format));
 }

Modified: team/dvossel/fixtheworld_phase1_step3/main/frame.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/main/frame.c?view=diff&rev=300880&r1=300879&r2=300880
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/frame.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/main/frame.c Thu Jan  6 16:53:47 2011
@@ -80,7 +80,7 @@
 
 struct ast_smoother {
 	int size;
-	format_t format;
+	struct ast_format format;
 	int flags;
 	float samplesperbyte;
 	unsigned int opt_needs_swap:1;
@@ -207,12 +207,12 @@
 		ast_log(LOG_WARNING, "Huh?  Can't smooth a non-voice frame!\n");
 		return -1;
 	}
-	if (!s->format) {
-		s->format = f->subclass.codec;
+	if (!s->format.id) {
+		ast_format_copy(&f->subclass.format, &s->format);
 		s->samplesperbyte = (float)f->samples / (float)f->datalen;
-	} else if (s->format != f->subclass.codec) {
+	} else if (ast_format_cmp(&s->format, &f->subclass.format) == AST_FORMAT_CMP_NOT_EQUAL) {
 		ast_log(LOG_WARNING, "Smoother was working on %s format frames, now trying to feed %s?\n",
-			ast_getformatname(s->format), ast_getformatname(f->subclass.codec));
+			ast_getformatname(&s->format), ast_getformatname(&f->subclass.format));
 		return -1;
 	}
 	if (s->len + f->datalen > SMOOTHER_SIZE) {
@@ -263,7 +263,7 @@
 		len = s->len;
 	/* Make frame */
 	s->f.frametype = AST_FRAME_VOICE;
-	s->f.subclass.codec = s->format;
+	ast_format_copy(&s->format, &s->f.subclass.format);
 	s->f.data.ptr = s->framedata + AST_FRIENDLY_OFFSET;
 	s->f.offset = AST_FRIENDLY_OFFSET;
 	s->f.datalen = len;
@@ -280,7 +280,7 @@
 		memmove(s->data, s->data + len, s->len);
 		if (!ast_tvzero(s->delivery)) {
 			/* If we have delivery time, increment it, otherwise, leave it at 0 */
-			s->delivery = ast_tvadd(s->delivery, ast_samp2tv(s->f.samples, ast_format_rate(s->format)));
+			s->delivery = ast_tvadd(s->delivery, ast_samp2tv(s->f.samples, ast_format_rate(&s->format)));
 		}
 	}
 	/* Return frame */
@@ -408,7 +408,7 @@
 			return NULL;
 		}
 		out->frametype = fr->frametype;
-		out->subclass.codec = fr->subclass.codec;
+		ast_format_copy(&fr->subclass.format, &out->subclass.format);
 		out->datalen = fr->datalen;
 		out->samples = fr->samples;
 		out->offset = fr->offset;
@@ -515,7 +515,7 @@
 	}
 
 	out->frametype = f->frametype;
-	out->subclass.codec = f->subclass.codec;
+	ast_format_copy(&f->subclass.format, &out->subclass.format);
 	out->datalen = f->datalen;
 	out->samples = f->samples;
 	out->delivery = f->delivery;
@@ -588,13 +588,13 @@
 
 	if (!size)
 		return buf;
-	snprintf(end, size, "(",);
+	snprintf(end, size, "(");
 	len = strlen(end);
 	end += len;
 	size -= len;
 	start = end;
 	for (x = 0; x < ARRAY_LEN(AST_FORMAT_LIST); x++) {
-		ast_format_set(&tmp_fmt, AST_FORMAT_LIST[x].id, 0)
+		ast_format_set(&tmp_fmt, AST_FORMAT_LIST[x].id, 0);
 		if (ast_cap_iscompatible(cap, &tmp_fmt)) {
 			snprintf(end, size, "%s|", AST_FORMAT_LIST[x].name);
 			len = strlen(end);
@@ -652,7 +652,7 @@
 	int x;
 	char *ret = "unknown";
 	for (x = 0; x < ARRAY_LEN(AST_FORMAT_LIST); x++) {
-		if (AST_FORMAT_LIST[x].id == format.id) {
+		if (AST_FORMAT_LIST[x].id == format->id) {
 			ret = AST_FORMAT_LIST[x].desc;
 			break;
 		}
@@ -662,8 +662,7 @@
 
 static char *show_codecs(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
-	int i, found=0;
-	char hex[25];
+	int x, found=0;
 
 	switch (cmd) {
 	case CLI_INIT:
@@ -683,25 +682,25 @@
 		ast_cli(a->fd, "Disclaimer: this command is for informational purposes only.\n"
 				"\tIt does not indicate anything about your configuration.\n");
 
-	ast_cli(a->fd, "%19s %9s %20s   TYPE   %8s   %s\n","INT","BINARY","HEX","NAME","DESCRIPTION");
+	ast_cli(a->fd, "%19s %8s %8s %s\n","ID","TYPE","NAME","DESCRIPTION");
 	ast_cli(a->fd, "-----------------------------------------------------------------------------------\n");
-	for (i = 0; i < 63; i++) {
-
+
+	for (x = 0; x < ARRAY_LEN(AST_FORMAT_LIST); x++) {
 		if (a->argc == 4) {
 			if (!strcasecmp(a->argv[3], "audio")) {
-				if (!((1LL << i) & AST_FORMAT_AUDIO_MASK)) {
+				if (AST_FORMAT_GET_TYPE(AST_FORMAT_LIST[x].id) != AST_FORMAT_TYPE_AUDIO) {
 					continue;
 				}
 			} else if (!strcasecmp(a->argv[3], "video")) {
-				if (!((1LL << i) & AST_FORMAT_VIDEO_MASK)) {
+				if (AST_FORMAT_GET_TYPE(AST_FORMAT_LIST[x].id) != AST_FORMAT_TYPE_VIDEO) {
 					continue;
 				}
 			} else if (!strcasecmp(a->argv[3], "image")) {
-				if (i != 16 && i != 17) {
+				if (AST_FORMAT_GET_TYPE(AST_FORMAT_LIST[x].id) != AST_FORMAT_TYPE_IMAGE) {
 					continue;
 				}
 			} else if (!strcasecmp(a->argv[3], "text")) {
-				if (!((1LL << i) & AST_FORMAT_TEXT_MASK)) {
+				if (AST_FORMAT_GET_TYPE(AST_FORMAT_LIST[x].id) != AST_FORMAT_TYPE_TEXT) {
 					continue;
 				}
 			} else {
@@ -709,14 +708,15 @@
 			}
 		}
 
-		snprintf(hex, sizeof(hex), "(0x%llx)", 1LL << i);
-		ast_cli(a->fd, "%19llu (1 << %2d) %20s  %5s   %8s   (%s)\n", 1LL << i, i, hex,
-			((1LL << i) & AST_FORMAT_AUDIO_MASK) ? "audio" :
-			i == 16 || i == 17 ? "image" :
-			((1LL << i) & AST_FORMAT_VIDEO_MASK) ? "video" :
-			((1LL << i) & AST_FORMAT_TEXT_MASK) ? "text" :
+		ast_cli(a->fd, "%19u %5s %8s (%s)\n",
+			AST_FORMAT_LIST[x].id,
+			(AST_FORMAT_GET_TYPE(AST_FORMAT_LIST[x].id) == AST_FORMAT_TYPE_AUDIO) ? "audio" :
+			(AST_FORMAT_GET_TYPE(AST_FORMAT_LIST[x].id)  == AST_FORMAT_TYPE_TEXT)  ? "image" :
+			(AST_FORMAT_GET_TYPE(AST_FORMAT_LIST[x].id)  == AST_FORMAT_TYPE_VIDEO) ? "video" :
+			(AST_FORMAT_GET_TYPE(AST_FORMAT_LIST[x].id)  == AST_FORMAT_TYPE_TEXT)  ? "text"  :
 			"(unk)",
-			ast_getformatname(1LL << i), ast_codec2str(1LL << i));
+			AST_FORMAT_LIST[x].name,
+			AST_FORMAT_LIST[x].desc);
 		found = 1;
 	}
 
@@ -729,9 +729,9 @@
 
 static char *show_codec_n(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
-	format_t codec;
-	int i, found = 0;
-	long long type_punned_codec;
+	enum ast_format_id format_id;
+	int x, found = 0;
+	int type_punned_codec;
 
 	switch (cmd) {
 	case CLI_INIT:
@@ -747,19 +747,21 @@
 	if (a->argc != 4)
 		return CLI_SHOWUSAGE;
 
-	if (sscanf(a->argv[3], "%30lld", &type_punned_codec) != 1) {
+	if (sscanf(a->argv[3], "%30d", &type_punned_codec) != 1) {
 		return CLI_SHOWUSAGE;
 	}
-	codec = type_punned_codec;
-
-	for (i = 0; i < 63; i++)
-		if (codec & (1LL << i)) {
+	format_id = type_punned_codec;
+
+	for (x = 0; x < ARRAY_LEN(AST_FORMAT_LIST); x++) {
+		if (AST_FORMAT_LIST[x].id == format_id) {
 			found = 1;
-			ast_cli(a->fd, "%11llu (1 << %2d)  %s\n", 1LL << i, i, ast_codec2str(1LL << i));
-		}
+			ast_cli(a->fd, "%11u %s\n", (unsigned int) format_id, AST_FORMAT_LIST[x].desc);
+			break;
+		}
+	}
 
 	if (!found)
-		ast_cli(a->fd, "Codec %lld not found\n", (long long) codec);
+		ast_cli(a->fd, "Codec %d not found\n", format_id);
 
 	return CLI_SUCCESS;
 }
@@ -895,7 +897,7 @@
 		break;
 	case AST_FRAME_IMAGE:
 		strcpy(ftype, "Image");
-		snprintf(subclass, sizeof(subclass), "Image format %s\n", ast_getformatname(f->subclass.codec));
+		snprintf(subclass, sizeof(subclass), "Image format %s\n", ast_getformatname(&f->subclass.format));
 		break;
 	case AST_FRAME_HTML:
 		strcpy(ftype, "HTML");
@@ -983,11 +985,11 @@
 	return 0;	
 }
 
-int ast_parse_allow_disallow(struct ast_codec_pref *pref, format_t *mask, const char *list, int allowing) 
+int ast_parse_allow_disallow(struct ast_codec_pref *pref, struct ast_cap *cap, const char *list, int allowing) 
 {
 	int errors = 0, framems = 0;
 	char *parse = NULL, *this = NULL, *psize = NULL;
-	format_t format = 0;
+	struct ast_format format;
 
 	parse = ast_strdupa(list);
 	while ((this = strsep(&parse, ","))) {
@@ -1002,30 +1004,30 @@
 				ast_log(LOG_WARNING, "Bad packetization value for codec %s\n", this);
 			}
 		}
-		if (!(format = ast_getformatbyname(this))) {
+		if (!ast_getformatbyname(this, &format)) {
 			ast_log(LOG_WARNING, "Cannot %s unknown format '%s'\n", allowing ? "allow" : "disallow", this);
 			errors++;
 			continue;
 		}
 
-		if (mask) {
+		if (cap) {
 			if (allowing)
-				*mask |= format;
+				ast_cap_add(cap, &format);
 			else
-				*mask &= ~format;
+				ast_cap_remove(cap, &format);
 		}
 
 		/* Set up a preference list for audio. Do not include video in preferences 
 		   since we can not transcode video and have to use whatever is offered
 		 */
-		if (pref && (format & AST_FORMAT_AUDIO_MASK)) {
+		if (pref && (AST_FORMAT_GET_TYPE(format.id) == AST_FORMAT_TYPE_AUDIO)) {
 			if (strcasecmp(this, "all")) {
 				if (allowing) {
-					ast_codec_pref_append(pref, format);
-					ast_codec_pref_setsize(pref, format, framems);
+					ast_codec_pref_append(pref, &format);
+					ast_codec_pref_setsize(pref, &format, framems);
 				}
 				else
-					ast_codec_pref_remove(pref, format);
+					ast_codec_pref_remove(pref, &format);
 			} else if (!allowing) {
 				memset(pref, 0, sizeof(*pref));
 			}
@@ -1184,9 +1186,8 @@
 int ast_codec_get_samples(struct ast_frame *f)
 {
 	int samples = 0;
-	char tmp[64];
-
-	switch (f->subclass.codec) {
+
+	switch (f->subclass.format.id) {
 	case AST_FORMAT_SPEEX:
 		samples = speex_samples(f->data.ptr, f->datalen);
 		break;
@@ -1238,17 +1239,17 @@
 		samples = (int) f->datalen * ((float) 48000 / 8000);
 		break;
 	default:
-		ast_log(LOG_WARNING, "Unable to calculate samples for format %s\n", ast_getformatname_multiple(tmp, sizeof(tmp), f->subclass.codec));
+		ast_log(LOG_WARNING, "Unable to calculate samples for format %s\n", ast_getformatname(&f->subclass.format));
 	}
 	return samples;
 }
 
-int ast_codec_get_len(format_t format, int samples)
+int ast_codec_get_len(struct ast_format *format, int samples)
 {
 	int len = 0;
 
 	/* XXX Still need speex, and lpc10 XXX */	
-	switch(format) {
+	switch(format->id) {
 	case AST_FORMAT_G723_1:
 		len = (samples / 240) * 20;
 		break;
@@ -1301,7 +1302,7 @@
 	short *fdata = f->data.ptr;
 	short adjust_value = abs(adjustment);
 
-	if ((f->frametype != AST_FRAME_VOICE) || (f->subclass.codec != AST_FORMAT_SLINEAR))
+	if ((f->frametype != AST_FRAME_VOICE) || (f->subclass.format.id != AST_FORMAT_SLINEAR))
 		return -1;
 
 	if (!adjustment)
@@ -1323,10 +1324,10 @@
 	int count;
 	short *data1, *data2;
 
-	if ((f1->frametype != AST_FRAME_VOICE) || (f1->subclass.codec != AST_FORMAT_SLINEAR))
+	if ((f1->frametype != AST_FRAME_VOICE) || (f1->subclass.format.id != AST_FORMAT_SLINEAR))
 		return -1;
 
-	if ((f2->frametype != AST_FRAME_VOICE) || (f2->subclass.codec != AST_FORMAT_SLINEAR))
+	if ((f2->frametype != AST_FRAME_VOICE) || (f2->subclass.format.id != AST_FORMAT_SLINEAR))
 		return -1;
 
 	if (f1->samples != f2->samples)

Modified: team/dvossel/fixtheworld_phase1_step3/main/image.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/main/image.c?view=diff&rev=300880&r1=300879&r2=300880
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/image.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/main/image.c Thu Jan  6 16:53:47 2011
@@ -96,7 +96,7 @@
 	}
 }
 
-struct ast_frame *ast_read_image(const char *filename, const char *preflang, int format)
+struct ast_frame *ast_read_image(const char *filename, const char *preflang, struct ast_format *format)
 {
 	struct ast_imager *i;
 	char buf[256];
@@ -109,7 +109,8 @@
 	
 	AST_RWLIST_RDLOCK(&imagers);
 	AST_RWLIST_TRAVERSE(&imagers, i, list) {
-		if (i->format & format) {
+		/* if NULL image format, just pick the first one, otherwise match it. */
+		if (!format || (ast_format_cmp(&i->format, format) == AST_FORMAT_CMP_EQUAL)) {
 			char *stringp=NULL;
 			ast_copy_string(tmp, i->exts, sizeof(tmp));
 			stringp = tmp;
@@ -157,7 +158,7 @@
 	struct ast_frame *f;
 	int res = -1;
 	if (chan->tech->send_image) {
-		f = ast_read_image(filename, chan->language, -1);
+		f = ast_read_image(filename, chan->language, NULL);
 		if (f) {
 			res = chan->tech->send_image(chan, f);
 			ast_frfree(f);
@@ -189,7 +190,7 @@
 	ast_cli(a->fd, FORMAT, "----", "----------", "-----------", "------");
 	AST_RWLIST_RDLOCK(&imagers);
 	AST_RWLIST_TRAVERSE(&imagers, i, list) {
-		ast_cli(a->fd, FORMAT2, i->name, i->exts, i->desc, ast_getformatname(i->format));
+		ast_cli(a->fd, FORMAT2, i->name, i->exts, i->desc, ast_getformatname(&i->format));
 		count_fmt++;
 	}
 	AST_RWLIST_UNLOCK(&imagers);

Modified: team/dvossel/fixtheworld_phase1_step3/main/indications.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/main/indications.c?view=diff&rev=300880&r1=300879&r2=300880
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/indications.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/main/indications.c Thu Jan  6 16:53:47 2011
@@ -116,7 +116,7 @@
 	int npos;
 	int oldnpos;
 	int pos;
-	int origwfmt;
+	struct ast_format origwfmt;
 	struct ast_frame f;
 	unsigned char offset[AST_FRIENDLY_OFFSET];
 	short data[4000];
@@ -127,7 +127,7 @@
 	struct playtones_state *ps = params;
 
 	if (chan) {
-		ast_set_write_format(chan, ps->origwfmt);
+		ast_set_write_format(chan, &ps->origwfmt);
 	}
 
 	if (ps->items) {
@@ -147,9 +147,9 @@
 		return NULL;
 	}
 
-	ps->origwfmt = chan->writeformat;
-
-	if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) {
+	ast_format_copy(&chan->writeformat, &ps->origwfmt);
+
+	if (ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR)) {
 		ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", chan->name);
 		playtones_release(NULL, ps);
 		ps = NULL;
@@ -223,7 +223,7 @@
 	}
 
 	ps->f.frametype = AST_FRAME_VOICE;
-	ps->f.subclass.codec = AST_FORMAT_SLINEAR;
+	ast_format_set(&ps->f.subclass.format, AST_FORMAT_SLINEAR, 0);
 	ps->f.datalen = len;
 	ps->f.samples = samples;
 	ps->f.offset = AST_FRIENDLY_OFFSET;




More information about the asterisk-commits mailing list