[asterisk-commits] file: branch group/media_formats r411572 - /team/group/media_formats/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Mar 28 17:09:35 CDT 2014


Author: file
Date: Fri Mar 28 17:09:29 2014
New Revision: 411572

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=411572
Log:
Move the res_format_attr_celt module over.

Modified:
    team/group/media_formats/res/res_format_attr_celt.c

Modified: team/group/media_formats/res/res_format_attr_celt.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/res/res_format_attr_celt.c?view=diff&rev=411572&r1=411571&r2=411572
==============================================================================
--- team/group/media_formats/res/res_format_attr_celt.c (original)
+++ team/group/media_formats/res/res_format_attr_celt.c Fri Mar 28 17:09:29 2014
@@ -45,10 +45,25 @@
 	unsigned int framesize;
 };
 
-static int celt_sdp_parse(struct ast_format_attr *format_attr, const char *attributes)
-{
-	struct celt_attr *attr = (struct celt_attr *) format_attr;
+static void celt_destroy(struct ast_format *format)
+{
+	struct celt_attr *attr = format->attribute_data;
+
+	ast_free(attr);
+}
+
+static int celt_sdp_parse(struct ast_format *format, const char *attributes)
+{
+	struct celt_attr *attr;
 	unsigned int val;
+
+	if (!format->attribute_data) {
+		format->attribute_data = ast_calloc(1, sizeof(*attr));
+	}
+	attr = format->attribute_data;
+	if (!attr) {
+		return -1;
+	}
 
 	if (sscanf(attributes, "framesize=%30u", &val) == 1) {
 		attr->framesize = val;
@@ -57,140 +72,117 @@
 	return 0;
 }
 
-static void celt_sdp_generate(const struct ast_format_attr *format_attr, unsigned int payload, struct ast_str **str)
-{
-	struct celt_attr *attr = (struct celt_attr *) format_attr;
-
-	if (!attr->framesize) {
+static void celt_sdp_generate(const struct ast_format *format, unsigned int payload, struct ast_str **str)
+{
+	struct celt_attr *attr = format->attribute_data;
+
+	if (!attr || !attr->framesize) {
 		return;
 	}
 
 	ast_str_append(str, 0, "a=fmtp:%d framesize=%d\r\n", payload, attr->framesize);
 }
 
-static enum ast_format_cmp_res celt_cmp(const struct ast_format_attr *fattr1, const struct ast_format_attr *fattr2)
-{
-	struct celt_attr *attr1 = (struct celt_attr *) fattr1;
-	struct celt_attr *attr2 = (struct celt_attr *) fattr2;
-
-	if (attr1->samplerate == attr2->samplerate) {
+static enum ast_format_cmp_res celt_cmp(const struct ast_format *format1, const struct ast_format *format2)
+{
+	struct celt_attr *attr1 = format1->attribute_data;
+	struct celt_attr *attr2 = format2->attribute_data;
+
+	if (((!attr1 || !attr1->samplerate) && (!attr2 || !attr2->samplerate)) ||
+		(attr1->samplerate == attr2->samplerate)) {
 		return AST_FORMAT_CMP_EQUAL;
 	}
+
 	return AST_FORMAT_CMP_NOT_EQUAL;
 }
 
-static int celt_get_val(const struct ast_format_attr *fattr, int key, void *result)
-{
-	const struct celt_attr *attr = (struct celt_attr *) fattr;
-	int *val = result;
-
-	switch (key) {
-	case CELT_ATTR_KEY_SAMP_RATE:
-		*val = attr->samplerate;
-		break;
-	case CELT_ATTR_KEY_MAX_BITRATE:
-		*val = attr->maxbitrate;
-		break;
-	case CELT_ATTR_KEY_FRAME_SIZE:
-		*val = attr->framesize;
-		break;
-	default:
-		ast_log(LOG_WARNING, "unknown attribute type %d\n", key);
+static struct ast_format *celt_getjoint(const struct ast_format *format1, const struct ast_format *format2)
+{
+	struct celt_attr *attr1 = format1->attribute_data;
+	struct celt_attr *attr2 = format2->attribute_data;
+	struct ast_format *jointformat;
+	struct celt_attr *jointattr;
+
+	if (attr1 && attr2 && (attr1->samplerate != attr2->samplerate)) {
+		return NULL;
+	}
+
+	jointformat = ast_format_create(format1->codec);
+	if (!jointformat) {
+		return NULL;
+	}
+
+	jointformat->attribute_data = ast_calloc(1, sizeof(*jointattr));
+	if (!jointformat->attribute_data) {
+		ao2_ref(jointformat, -1);
+		return NULL;
+	}
+	jointattr = jointformat->attribute_data;
+
+	/* either would work, they are guaranteed the same at this point. */
+	jointattr->samplerate = attr1->samplerate;
+	/* Take the lowest max bitrate */
+	jointattr->maxbitrate = MIN(attr1->maxbitrate, attr2->maxbitrate);
+
+	jointattr->framesize = attr2->framesize; /* TODO figure out what joint framesize means */
+
+	return jointformat;
+}
+
+static int celt_set(struct ast_format *format, const char *name, const char *value)
+{
+	struct celt_attr *attr;
+	unsigned int val;
+
+	if (!format->attribute_data) {
+		format->attribute_data = ast_calloc(1, sizeof(*attr));
+	}
+	attr = format->attribute_data;
+	if (!attr) {
 		return -1;
 	}
-	return 0;
-}
-
-static int celt_isset(const struct ast_format_attr *fattr, va_list ap)
-{
-	enum celt_attr_keys key;
-	const struct celt_attr *attr = (struct celt_attr *) fattr;
-
-	for (key = va_arg(ap, int);
-		key != AST_FORMAT_ATTR_END;
-		key = va_arg(ap, int))
-	{
-		switch (key) {
-		case CELT_ATTR_KEY_SAMP_RATE:
-			if (attr->samplerate != (va_arg(ap, int))) {
-				return -1;
-			}
-			break;
-		case CELT_ATTR_KEY_MAX_BITRATE:
-			if (attr->maxbitrate != (va_arg(ap, int))) {
-				return -1;
-			}
-			break;
-		case CELT_ATTR_KEY_FRAME_SIZE:
-			if (attr->framesize != (va_arg(ap, int))) {
-				return -1;
-			}
-			break;
-		default:
-			ast_log(LOG_WARNING, "unknown attribute type %d\n", key);
+
+	if (!strcasecmp(name, "sample_rate")) {
+		if (sscanf(value, "%30u", &val) != 1) {
+			ast_log(LOG_WARNING, "Unknown value '%s' for attribute type '%s'\n",
+				value, name);
 			return -1;
 		}
-	}
+		attr->samplerate = val;
+	} else if (!strcasecmp(name, "max_bitrate")) {
+		if (sscanf(value, "%30u", &val) != 1) {
+			ast_log(LOG_WARNING, "Unknown value '%s' for attribute type '%s'\n",
+				value, name);
+			return -1;
+		}
+		attr->maxbitrate = val;
+	} else if (!strcasecmp(name, "frame_size")) {
+		if (sscanf(value, "%30u", &val) != 1) {
+			ast_log(LOG_WARNING, "Unknown value '%s' for attribute type '%s'\n",
+				value, name);
+			return -1;
+		}
+		attr->framesize = val;
+	} else {
+		ast_log(LOG_WARNING, "Unknown attribute type '%s'\n", name);
+		return -1;
+	}
+
 	return 0;
 }
-static int celt_getjoint(const struct ast_format_attr *fattr1, const struct ast_format_attr *fattr2, struct ast_format_attr *result)
-{
-	struct celt_attr *attr1 = (struct celt_attr *) fattr1;
-	struct celt_attr *attr2 = (struct celt_attr *) fattr2;
-	struct celt_attr *attr_res = (struct celt_attr *) result;
-
-	/* sample rate is the only attribute that has any bearing on if joint capabilities exist or not */
-	if (attr1->samplerate != attr2->samplerate) {
-		return -1;
-	}
-	/* either would work, they are guaranteed the same at this point. */
-	attr_res->samplerate = attr1->samplerate;
-	/* Take the lowest max bitrate */
-	attr_res->maxbitrate = MIN(attr1->maxbitrate, attr2->maxbitrate);
-
-	attr_res->framesize = attr2->framesize; /* TODO figure out what joint framesize means */
-	return 0;
-}
-
-static void celt_set(struct ast_format_attr *fattr, va_list ap)
-{
-	enum celt_attr_keys key;
-	struct celt_attr *attr = (struct celt_attr *) fattr;
-
-	for (key = va_arg(ap, int);
-		key != AST_FORMAT_ATTR_END;
-		key = va_arg(ap, int))
-	{
-		switch (key) {
-		case CELT_ATTR_KEY_SAMP_RATE:
-			attr->samplerate = (va_arg(ap, int));
-			break;
-		case CELT_ATTR_KEY_MAX_BITRATE:
-			attr->maxbitrate = (va_arg(ap, int));
-			break;
-		case CELT_ATTR_KEY_FRAME_SIZE:
-			attr->framesize = (va_arg(ap, int));
-			break;
-		default:
-			ast_log(LOG_WARNING, "unknown attribute type %d\n", key);
-		}
-	}
-}
-
-static struct ast_format_attr_interface celt_interface = {
-	.id = AST_FORMAT_CELT,
-	.format_attr_cmp = celt_cmp,
-	.format_attr_get_joint = celt_getjoint,
-	.format_attr_set = celt_set,
-	.format_attr_isset = celt_isset,
-	.format_attr_get_val = celt_get_val,
-	.format_attr_sdp_parse = celt_sdp_parse,
-	.format_attr_sdp_generate = celt_sdp_generate,
+
+static struct ast_format_interface celt_interface = {
+	.format_destroy = celt_destroy,
+	.format_cmp = celt_cmp,
+	.format_get_joint = celt_getjoint,
+	.format_attribute_set = celt_set,
+	.format_sdp_parse = celt_sdp_parse,
+	.format_sdp_generate = celt_sdp_generate,
 };
 
 static int load_module(void)
 {
-	if (ast_format_attr_reg_interface(&celt_interface)) {
+	if (ast_format_interface_register("celt", &celt_interface)) {
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
@@ -199,7 +191,6 @@
 
 static int unload_module(void)
 {
-	ast_format_attr_unreg_interface(&celt_interface);
 	return 0;
 }
 




More information about the asterisk-commits mailing list