[Asterisk-code-review] siren: Add format attribute modules for Siren7 and Siren14. (asterisk[13])

Anonymous Coward asteriskteam at digium.com
Wed Jun 29 11:24:26 CDT 2016


Anonymous Coward #1000019 has submitted this change and it was merged.

Change subject: siren: Add format attribute modules for Siren7 and Siren14.
......................................................................


siren: Add format attribute modules for Siren7 and Siren14.

This change removes hardcoded SDP parsing and generation for
Siren7 and Siren14 from chan_sip and moves it to format attribute
modules so it can also be used by chan_pjsip.

With this the fmtp lines for both are added with the bitrate
information.

ASTERISK-26021

Change-Id: Ibb004eda37a14c0a35ef0613f6237977fc800037
---
M channels/chan_sip.c
A res/res_format_attr_siren14.c
A res/res_format_attr_siren7.c
3 files changed, 189 insertions(+), 25 deletions(-)

Approvals:
  Mark Michelson: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, but someone else must approve
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, approved



diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 16a28fe..a5aa6c3 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -11332,25 +11332,7 @@
 				ast_rtp_codecs_payloads_unset(newaudiortp, NULL, codec);
 			}
 
-			if (ast_format_cmp(format, ast_format_siren7) == AST_FORMAT_CMP_EQUAL) {
-				if (sscanf(fmtp_string, "bitrate=%30u", &bit_rate) == 1) {
-					if (bit_rate != 32000) {
-						ast_log(LOG_WARNING, "Got Siren7 offer at %u bps, but only 32000 bps supported; ignoring.\n", bit_rate);
-						ast_rtp_codecs_payloads_unset(newaudiortp, NULL, codec);
-					} else {
-						found = TRUE;
-					}
-				}
-			} else if (ast_format_cmp(format, ast_format_siren14) == AST_FORMAT_CMP_EQUAL) {
-				if (sscanf(fmtp_string, "bitrate=%30u", &bit_rate) == 1) {
-					if (bit_rate != 48000) {
-						ast_log(LOG_WARNING, "Got Siren14 offer at %u bps, but only 48000 bps supported; ignoring.\n", bit_rate);
-						ast_rtp_codecs_payloads_unset(newaudiortp, NULL, codec);
-					} else {
-						found = TRUE;
-					}
-				}
-			} else if (ast_format_cmp(format, ast_format_g719) == AST_FORMAT_CMP_EQUAL) {
+			if (ast_format_cmp(format, ast_format_g719) == AST_FORMAT_CMP_EQUAL) {
 				if (sscanf(fmtp_string, "bitrate=%30u", &bit_rate) == 1) {
 					if (bit_rate != 64000) {
 						ast_log(LOG_WARNING, "Got G.719 offer at %u bps, but only 64000 bps supported; ignoring.\n", bit_rate);
@@ -13009,12 +12991,6 @@
 	} else if (ast_format_cmp(format, ast_format_g723) == AST_FORMAT_CMP_EQUAL) {
 		/* Indicate that we don't support VAD (G.723.1 annex A) */
 		ast_str_append(a_buf, 0, "a=fmtp:%d annexa=no\r\n", rtp_code);
-	} else if (ast_format_cmp(format, ast_format_siren7) == AST_FORMAT_CMP_EQUAL) {
-		/* Indicate that we only expect 32Kbps */
-		ast_str_append(a_buf, 0, "a=fmtp:%d bitrate=32000\r\n", rtp_code);
-	} else if (ast_format_cmp(format, ast_format_siren14) == AST_FORMAT_CMP_EQUAL) {
-		/* Indicate that we only expect 48Kbps */
-		ast_str_append(a_buf, 0, "a=fmtp:%d bitrate=48000\r\n", rtp_code);
 	} else if (ast_format_cmp(format, ast_format_g719) == AST_FORMAT_CMP_EQUAL) {
 		/* Indicate that we only expect 64Kbps */
 		ast_str_append(a_buf, 0, "a=fmtp:%d bitrate=64000\r\n", rtp_code);
diff --git a/res/res_format_attr_siren14.c b/res/res_format_attr_siren14.c
new file mode 100644
index 0000000..dea13ae
--- /dev/null
+++ b/res/res_format_attr_siren14.c
@@ -0,0 +1,94 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2016, Digium, Inc.
+ *
+ * Joshua Colp <jcolp at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*!
+ * \file
+ * \brief Siren14 format attribute interface
+ *
+ * \author Joshua Colp <jcolp at digium.com>
+ */
+
+/*** MODULEINFO
+	<support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/module.h"
+#include "asterisk/format.h"
+
+/* Destroy is a required callback and must exist */
+static void siren14_destroy(struct ast_format *format)
+{
+}
+
+/* Clone is a required callback and must exist */
+static int siren14_clone(const struct ast_format *src, struct ast_format *dst)
+{
+	return 0;
+}
+
+static struct ast_format *siren14_parse_sdp_fmtp(const struct ast_format *format, const char *attributes)
+{
+	unsigned int val;
+
+	if (sscanf(attributes, "bitrate=%30u", &val) == 1) {
+		if (val != 48000) {
+			ast_log(LOG_WARNING, "Got siren14 offer at %u bps, but only 48000 bps supported; ignoring.\n", val);
+			return NULL;
+		}
+	}
+
+	/* We aren't modifying the format and once passed back it won't be touched, so use what we were given */
+	return ao2_bump((struct ast_format *)format);
+}
+
+static void siren14_generate_sdp_fmtp(const struct ast_format *format, unsigned int payload, struct ast_str **str)
+{
+	ast_str_append(str, 0, "a=fmtp:%u bitrate=48000\r\n", payload);
+}
+
+static struct ast_format_interface siren14_interface = {
+	.format_destroy = siren14_destroy,
+	.format_clone = siren14_clone,
+	.format_parse_sdp_fmtp = siren14_parse_sdp_fmtp,
+	.format_generate_sdp_fmtp = siren14_generate_sdp_fmtp,
+};
+
+static int load_module(void)
+{
+	if (ast_format_interface_register("siren14", &siren14_interface)) {
+		return AST_MODULE_LOAD_DECLINE;
+	}
+
+	return AST_MODULE_LOAD_SUCCESS;
+}
+
+static int unload_module(void)
+{
+	return 0;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Siren14 Format Attribute Module",
+	.support_level = AST_MODULE_SUPPORT_CORE,
+	.load = load_module,
+	.unload = unload_module,
+	.load_pri = AST_MODPRI_CHANNEL_DEPEND,
+);
diff --git a/res/res_format_attr_siren7.c b/res/res_format_attr_siren7.c
new file mode 100644
index 0000000..840de48
--- /dev/null
+++ b/res/res_format_attr_siren7.c
@@ -0,0 +1,94 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2016, Digium, Inc.
+ *
+ * Joshua Colp <jcolp at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*!
+ * \file
+ * \brief Siren7 format attribute interface
+ *
+ * \author Joshua Colp <jcolp at digium.com>
+ */
+
+/*** MODULEINFO
+	<support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/module.h"
+#include "asterisk/format.h"
+
+/* Destroy is a required callback and must exist */
+static void siren7_destroy(struct ast_format *format)
+{
+}
+
+/* Clone is a required callback and must exist */
+static int siren7_clone(const struct ast_format *src, struct ast_format *dst)
+{
+	return 0;
+}
+
+static struct ast_format *siren7_parse_sdp_fmtp(const struct ast_format *format, const char *attributes)
+{
+	unsigned int val;
+
+	if (sscanf(attributes, "bitrate=%30u", &val) == 1) {
+		if (val != 32000) {
+			ast_log(LOG_WARNING, "Got Siren7 offer at %u bps, but only 32000 bps supported; ignoring.\n", val);
+			return NULL;
+		}
+	}
+
+	/* We aren't modifying the format and once passed back it won't be touched, so use what we were given */
+	return ao2_bump((struct ast_format *)format);
+}
+
+static void siren7_generate_sdp_fmtp(const struct ast_format *format, unsigned int payload, struct ast_str **str)
+{
+	ast_str_append(str, 0, "a=fmtp:%u bitrate=32000\r\n", payload);
+}
+
+static struct ast_format_interface siren7_interface = {
+	.format_destroy = siren7_destroy,
+	.format_clone = siren7_clone,
+	.format_parse_sdp_fmtp = siren7_parse_sdp_fmtp,
+	.format_generate_sdp_fmtp = siren7_generate_sdp_fmtp,
+};
+
+static int load_module(void)
+{
+	if (ast_format_interface_register("siren7", &siren7_interface)) {
+		return AST_MODULE_LOAD_DECLINE;
+	}
+
+	return AST_MODULE_LOAD_SUCCESS;
+}
+
+static int unload_module(void)
+{
+	return 0;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Siren7 Format Attribute Module",
+	.support_level = AST_MODULE_SUPPORT_CORE,
+	.load = load_module,
+	.unload = unload_module,
+	.load_pri = AST_MODPRI_CHANNEL_DEPEND,
+);

-- 
To view, visit https://gerrit.asterisk.org/3089
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ibb004eda37a14c0a35ef0613f6237977fc800037
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Alexander Traud <pabstraud at compuserve.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>



More information about the asterisk-code-review mailing list