Translate between various formats natively through DAHDI transcoding. More...
#include "asterisk.h"#include <fcntl.h>#include <netinet/in.h>#include <sys/ioctl.h>#include <sys/mman.h>#include <sys/poll.h>#include <dahdi/user.h>#include "asterisk/lock.h"#include "asterisk/translate.h"#include "asterisk/config.h"#include "asterisk/module.h"#include "asterisk/cli.h"#include "asterisk/channel.h"#include "asterisk/utils.h"#include "asterisk/linkedlists.h"#include "asterisk/ulaw.h"
Go to the source code of this file.
Data Structures | |
| struct | channel_usage |
| struct | codec_dahdi_pvt |
| struct | format_map |
| struct | translator |
| struct | translators |
| the list of translators More... | |
Defines | |
| #define | BUFFER_SIZE 8000 |
| #define | G723_SAMPLES 240 |
| #define | G729_SAMPLES 160 |
Functions | |
| static void | __reg_module (void) |
| static void | __unreg_module (void) |
| static void | build_translators (struct format_map *map, unsigned int dstfmts, unsigned int srcfmts) |
| static int | dahdi_decoder_framein (struct ast_trans_pvt *pvt, struct ast_frame *f) |
| static struct ast_frame * | dahdi_decoder_frameout (struct ast_trans_pvt *pvt) |
| static void | dahdi_destroy (struct ast_trans_pvt *pvt) |
| static int | dahdi_encoder_framein (struct ast_trans_pvt *pvt, struct ast_frame *f) |
| static struct ast_frame * | dahdi_encoder_frameout (struct ast_trans_pvt *pvt) |
| static int | dahdi_new (struct ast_trans_pvt *pvt) |
| static int | dahdi_translate (struct ast_trans_pvt *pvt, int dest, int source) |
| static void | dahdi_write_frame (struct codec_dahdi_pvt *dahdip, const uint8_t *buffer, const ssize_t count) |
| static void | drop_translator (int dst, int src) |
| static struct ast_frame * | fakesrc_sample (void) |
| static int | find_transcoders (void) |
| static char * | handle_cli_transcoder_show (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static int | is_encoder (struct translator *zt) |
| static int | lintoulaw (struct ast_trans_pvt *pvt, struct ast_frame *f) |
| static int | load_module (void) |
| static int | register_translator (int dst, int src) |
| static int | reload (void) |
| static int | ulawtolin (struct ast_trans_pvt *pvt, int samples) |
| static int | unload_module (void) |
| static void | unregister_translators (void) |
Variables | |
| static struct ast_module_info __MODULE_INFO_SECTION | __mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Generic DAHDI Transcoder Codec Translator" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .reload = reload, } |
| static struct ast_module_info * | ast_module_info = &__mod_info |
| static struct channel_usage | channels |
| static struct ast_cli_entry | cli [] |
| static struct format_map | global_format_map = { { { 0 } } } |
| static struct translators | translators |
Translate between various formats natively through DAHDI transcoding.
Definition in file codec_dahdi.c.
| #define BUFFER_SIZE 8000 |
Definition at line 54 of file codec_dahdi.c.
Referenced by register_translator().
| #define G723_SAMPLES 240 |
Definition at line 56 of file codec_dahdi.c.
Referenced by dahdi_translate().
| #define G729_SAMPLES 160 |
Definition at line 57 of file codec_dahdi.c.
Referenced by dahdi_translate().
| static void __reg_module | ( | void | ) | [static] |
Definition at line 650 of file codec_dahdi.c.
| static void __unreg_module | ( | void | ) | [static] |
Definition at line 650 of file codec_dahdi.c.
| static void build_translators | ( | struct format_map * | map, |
| unsigned int | dstfmts, | ||
| unsigned int | srcfmts | ||
| ) | [static] |
Definition at line 553 of file codec_dahdi.c.
References format_map::map, and register_translator().
Referenced by find_transcoders().
{
unsigned int src, dst;
for (src = 0; src < 32; src++) {
for (dst = 0; dst < 32; dst++) {
if (!(srcfmts & (1 << src)))
continue;
if (!(dstfmts & (1 << dst)))
continue;
if (global_format_map.map[dst][src])
continue;
if (!register_translator(dst, src))
map->map[dst][src] = 1;
}
}
}
| static int dahdi_decoder_framein | ( | struct ast_trans_pvt * | pvt, |
| struct ast_frame * | f | ||
| ) | [static] |
Definition at line 275 of file codec_dahdi.c.
References ast_log(), dahdi_write_frame(), ast_frame::data, ast_trans_pvt::datalen, ast_frame::datalen, codec_dahdi_pvt::fake, LOG_ERROR, ast_frame::ptr, ast_trans_pvt::pvt, codec_dahdi_pvt::required_samples, ast_frame::samples, ast_trans_pvt::samples, and ast_frame::subclass.
Referenced by register_translator().
{
struct codec_dahdi_pvt *dahdip = pvt->pvt;
if (!f->subclass) {
/* We're just faking a return for calculation purposes. */
dahdip->fake = 2;
pvt->samples = f->samples;
return 0;
}
if (!f->datalen) {
if (f->samples != dahdip->required_samples) {
ast_log(LOG_ERROR, "%d != %d %d\n", f->samples, dahdip->required_samples, f->datalen);
}
}
dahdi_write_frame(dahdip, f->data.ptr, f->datalen);
pvt->samples += f->samples;
pvt->datalen = 0;
return -1;
}
| static struct ast_frame* dahdi_decoder_frameout | ( | struct ast_trans_pvt * | pvt | ) | [static, read] |
Definition at line 297 of file codec_dahdi.c.
References AST_FRAME_VOICE, AST_FRFLAG_FROM_TRANSLATOR, AST_FRIENDLY_OFFSET, ast_log(), ast_set_flag, ast_translator::buf_size, ast_trans_pvt::c, ast_frame::data, ast_trans_pvt::datalen, ast_frame::datalen, ast_translator::dstfmt, errno, ast_trans_pvt::f, codec_dahdi_pvt::fake, codec_dahdi_pvt::fd, ast_frame::frametype, LOG_ERROR, ast_frame::mallocd, ast_translator::name, ast_frame::offset, ast_trans_pvt::outbuf, ast_frame::ptr, ast_trans_pvt::pvt, codec_dahdi_pvt::required_samples, ast_trans_pvt::samples, ast_frame::samples, codec_dahdi_pvt::softslin, ast_frame::src, ast_frame::subclass, ast_trans_pvt::t, codec_dahdi_pvt::ulaw_buffer, and ulawtolin().
Referenced by register_translator().
{
int res;
struct codec_dahdi_pvt *dahdip = pvt->pvt;
if (2 == dahdip->fake) {
dahdip->fake = 1;
pvt->f.frametype = AST_FRAME_VOICE;
pvt->f.subclass = 0;
pvt->f.samples = dahdip->required_samples;
pvt->f.data.ptr = NULL;
pvt->f.offset = 0;
pvt->f.datalen = 0;
pvt->f.mallocd = 0;
ast_set_flag(&pvt->f, AST_FRFLAG_FROM_TRANSLATOR);
pvt->samples = 0;
return &pvt->f;
} else if (1 == dahdip->fake) {
pvt->samples = 0;
dahdip->fake = 0;
return NULL;
}
/* Let's check to see if there is a new frame for us.... */
if (dahdip->softslin) {
res = read(dahdip->fd, dahdip->ulaw_buffer, sizeof(dahdip->ulaw_buffer));
} else {
res = read(dahdip->fd, pvt->outbuf.c + pvt->datalen, pvt->t->buf_size - pvt->datalen);
}
if (-1 == res) {
if (EWOULDBLOCK == errno) {
/* Nothing waiting... */
return NULL;
} else {
ast_log(LOG_ERROR, "Failed to read from transcoder: %s\n", strerror(errno));
return NULL;
}
} else {
if (dahdip->softslin) {
ulawtolin(pvt, res);
pvt->f.datalen = res * 2;
} else {
pvt->f.datalen = res;
}
pvt->datalen = 0;
pvt->f.frametype = AST_FRAME_VOICE;
pvt->f.subclass = 1 << (pvt->t->dstfmt);
pvt->f.mallocd = 0;
pvt->f.offset = AST_FRIENDLY_OFFSET;
pvt->f.src = pvt->t->name;
pvt->f.data.ptr = pvt->outbuf.c;
pvt->f.samples = res;
ast_set_flag(&pvt->f, AST_FRFLAG_FROM_TRANSLATOR);
pvt->samples = 0;
return &pvt->f;
}
/* Shouldn't get here... */
return NULL;
}
| static void dahdi_destroy | ( | struct ast_trans_pvt * | pvt | ) | [static] |
Definition at line 361 of file codec_dahdi.c.
References ast_atomic_fetchadd_int(), AST_FORMAT_G723_1, AST_FORMAT_G729A, codec_dahdi_pvt::fd, codec_dahdi_pvt::fmts, and ast_trans_pvt::pvt.
Referenced by register_translator().
{
struct codec_dahdi_pvt *dahdip = pvt->pvt;
switch (dahdip->fmts.dstfmt) {
case AST_FORMAT_G729A:
case AST_FORMAT_G723_1:
ast_atomic_fetchadd_int(&channels.encoders, -1);
break;
default:
ast_atomic_fetchadd_int(&channels.decoders, -1);
break;
}
close(dahdip->fd);
}
| static int dahdi_encoder_framein | ( | struct ast_trans_pvt * | pvt, |
| struct ast_frame * | f | ||
| ) | [static] |
Definition at line 178 of file codec_dahdi.c.
References ast_log(), dahdi_write_frame(), ast_frame::data, ast_trans_pvt::datalen, codec_dahdi_pvt::fake, lintoulaw(), LOG_ERROR, ast_frame::ptr, ast_trans_pvt::pvt, codec_dahdi_pvt::required_samples, ast_frame::samples, ast_trans_pvt::samples, codec_dahdi_pvt::samples_in_buffer, codec_dahdi_pvt::softslin, ast_frame::subclass, and codec_dahdi_pvt::ulaw_buffer.
Referenced by register_translator().
{
struct codec_dahdi_pvt *dahdip = pvt->pvt;
if (!f->subclass) {
/* We're just faking a return for calculation purposes. */
dahdip->fake = 2;
pvt->samples = f->samples;
return 0;
}
/* Buffer up the packets and send them to the hardware if we
* have enough samples set up. */
if (dahdip->softslin) {
if (lintoulaw(pvt, f)) {
return -1;
}
} else {
/* NOTE: If softslin support is not needed, and the sample
* size is equal to the required sample size, we wouldn't
* need this copy operation. But at the time this was
* written, only softslin is supported. */
if (dahdip->samples_in_buffer + f->samples > sizeof(dahdip->ulaw_buffer)) {
ast_log(LOG_ERROR, "Out of buffer space.\n");
return -1;
}
memcpy(&dahdip->ulaw_buffer[dahdip->samples_in_buffer], f->data.ptr, f->samples);
dahdip->samples_in_buffer += f->samples;
}
while (dahdip->samples_in_buffer > dahdip->required_samples) {
dahdi_write_frame(dahdip, dahdip->ulaw_buffer, dahdip->required_samples);
dahdip->samples_in_buffer -= dahdip->required_samples;
if (dahdip->samples_in_buffer) {
/* Shift any remaining bytes down. */
memmove(dahdip->ulaw_buffer, &dahdip->ulaw_buffer[dahdip->required_samples],
dahdip->samples_in_buffer);
}
}
pvt->samples += f->samples;
pvt->datalen = 0;
return -1;
}
| static struct ast_frame* dahdi_encoder_frameout | ( | struct ast_trans_pvt * | pvt | ) | [static, read] |
Definition at line 222 of file codec_dahdi.c.
References AST_FRAME_VOICE, AST_FRFLAG_FROM_TRANSLATOR, AST_FRIENDLY_OFFSET, ast_log(), ast_set_flag, ast_translator::buf_size, ast_trans_pvt::c, ast_frame::data, ast_trans_pvt::datalen, ast_frame::datalen, ast_translator::dstfmt, errno, ast_trans_pvt::f, codec_dahdi_pvt::fake, codec_dahdi_pvt::fd, ast_frame::frametype, LOG_ERROR, ast_frame::mallocd, ast_translator::name, ast_frame::offset, ast_trans_pvt::outbuf, ast_frame::ptr, ast_trans_pvt::pvt, codec_dahdi_pvt::required_samples, ast_trans_pvt::samples, ast_frame::samples, ast_frame::src, ast_frame::subclass, and ast_trans_pvt::t.
Referenced by register_translator().
{
struct codec_dahdi_pvt *dahdip = pvt->pvt;
int res;
if (2 == dahdip->fake) {
dahdip->fake = 1;
pvt->f.frametype = AST_FRAME_VOICE;
pvt->f.subclass = 0;
pvt->f.samples = dahdip->required_samples;
pvt->f.data.ptr = NULL;
pvt->f.offset = 0;
pvt->f.datalen = 0;
pvt->f.mallocd = 0;
ast_set_flag(&pvt->f, AST_FRFLAG_FROM_TRANSLATOR);
pvt->samples = 0;
return &pvt->f;
} else if (1 == dahdip->fake) {
dahdip->fake = 0;
return NULL;
}
res = read(dahdip->fd, pvt->outbuf.c + pvt->datalen, pvt->t->buf_size - pvt->datalen);
if (-1 == res) {
if (EWOULDBLOCK == errno) {
/* Nothing waiting... */
return NULL;
} else {
ast_log(LOG_ERROR, "Failed to read from transcoder: %s\n", strerror(errno));
return NULL;
}
} else {
pvt->f.datalen = res;
pvt->f.samples = dahdip->required_samples;
pvt->f.frametype = AST_FRAME_VOICE;
pvt->f.subclass = 1 << (pvt->t->dstfmt);
pvt->f.mallocd = 0;
pvt->f.offset = AST_FRIENDLY_OFFSET;
pvt->f.src = pvt->t->name;
pvt->f.data.ptr = pvt->outbuf.c;
ast_set_flag(&pvt->f, AST_FRFLAG_FROM_TRANSLATOR);
pvt->samples = 0;
pvt->datalen = 0;
return &pvt->f;
}
/* Shouldn't get here... */
return NULL;
}
| static int dahdi_new | ( | struct ast_trans_pvt * | pvt | ) | [static] |
Definition at line 451 of file codec_dahdi.c.
References dahdi_translate(), ast_translator::dstfmt, ast_translator::srcfmt, and ast_trans_pvt::t.
Referenced by register_translator().
{
return dahdi_translate(pvt, pvt->t->dstfmt, pvt->t->srcfmt);
}
| static int dahdi_translate | ( | struct ast_trans_pvt * | pvt, |
| int | dest, | ||
| int | source | ||
| ) | [static] |
Definition at line 378 of file codec_dahdi.c.
References ast_atomic_fetchadd_int(), ast_debug, AST_FORMAT_G723_1, AST_FORMAT_G729A, AST_FORMAT_SLINEAR, AST_FORMAT_ULAW, ast_log(), errno, codec_dahdi_pvt::fd, codec_dahdi_pvt::fmts, G723_SAMPLES, G729_SAMPLES, LOG_ERROR, LOG_WARNING, ast_trans_pvt::pvt, codec_dahdi_pvt::required_samples, and codec_dahdi_pvt::softslin.
Referenced by dahdi_new().
{
/* Request translation through zap if possible */
int fd;
struct codec_dahdi_pvt *dahdip = pvt->pvt;
int flags;
int tried_once = 0;
const char *dev_filename = "/dev/dahdi/transcode";
if ((fd = open(dev_filename, O_RDWR)) < 0) {
ast_log(LOG_ERROR, "Failed to open %s: %s\n", dev_filename, strerror(errno));
return -1;
}
dahdip->fmts.srcfmt = (1 << source);
dahdip->fmts.dstfmt = (1 << dest);
ast_debug(1, "Opening transcoder channel from %d to %d.\n", source, dest);
retry:
if (ioctl(fd, DAHDI_TC_ALLOCATE, &dahdip->fmts)) {
if ((ENODEV == errno) && !tried_once) {
/* We requested to translate to/from an unsupported
* format. Most likely this is because signed linear
* was not supported by any hardware devices even
* though this module always registers signed linear
* support. In this case we'll retry, requesting
* support for ULAW instead of signed linear and then
* we'll just convert from ulaw to signed linear in
* software. */
if (AST_FORMAT_SLINEAR == dahdip->fmts.srcfmt) {
ast_debug(1, "Using soft_slin support on source\n");
dahdip->softslin = 1;
dahdip->fmts.srcfmt = AST_FORMAT_ULAW;
} else if (AST_FORMAT_SLINEAR == dahdip->fmts.dstfmt) {
ast_debug(1, "Using soft_slin support on destination\n");
dahdip->softslin = 1;
dahdip->fmts.dstfmt = AST_FORMAT_ULAW;
}
tried_once = 1;
goto retry;
}
ast_log(LOG_ERROR, "Unable to attach to transcoder: %s\n", strerror(errno));
close(fd);
return -1;
}
flags = fcntl(fd, F_GETFL);
if (flags > - 1) {
if (fcntl(fd, F_SETFL, flags | O_NONBLOCK))
ast_log(LOG_WARNING, "Could not set non-block mode!\n");
}
dahdip->fd = fd;
dahdip->required_samples = ((dahdip->fmts.dstfmt|dahdip->fmts.srcfmt)&AST_FORMAT_G723_1) ? G723_SAMPLES : G729_SAMPLES;
switch (dahdip->fmts.dstfmt) {
case AST_FORMAT_G729A:
ast_atomic_fetchadd_int(&channels.encoders, +1);
break;
case AST_FORMAT_G723_1:
ast_atomic_fetchadd_int(&channels.encoders, +1);
break;
default:
ast_atomic_fetchadd_int(&channels.decoders, +1);
break;
}
return 0;
}
| static void dahdi_write_frame | ( | struct codec_dahdi_pvt * | dahdip, |
| const uint8_t * | buffer, | ||
| const ssize_t | count | ||
| ) | [static] |
Definition at line 159 of file codec_dahdi.c.
References ast_log(), errno, codec_dahdi_pvt::fd, LOG_ERROR, and option_verbose.
Referenced by dahdi_decoder_framein(), and dahdi_encoder_framein().
{
int res;
struct pollfd p = {0};
if (!count) return;
res = write(dahdip->fd, buffer, count);
if (option_verbose > 10) {
if (-1 == res) {
ast_log(LOG_ERROR, "Failed to write to transcoder: %s\n", strerror(errno));
}
if (count != res) {
ast_log(LOG_ERROR, "Requested write of %zd bytes, but only wrote %d bytes.\n", count, res);
}
}
p.fd = dahdip->fd;
p.events = POLLOUT;
res = poll(&p, 1, 50);
}
| static void drop_translator | ( | int | dst, |
| int | src | ||
| ) | [static] |
Definition at line 519 of file codec_dahdi.c.
References ast_free, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_unregister_translator(), ast_translator::dstfmt, translator::entry, format_map::map, ast_translator::srcfmt, and translator::t.
Referenced by find_transcoders().
{
struct translator *cur;
AST_LIST_LOCK(&translators);
AST_LIST_TRAVERSE_SAFE_BEGIN(&translators, cur, entry) {
if (cur->t.srcfmt != src)
continue;
if (cur->t.dstfmt != dst)
continue;
AST_LIST_REMOVE_CURRENT(entry);
ast_unregister_translator(&cur->t);
ast_free(cur);
global_format_map.map[dst][src] = 0;
break;
}
AST_LIST_TRAVERSE_SAFE_END;
AST_LIST_UNLOCK(&translators);
}
| static struct ast_frame* fakesrc_sample | ( | void | ) | [static, read] |
Definition at line 456 of file codec_dahdi.c.
References AST_FRAME_VOICE, f, and ast_frame::frametype.
Referenced by register_translator().
{
/* Don't bother really trying to test hardware ones. */
static struct ast_frame f = {
.frametype = AST_FRAME_VOICE,
.samples = 160,
.src = __PRETTY_FUNCTION__
};
return &f;
}
| static int find_transcoders | ( | void | ) | [static] |
Definition at line 574 of file codec_dahdi.c.
References ast_atomic_fetchadd_int(), AST_FORMAT_ALAW, AST_FORMAT_SLINEAR, AST_FORMAT_ULAW, ast_log(), ast_verbose(), build_translators(), drop_translator(), errno, LOG_ERROR, format_map::map, option_verbose, and VERBOSE_PREFIX_2.
Referenced by load_module().
{
struct dahdi_transcoder_info info = { 0, };
struct format_map map = { { { 0 } } };
int fd, res;
unsigned int x, y;
if ((fd = open("/dev/dahdi/transcode", O_RDWR)) < 0) {
ast_log(LOG_ERROR, "Failed to open /dev/dahdi/transcode: %s\n", strerror(errno));
return 0;
}
for (info.tcnum = 0; !(res = ioctl(fd, DAHDI_TC_GETINFO, &info)); info.tcnum++) {
if (option_verbose > 1)
ast_verbose(VERBOSE_PREFIX_2 "Found transcoder '%s'.\n", info.name);
/* Complex codecs need to support signed linear. If the
* hardware transcoder does not natively support signed linear
* format, we will emulate it in software directly in this
* module. Also, do not allow direct ulaw/alaw to complex
* codec translation, since that will prevent the generic PLC
* functions from working. */
if (info.dstfmts & (AST_FORMAT_ULAW | AST_FORMAT_ALAW)) {
info.dstfmts |= AST_FORMAT_SLINEAR;
info.dstfmts &= ~(AST_FORMAT_ULAW | AST_FORMAT_ALAW);
}
if (info.srcfmts & (AST_FORMAT_ULAW | AST_FORMAT_ALAW)) {
info.srcfmts |= AST_FORMAT_SLINEAR;
info.srcfmts &= ~(AST_FORMAT_ULAW | AST_FORMAT_ALAW);
}
build_translators(&map, info.dstfmts, info.srcfmts);
ast_atomic_fetchadd_int(&channels.total, info.numchannels / 2);
}
close(fd);
if (!info.tcnum && (option_verbose > 1))
ast_verbose(VERBOSE_PREFIX_2 "No hardware transcoders found.\n");
for (x = 0; x < 32; x++) {
for (y = 0; y < 32; y++) {
if (!map.map[x][y] && global_format_map.map[x][y])
drop_translator(x, y);
}
}
return 0;
}
| static char * handle_cli_transcoder_show | ( | struct ast_cli_entry * | e, |
| int | cmd, | ||
| struct ast_cli_args * | a | ||
| ) | [static] |
Definition at line 131 of file codec_dahdi.c.
References ast_cli_args::argc, ast_cli(), channels, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, channel_usage::decoders, channel_usage::encoders, ast_cli_args::fd, channel_usage::total, and ast_cli_entry::usage.
{
struct channel_usage copy;
switch (cmd) {
case CLI_INIT:
e->command = "transcoder show";
e->usage =
"Usage: transcoder show\n"
" Displays channel utilization of DAHDI transcoder(s).\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (a->argc != 2)
return CLI_SHOWUSAGE;
copy = channels;
if (copy.total == 0)
ast_cli(a->fd, "No DAHDI transcoders found.\n");
else
ast_cli(a->fd, "%d/%d encoders/decoders of %d channels are in use.\n", copy.encoders, copy.decoders, copy.total);
return CLI_SUCCESS;
}
| static int is_encoder | ( | struct translator * | zt | ) | [static] |
Definition at line 468 of file codec_dahdi.c.
References AST_FORMAT_ALAW, AST_FORMAT_SLINEAR, AST_FORMAT_ULAW, ast_translator::srcfmt, and translator::t.
Referenced by register_translator().
{
if (zt->t.srcfmt&(AST_FORMAT_ULAW|AST_FORMAT_ALAW|AST_FORMAT_SLINEAR)) {
return 1;
} else {
return 0;
}
}
| static int lintoulaw | ( | struct ast_trans_pvt * | pvt, |
| struct ast_frame * | f | ||
| ) | [static] |
Definition at line 111 of file codec_dahdi.c.
References AST_LIN2MU, ast_log(), ast_frame::data, LOG_ERROR, ast_frame::ptr, ast_trans_pvt::pvt, ast_frame::samples, codec_dahdi_pvt::samples_in_buffer, and codec_dahdi_pvt::ulaw_buffer.
Referenced by dahdi_encoder_framein().
{
struct codec_dahdi_pvt *dahdip = pvt->pvt;
int i = f->samples;
uint8_t *dst = &dahdip->ulaw_buffer[dahdip->samples_in_buffer];
int16_t *src = f->data.ptr;
if (dahdip->samples_in_buffer + i > sizeof(dahdip->ulaw_buffer)) {
ast_log(LOG_ERROR, "Out of buffer space!\n");
return -i;
}
while (i--) {
*dst++ = AST_LIN2MU(*src++);
}
dahdip->samples_in_buffer += f->samples;
return 0;
}
| static int load_module | ( | void | ) | [static] |
Definition at line 638 of file codec_dahdi.c.
References ARRAY_LEN, ast_cli_register_multiple(), AST_MODULE_LOAD_SUCCESS, ast_ulaw_init(), and find_transcoders().
{
ast_ulaw_init();
find_transcoders();
ast_cli_register_multiple(cli, ARRAY_LEN(cli));
return AST_MODULE_LOAD_SUCCESS;
}
| static int register_translator | ( | int | dst, |
| int | src | ||
| ) | [static] |
Definition at line 477 of file codec_dahdi.c.
References ast_calloc, ast_free, ast_getformatname(), AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_register_translator, ast_translator::buf_size, ast_translator::buffer_samples, BUFFER_SIZE, dahdi_decoder_framein(), dahdi_decoder_frameout(), dahdi_destroy(), dahdi_encoder_framein(), dahdi_encoder_frameout(), dahdi_new(), ast_translator::desc_size, ast_translator::destroy, ast_translator::dstfmt, translator::entry, fakesrc_sample(), ast_translator::framein, ast_translator::frameout, is_encoder(), format_map::map, ast_translator::name, ast_translator::native_plc, ast_translator::newpvt, ast_translator::sample, ast_translator::srcfmt, and translator::t.
Referenced by build_translators().
{
struct translator *zt;
int res;
if (!(zt = ast_calloc(1, sizeof(*zt)))) {
return -1;
}
snprintf((char *) (zt->t.name), sizeof(zt->t.name), "zap%sto%s",
ast_getformatname((1 << src)), ast_getformatname((1 << dst)));
zt->t.srcfmt = (1 << src);
zt->t.dstfmt = (1 << dst);
zt->t.buf_size = BUFFER_SIZE;
if (is_encoder(zt)) {
zt->t.framein = dahdi_encoder_framein;
zt->t.frameout = dahdi_encoder_frameout;
} else {
zt->t.framein = dahdi_decoder_framein;
zt->t.frameout = dahdi_decoder_frameout;
}
zt->t.destroy = dahdi_destroy;
zt->t.buffer_samples = 0;
zt->t.newpvt = dahdi_new;
zt->t.sample = fakesrc_sample;
zt->t.native_plc = 0;
zt->t.desc_size = sizeof(struct codec_dahdi_pvt);
if ((res = ast_register_translator(&zt->t))) {
ast_free(zt);
return -1;
}
AST_LIST_LOCK(&translators);
AST_LIST_INSERT_HEAD(&translators, zt, entry);
AST_LIST_UNLOCK(&translators);
global_format_map.map[dst][src] = 1;
return res;
}
| static int reload | ( | void | ) | [static] |
Definition at line 625 of file codec_dahdi.c.
References AST_MODULE_LOAD_SUCCESS.
{
return AST_MODULE_LOAD_SUCCESS;
}
| static int ulawtolin | ( | struct ast_trans_pvt * | pvt, |
| int | samples | ||
| ) | [static] |
Definition at line 95 of file codec_dahdi.c.
References AST_MULAW, ast_trans_pvt::datalen, ast_trans_pvt::i16, ast_trans_pvt::outbuf, ast_trans_pvt::pvt, and codec_dahdi_pvt::ulaw_buffer.
Referenced by dahdi_decoder_frameout().
{
struct codec_dahdi_pvt *dahdip = pvt->pvt;
int i = samples;
uint8_t *src = &dahdip->ulaw_buffer[0];
int16_t *dst = pvt->outbuf.i16 + pvt->datalen;
/* convert and copy in outbuf */
while (i--) {
*dst++ = AST_MULAW(*src++);
}
return 0;
}
| static int unload_module | ( | void | ) | [static] |
Definition at line 630 of file codec_dahdi.c.
References ARRAY_LEN, ast_cli_unregister_multiple(), and unregister_translators().
{
ast_cli_unregister_multiple(cli, ARRAY_LEN(cli));
unregister_translators();
return 0;
}
| static void unregister_translators | ( | void | ) | [static] |
Definition at line 541 of file codec_dahdi.c.
References ast_free, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, ast_unregister_translator(), translator::entry, and translator::t.
Referenced by unload_module().
{
struct translator *cur;
AST_LIST_LOCK(&translators);
while ((cur = AST_LIST_REMOVE_HEAD(&translators, entry))) {
ast_unregister_translator(&cur->t);
ast_free(cur);
}
AST_LIST_UNLOCK(&translators);
}
struct ast_module_info __MODULE_INFO_SECTION __mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Generic DAHDI Transcoder Codec Translator" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .reload = reload, } [static] |
Definition at line 650 of file codec_dahdi.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 650 of file codec_dahdi.c.
struct channel_usage channels [static] |
Referenced by check_header(), and handle_cli_transcoder_show().
struct ast_cli_entry cli[] [static] |
{
AST_CLI_DEFINE(handle_cli_transcoder_show, "Display DAHDI transcoder utilization.")
}
Definition at line 67 of file codec_dahdi.c.
struct format_map global_format_map = { { { 0 } } } [static] |
Definition at line 75 of file codec_dahdi.c.
struct translators translators [static] |