diff options
author | David Vossel <dvossel@digium.com> | 2011-07-07 19:39:17 +0000 |
---|---|---|
committer | David Vossel <dvossel@digium.com> | 2011-07-07 19:39:17 +0000 |
commit | 513c680b8c13bc644d9a12ec818c42b7ab5ee072 (patch) | |
tree | 2ad8099f4523512b84dacc6d135c659bddf247eb /main | |
parent | b5609161e076a7357c7d9e96d889e11c72edbfa3 (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')
-rw-r--r-- | main/channel.c | 12 | ||||
-rw-r--r-- | main/format.c | 54 | ||||
-rw-r--r-- | main/frame.c | 4 | ||||
-rw-r--r-- | main/rtp_engine.c | 4 |
4 files changed, 70 insertions, 4 deletions
diff --git a/main/channel.c b/main/channel.c index ed84da1e6..902c79d85 100644 --- a/main/channel.c +++ b/main/channel.c @@ -1081,6 +1081,8 @@ struct ast_format *ast_best_codec(struct ast_format_cap *cap, struct ast_format AST_FORMAT_SPEEX, /*! SILK is pretty awesome. */ AST_FORMAT_SILK, + /*! CELT supports crazy high sample rates */ + AST_FORMAT_CELT, /*! Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough to use it */ AST_FORMAT_LPC10, @@ -5019,12 +5021,13 @@ int ast_write(struct ast_channel *chan, struct ast_frame *fr) from the single frame we passed in; if so, feed each one of them to the channel, freeing each one after it has been written */ if ((f != fr) && AST_LIST_NEXT(f, frame_list)) { - struct ast_frame *cur, *next; + struct ast_frame *cur, *next = NULL; unsigned int skip = 0; - for (cur = f, next = AST_LIST_NEXT(cur, frame_list); - cur; - cur = next, next = cur ? AST_LIST_NEXT(cur, frame_list) : NULL) { + cur = f; + while (cur) { + next = AST_LIST_NEXT(cur, frame_list); + AST_LIST_NEXT(cur, frame_list) = NULL; if (!skip) { if ((res = chan->tech->write(chan, cur)) < 0) { chan->_softhangup |= AST_SOFTHANGUP_DEV; @@ -5037,6 +5040,7 @@ int ast_write(struct ast_channel *chan, struct ast_frame *fr) } } ast_frfree(cur); + cur = next; } /* reset f so the code below doesn't attempt to free it */ 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); } diff --git a/main/frame.c b/main/frame.c index bb32386ca..b664e2e84 100644 --- a/main/frame.c +++ b/main/frame.c @@ -1011,6 +1011,10 @@ int ast_codec_get_samples(struct ast_frame *f) } else { return 160; } + case AST_FORMAT_CELT: + /* TODO The assumes 20ms delivery right now, which is incorrect */ + samples = ast_format_rate(&f->subclass.format) / 50; + break; default: ast_log(LOG_WARNING, "Unable to calculate samples for format %s\n", ast_getformatname(&f->subclass.format)); } diff --git a/main/rtp_engine.c b/main/rtp_engine.c index a3d9c4d8e..4ad3c9024 100644 --- a/main/rtp_engine.c +++ b/main/rtp_engine.c @@ -1931,6 +1931,10 @@ int ast_rtp_engine_load_format(const struct ast_format *format) set_next_mime_type(format, 0, "audio", "SILK", ast_format_rate(format)); add_static_payload(-1, format, 0); break; + case AST_FORMAT_CELT: + set_next_mime_type(format, 0, "audio", "CELT", ast_format_rate(format)); + add_static_payload(-1, format, 0); + break; default: break; } |