summaryrefslogtreecommitdiff
path: root/main/format.c
diff options
context:
space:
mode:
authorDavid Vossel <dvossel@digium.com>2011-07-07 19:39:17 +0000
committerDavid Vossel <dvossel@digium.com>2011-07-07 19:39:17 +0000
commit513c680b8c13bc644d9a12ec818c42b7ab5ee072 (patch)
tree2ad8099f4523512b84dacc6d135c659bddf247eb /main/format.c
parentb5609161e076a7357c7d9e96d889e11c72edbfa3 (diff)
Adds pass-through support for codec CELT.
This patch adds pass-through support for CELT. CELT formats are defined in codecs.conf and can be configured to any sample rate a CELT endpoint supports. This patch also addresses a crash in channel.c resulting from a frame list being freed incorrectly. This crash was discovered while testing a CELT translator which had to split encoded audio into multiple frames. The codec translator is not a part of this patch, but may be contributed in the future. Review: https://reviewboard.asterisk.org/r/1294/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@326855 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/format.c')
-rw-r--r--main/format.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/main/format.c b/main/format.c
index 28b15ae21..1c60ab770 100644
--- a/main/format.c
+++ b/main/format.c
@@ -748,6 +748,15 @@ int ast_format_rate(const struct ast_format *format)
} else {
return 8000;
}
+ case AST_FORMAT_CELT:
+ {
+ int samplerate;
+ if (!(ast_format_get_value(format,
+ CELT_ATTR_KEY_SAMP_RATE,
+ &samplerate))) {
+ return samplerate;
+ }
+ }
default:
return 8000;
}
@@ -1085,6 +1094,32 @@ init_cleanup:
return -1;
}
+static int custom_celt_format(struct ast_format_list *entry, unsigned int maxbitrate, unsigned int framesize)
+{
+ if (!entry->samplespersecond) {
+ ast_log(LOG_WARNING, "Custom CELT format definition '%s' requires sample rate to be defined.\n", entry->name);
+ }
+ ast_format_set(&entry->format, AST_FORMAT_CELT, 0);
+ if (!has_interface(&entry->format)) {
+ return -1;
+ }
+
+ snprintf(entry->desc, sizeof(entry->desc), "CELT Custom Format %dkhz", entry->samplespersecond/1000);
+
+ ast_format_append(&entry->format,
+ CELT_ATTR_KEY_SAMP_RATE, entry->samplespersecond,
+ CELT_ATTR_KEY_MAX_BITRATE, maxbitrate,
+ CELT_ATTR_KEY_FRAME_SIZE, framesize,
+ AST_FORMAT_ATTR_END);
+
+ entry->fr_len = 80;
+ entry->min_ms = 20;
+ entry->max_ms = 20;
+ entry->inc_ms = 20;
+ entry->def_ms = 20;
+ return 0;
+}
+
static int custom_silk_format(struct ast_format_list *entry, unsigned int maxbitrate, int usedtx, int usefec, int packetloss_percentage)
{
if (!entry->samplespersecond) {
@@ -1144,6 +1179,8 @@ static int conf_process_format_name(const char *name, enum ast_format_id *id)
{
if (!strcasecmp(name, "silk")) {
*id = AST_FORMAT_SILK;
+ } else if (!strcasecmp(name, "celt")) {
+ *id = AST_FORMAT_CELT;
} else {
*id = 0;
return -1;
@@ -1163,8 +1200,14 @@ static int conf_process_sample_rate(const char *rate, unsigned int *result)
*result = 24000;
} else if (!strcasecmp(rate, "32000")) {
*result = 32000;
+ } else if (!strcasecmp(rate, "44100")) {
+ *result = 44100;
} else if (!strcasecmp(rate, "48000")) {
*result = 48000;
+ } else if (!strcasecmp(rate, "96000")) {
+ *result = 96000;
+ } else if (!strcasecmp(rate, "192000")) {
+ *result = 192000;
} else {
*result = 0;
return -1;
@@ -1184,6 +1227,7 @@ static int load_format_config(void)
struct {
enum ast_format_id id;
unsigned int maxbitrate;
+ unsigned int framesize;
unsigned int packetloss_percentage;
int usefec;
int usedtx;
@@ -1221,6 +1265,11 @@ static int load_format_config(void)
ast_log(LOG_WARNING, "maxbitrate '%s' at line %d of %s is not supported.\n",
var->value, var->lineno, FORMAT_CONFIG);
}
+ } else if (!strcasecmp(var->name, "framesize")) {
+ if (sscanf(var->value, "%30u", &settings.framesize) != 1) {
+ ast_log(LOG_WARNING, "framesize '%s' at line %d of %s is not supported.\n",
+ var->value, var->lineno, FORMAT_CONFIG);
+ }
} else if (!strcasecmp(var->name, "dtx")) {
settings.usedtx = ast_true(var->value) ? 1 : 0;
} else if (!strcasecmp(var->name, "fec")) {
@@ -1239,6 +1288,11 @@ static int load_format_config(void)
add_it = 1;
}
break;
+ case AST_FORMAT_CELT:
+ if (!(custom_celt_format(&entry, settings.maxbitrate, settings.framesize))) {
+ add_it = 1;
+ }
+ break;
default:
ast_log(LOG_WARNING, "Can not create custom format %s\n", entry.name);
}