summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorJoshua Colp <jcolp@digium.com>2016-09-04 14:11:34 -0500
committerGerrit Code Review <gerrit2@gerrit.digium.api>2016-09-04 14:11:34 -0500
commite34f299a9672f829ee8d6652d221700fe2c6c56d (patch)
tree06e7940a019b1177c7aadbe7810c9e34a6ea17f7 /main
parentf87008f11adb6652f13fbca965a7b580ab0dac93 (diff)
parent2e79f52d7116e5529ab78972cee8081b6ffe6878 (diff)
Merge "codecs: Add Codec 2 mode 2400."
Diffstat (limited to 'main')
-rw-r--r--main/codec_builtin.c25
-rw-r--r--main/format_cache.c10
2 files changed, 34 insertions, 1 deletions
diff --git a/main/codec_builtin.c b/main/codec_builtin.c
index 15147980d..facb5a84c 100644
--- a/main/codec_builtin.c
+++ b/main/codec_builtin.c
@@ -108,6 +108,30 @@ static struct ast_codec g723 = {
.get_length = g723_length,
};
+static int codec2_samples(struct ast_frame *frame)
+{
+ return 160 * (frame->datalen / 6);
+}
+
+static int codec2_length(unsigned int samples)
+{
+ return (samples / 160) * 6;
+}
+
+static struct ast_codec codec2 = {
+ .name = "codec2",
+ .description = "Codec 2",
+ .type = AST_MEDIA_TYPE_AUDIO,
+ .sample_rate = 8000,
+ .minimum_ms = 20,
+ .maximum_ms = 300,
+ .default_ms = 20,
+ .minimum_bytes = 6,
+ .samples_count = codec2_samples,
+ .get_length = codec2_length,
+ .smooth = 1,
+};
+
static int none_samples(struct ast_frame *frame)
{
return frame->datalen;
@@ -869,6 +893,7 @@ int ast_codec_builtin_init(void)
{
int res = 0;
+ res |= CODEC_REGISTER_AND_CACHE(codec2);
res |= CODEC_REGISTER_AND_CACHE(g723);
res |= CODEC_REGISTER_AND_CACHE(ulaw);
res |= CODEC_REGISTER_AND_CACHE(alaw);
diff --git a/main/format_cache.c b/main/format_cache.c
index b4d426092..c704f1c37 100644
--- a/main/format_cache.c
+++ b/main/format_cache.c
@@ -218,6 +218,11 @@ struct ast_format *ast_format_siren7;
struct ast_format *ast_format_opus;
/*!
+ * \brief Built-in cached codec2 format.
+ */
+struct ast_format *ast_format_codec2;
+
+/*!
* \brief Built-in cached t140 format.
*/
struct ast_format *ast_format_t140;
@@ -328,6 +333,7 @@ static void format_cache_shutdown(void)
ao2_replace(ast_format_testlaw, NULL);
ao2_replace(ast_format_g719, NULL);
ao2_replace(ast_format_opus, NULL);
+ ao2_replace(ast_format_codec2, NULL);
ao2_replace(ast_format_jpeg, NULL);
ao2_replace(ast_format_png, NULL);
ao2_replace(ast_format_h261, NULL);
@@ -360,7 +366,9 @@ int ast_format_cache_init(void)
static void set_cached_format(const char *name, struct ast_format *format)
{
- if (!strcmp(name, "g723")) {
+ if (!strcmp(name, "codec2")) {
+ ao2_replace(ast_format_codec2, format);
+ } else if (!strcmp(name, "g723")) {
ao2_replace(ast_format_g723, format);
} else if (!strcmp(name, "ulaw")) {
ao2_replace(ast_format_ulaw, format);