[Asterisk-code-review] res rtp asterisk: Swap byte-order when sending signed linear (asterisk[master])

Sean Bright asteriskteam at digium.com
Tue Jan 31 13:11:53 CST 2017


Sean Bright has uploaded a new change for review. ( https://gerrit.asterisk.org/4854 )

Change subject: res_rtp_asterisk:  Swap byte-order when sending signed linear
......................................................................

res_rtp_asterisk:  Swap byte-order when sending signed linear

Before Asterisk 13, signed linear was converted into network byte order by a
smoother before being sent over the network. We restore this behavior by adding
a 'smoother_flags' field to ast_codec and changing the 'smooth' field to a
single digit bitfield. We also add a flag that forces the creation of the
smoother.

ASTERISK-24858 #close
Reported-by: Frankie Chin

Change-Id: I868449617d1a7819578f218c8c6b2111ad84f5a9
---
M include/asterisk/codec.h
M include/asterisk/format.h
M include/asterisk/smoother.h
M main/codec_builtin.c
M main/format.c
M res/res_rtp_asterisk.c
6 files changed, 35 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/54/4854/1

diff --git a/include/asterisk/codec.h b/include/asterisk/codec.h
index 3873324..aad213f 100644
--- a/include/asterisk/codec.h
+++ b/include/asterisk/codec.h
@@ -74,7 +74,9 @@
 	 */
 	int (*get_length)(unsigned int samples);
 	/*! \brief Whether the media can be smoothed or not */
-	unsigned int smooth;
+	unsigned int smooth:1;
+	/*! \brief Flags for the smoother */
+	unsigned int smoother_flags:3;
 	/*! \brief The module that registered this codec */
 	struct ast_module *mod;
 };
diff --git a/include/asterisk/format.h b/include/asterisk/format.h
index b01592d..27a0ed2 100644
--- a/include/asterisk/format.h
+++ b/include/asterisk/format.h
@@ -356,6 +356,15 @@
 int ast_format_can_be_smoothed(const struct ast_format *format);
 
 /*!
+ * \brief Get smoother flags for this format
+ *
+ * \param format The media format
+ *
+ * \return smoother flags for the provided format
+ */
+int ast_format_get_smoother_flags(const struct ast_format *format);
+
+/*!
  * \brief Get the media type of a format
  *
  * \param format The media format
diff --git a/include/asterisk/smoother.h b/include/asterisk/smoother.h
index e63aa77..65ac889 100644
--- a/include/asterisk/smoother.h
+++ b/include/asterisk/smoother.h
@@ -33,6 +33,7 @@
 
 #define AST_SMOOTHER_FLAG_G729		(1 << 0)
 #define AST_SMOOTHER_FLAG_BE		(1 << 1)
+#define AST_SMOOTHER_FLAG_FORCED	(1 << 2)
 
 /*! \name AST_Smoother
 */
diff --git a/main/codec_builtin.c b/main/codec_builtin.c
index f622c91..902422f 100644
--- a/main/codec_builtin.c
+++ b/main/codec_builtin.c
@@ -36,6 +36,7 @@
 #include "asterisk/format.h"
 #include "asterisk/format_cache.h"
 #include "asterisk/frame.h"
+#include "asterisk/smoother.h"
 
 int __ast_codec_register_with_format(struct ast_codec *codec, const char *format_name,
 	struct ast_module *mod);
@@ -288,6 +289,7 @@
 	.samples_count = slin_samples,
 	.get_length = slin_length,
 	.smooth = 1,
