summaryrefslogtreecommitdiff
path: root/main/codec_builtin.c
diff options
context:
space:
mode:
authorMark Michelson <mmichelson@digium.com>2016-06-30 15:58:53 -0500
committerMark Michelson <mmichelson@digium.com>2016-07-14 15:59:49 -0500
commit273052f40498378d3f2d3548347a243df68ee9a4 (patch)
tree3d959becc0aa82c887a4b70643d5481a5ce7c797 /main/codec_builtin.c
parent3cf33dd4e7e886383531335efda3baca728b1f51 (diff)
Update support for SILK format.
This commit adds scaffolding in order to support the SILK audio format on calls. Roughly, this is what is added: * Cached silk formats. One for each possible sample rate. * ast_codec structures for each possible sample rate. * RTP payload mappings for "SILK". In addition, this change overhauls the res_format_attr_silk file in the following ways: * The "samplerate" attribute is scrapped. That's native to the format. * There are far more checks to ensure that attributes have been allocated before attempting to reference them. * We do not SDP fmtp lines for attributes set to 0. These changes make way to be able to install a codec_silk module and have it actually work. It also should allow for passthrough silk calls in Asterisk. Change-Id: Ieeb39c95a9fecc9246bcfd3c45a6c9b51c59380e
Diffstat (limited to 'main/codec_builtin.c')
-rw-r--r--main/codec_builtin.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/main/codec_builtin.c b/main/codec_builtin.c
index 913164328..50fbf555c 100644
--- a/main/codec_builtin.c
+++ b/main/codec_builtin.c
@@ -772,6 +772,65 @@ static struct ast_codec t140 = {
.type = AST_MEDIA_TYPE_TEXT,
};
+static int silk_samples(struct ast_frame *frame)
+{
+ /* XXX This is likely not at all what's intended from this callback. However,
+ * since SILK is variable bit rate, I have no idea how to take a frame of data
+ * and determine the number of samples present. Instead, we base this on the
+ * sample rate of the codec and the expected number of samples to receive in 20ms.
+ * In testing, this has worked just fine.
+ */
+ return ast_format_get_sample_rate(frame->subclass.format) / 50;
+}
+
+static struct ast_codec silk8 = {
+ .name = "silk",
+ .description = "SILK Codec (8 KHz)",
+ .type = AST_MEDIA_TYPE_AUDIO,
+ .sample_rate = 8000,
+ .minimum_ms = 20,
+ .maximum_ms = 100,
+ .default_ms = 20,
+ .minimum_bytes = 160,
+ .samples_count = silk_samples
+};
+
+static struct ast_codec silk12 = {
+ .name = "silk",
+ .description = "SILK Codec (12 KHz)",
+ .type = AST_MEDIA_TYPE_AUDIO,
+ .sample_rate = 12000,
+ .minimum_ms = 20,
+ .maximum_ms = 100,
+ .default_ms = 20,
+ .minimum_bytes = 240,
+ .samples_count = silk_samples
+};
+
+static struct ast_codec silk16 = {
+ .name = "silk",
+ .description = "SILK Codec (16 KHz)",
+ .type = AST_MEDIA_TYPE_AUDIO,
+ .sample_rate = 16000,
+ .minimum_ms = 20,
+ .maximum_ms = 100,
+ .default_ms = 20,
+ .minimum_bytes = 320,
+ .samples_count = silk_samples
+};
+
+static struct ast_codec silk24 = {
+ .name = "silk",
+ .description = "SILK Codec (24 KHz)",
+ .type = AST_MEDIA_TYPE_AUDIO,
+ .sample_rate = 24000,
+ .minimum_ms = 20,
+ .maximum_ms = 100,
+ .default_ms = 20,
+ .minimum_bytes = 480,
+ .samples_count = silk_samples
+};
+
#define CODEC_REGISTER_AND_CACHE(codec) \
({ \
int __res_ ## __LINE__ = 0; \
@@ -843,6 +902,10 @@ int ast_codec_builtin_init(void)
res |= CODEC_REGISTER_AND_CACHE(t140red);
res |= CODEC_REGISTER_AND_CACHE(t140);
res |= CODEC_REGISTER_AND_CACHE(none);
+ res |= CODEC_REGISTER_AND_CACHE_NAMED("silk8", silk8);
+ res |= CODEC_REGISTER_AND_CACHE_NAMED("silk12", silk12);
+ res |= CODEC_REGISTER_AND_CACHE_NAMED("silk16", silk16);
+ res |= CODEC_REGISTER_AND_CACHE_NAMED("silk24", silk24);
return res;
}