[Asterisk-code-review] res rtp asterisk: Swap byte-order when sending signed linear (asterisk[14])
Sean Bright
asteriskteam at digium.com
Tue Jan 31 13:09:07 CST 2017
Sean Bright has uploaded a new change for review. ( https://gerrit.asterisk.org/4853 )
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/53/4853/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 a5ca038..bc93351 100644
--- a/include/asterisk/format.h
+++ b/include/asterisk/format.h
@@ -338,6 +338,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 4f17505..dd02813 100644
--- a/main/codec_builtin.c
+++ b/main/codec_builtin.c
@@ -38,6 +38,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);
@@ -266,6 +267,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 = {
@@ -280,6 +282,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 = {
@@ -294,6 +297,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 = {
@@ -308,6 +312,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 = {
@@ -322,6 +327,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 = {
@@ -336,6 +342,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 = {
@@ -350,6 +357,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 = {
@@ -364,6 +372,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 = {
@@ -378,6 +387,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 cc9ac45..31e53a0 100644
--- a/main/format.c
+++ b/main/format.c
@@ -380,6 +380,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 6222f12..aa8c432 100644
--- a/res/res_rtp_asterisk.c
+++ b/res/res_rtp_asterisk.c
@@ -3631,7 +3631,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));
@@ -3640,6 +3646,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/4853
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I868449617d1a7819578f218c8c6b2111ad84f5a9
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 14
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
More information about the asterisk-code-review
mailing list