+	.smoother_flags = AST_SMOOTHER_FLAG_BE | AST_SMOOTHER_FLAG_FORCED,
 };
 
 static struct ast_codec slin12 = {
@@ -302,6 +304,7 @@
 	.samples_count = slin_samples,
 	.get_length = slin_length,
 	.smooth = 1,
+	.smoother_flags = AST_SMOOTHER_FLAG_BE | AST_SMOOTHER_FLAG_FORCED,
 };
 
 static struct ast_codec slin16 = {
@@ -316,6 +319,7 @@
 	.samples_count = slin_samples,
 	.get_length = slin_length,
 	.smooth = 1,
+	.smoother_flags = AST_SMOOTHER_FLAG_BE | AST_SMOOTHER_FLAG_FORCED,
 };
 
 static struct ast_codec slin24 = {
@@ -330,6 +334,7 @@
 	.samples_count = slin_samples,
 	.get_length = slin_length,
 	.smooth = 1,
+	.smoother_flags = AST_SMOOTHER_FLAG_BE | AST_SMOOTHER_FLAG_FORCED,
 };
 
 static struct ast_codec slin32 = {
@@ -344,6 +349,7 @@
 	.samples_count = slin_samples,
 	.get_length = slin_length,
 	.smooth = 1,
+	.smoother_flags = AST_SMOOTHER_FLAG_BE | AST_SMOOTHER_FLAG_FORCED,
 };
 
 static struct ast_codec slin44 = {
@@ -358,6 +364,7 @@
 	.samples_count = slin_samples,
 	.get_length = slin_length,
 	.smooth = 1,
+	.smoother_flags = AST_SMOOTHER_FLAG_BE | AST_SMOOTHER_FLAG_FORCED,
 };
 
 static struct ast_codec slin48 = {
@@ -372,6 +379,7 @@
 	.samples_count = slin_samples,
 	.get_length = slin_length,
 	.smooth = 1,
+	.smoother_flags = AST_SMOOTHER_FLAG_BE | AST_SMOOTHER_FLAG_FORCED,
 };
 
 static struct ast_codec slin96 = {
@@ -386,6 +394,7 @@
 	.samples_count = slin_samples,
 	.get_length = slin_length,
 	.smooth = 1,
+	.smoother_flags = AST_SMOOTHER_FLAG_BE | AST_SMOOTHER_FLAG_FORCED,
 };
 
 static struct ast_codec slin192 = {
@@ -400,6 +409,7 @@
 	.samples_count = slin_samples,
 	.get_length = slin_length,
 	.smooth = 1,
+	.smoother_flags = AST_SMOOTHER_FLAG_BE | AST_SMOOTHER_FLAG_FORCED,
 };
 
 static int lpc10_samples(struct ast_frame *frame)
diff --git a/main/format.c b/main/format.c
index 5ae5ad9..09e736c 100644
--- a/main/format.c
+++ b/main/format.c
@@ -391,6 +391,11 @@
 	return format->codec->smooth;
 }
 
+int ast_format_get_smoother_flags(const struct ast_format *format)
+{
+	return format->codec->smoother_flags;
+}
+
 enum ast_media_type ast_format_get_type(const struct ast_format *format)
 {
 	return format->codec->type;
diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c
index c4608db..b7e2474 100644
--- a/res/res_rtp_asterisk.c
+++ b/res/res_rtp_asterisk.c
@@ -3629,7 +3629,13 @@
 
 	/* If no smoother is present see if we have to set one up */
 	if (!rtp->smoother && ast_format_can_be_smoothed(format)) {
+		unsigned int smoother_flags = ast_format_get_smoother_flags(format);
 		unsigned int framing_ms = ast_rtp_codecs_get_framing(ast_rtp_instance_get_codecs(instance));
+
+		int forced = smoother_flags & AST_SMOOTHER_FLAG_FORCED;
+		if (!framing_ms && forced) {
+			framing_ms = ast_format_get_default_ms(format);
+		}
 
 		if (framing_ms) {
 			rtp->smoother = ast_smoother_new((framing_ms * ast_format_get_minimum_bytes(format)) / ast_format_get_minimum_ms(format));
@@ -3638,6 +3644,7 @@
 					ast_format_get_name(format), framing_ms, ast_format_get_minimum_bytes(format));
 				return -1;
 			}
+			ast_smoother_set_flags(rtp->smoother, smoother_flags);
 		}
 	}
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I868449617d1a7819578f218c8c6b2111ad84f5a9
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>



More information about the asterisk-code-review mailing list