39 #include <netinet/in.h>
40 #include <sys/ioctl.h>
43 #include <dahdi/user.h>
55 #define BUFFER_SIZE 8000
57 #define G723_SAMPLES 240
58 #define G729_SAMPLES 160
59 #define ULAW_SAMPLES 160
74 unsigned int map[32][32];
88 struct dahdi_transcoder_formats fmts;
89 unsigned int softslin:1;
94 uint8_t ulaw_buffer[1024];
140 e->
command =
"transcoder show";
142 "Usage: transcoder show\n"
143 " Displays channel utilization of DAHDI transcoder(s).\n";
155 ast_cli(a->
fd,
"No DAHDI transcoders found.\n");
166 res = write(dahdip->
fd, buffer, count);
172 ast_log(
LOG_ERROR,
"Requested write of %zd bytes, but only wrote %d bytes.\n", count, res);
224 struct pollfd p = {0};
235 if (2 == dahdip->
fake) {
248 }
else if (1 == dahdip->
fake) {
259 if (EWOULDBLOCK ==
errno) {
317 if (2 == dahdip->
fake) {
328 }
else if (1 == dahdip->
fake) {
346 if (EWOULDBLOCK ==
errno) {
385 switch (dahdip->
fmts.dstfmt) {
405 const char *dev_filename =
"/dev/dahdi/transcode";
407 if ((fd = open(dev_filename, O_RDWR)) < 0) {
412 dahdip->
fmts.srcfmt = (1 << source);
413 dahdip->
fmts.dstfmt = (1 << dest);
415 ast_debug(1,
"Opening transcoder channel from %d to %d.\n", source, dest);
418 if (ioctl(fd, DAHDI_TC_ALLOCATE, &dahdip->
fmts)) {
419 if ((ENODEV ==
errno) && !tried_once) {
429 ast_debug(1,
"Using soft_slin support on source\n");
433 ast_debug(1,
"Using soft_slin support on destination\n");
446 flags = fcntl(fd, F_GETFL);
448 if (fcntl(fd, F_SETFL, flags | O_NONBLOCK))
456 switch (dahdip->
fmts.dstfmt) {
482 .src = __PRETTY_FUNCTION__
506 snprintf((
char *) (zt->
t.
name),
sizeof(zt->
t.
name),
"zap%sto%s",
534 global_format_map.
map[dst][src] = 1;
554 global_format_map.
map[dst][src] = 0;
575 unsigned int src, dst;
577 for (src = 0; src < 32; src++) {
578 for (dst = 0; dst < 32; dst++) {
579 if (!(srcfmts & (1 << src)))
582 if (!(dstfmts & (1 << dst)))
585 if (global_format_map.
map[dst][src])
589 map->
map[dst][src] = 1;
596 struct dahdi_transcoder_info info = { 0, };
601 if ((fd = open(
"/dev/dahdi/transcode", O_RDWR)) < 0) {
606 for (info.tcnum = 0; !(res = ioctl(fd, DAHDI_TC_GETINFO, &info)); info.tcnum++) {
635 for (x = 0; x < 32; x++) {
636 for (y = 0; y < 32; y++) {
637 if (!map.
map[x][y] && global_format_map.
map[x][y])
struct dahdi_transcoder_formats fmts
union ast_frame_subclass subclass
int datalen
actual space used in outbuf
static int register_translator(int dst, int src)
#define AST_CLI_DEFINE(fn, txt,...)
#define AST_LIST_LOCK(head)
Locks a list.
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
struct ast_frame *(* sample)(void)
union ast_trans_pvt::@213 outbuf
static struct ast_frame * dahdi_encoder_frameout(struct ast_trans_pvt *pvt)
Descriptor of a translator.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
uint8_t ulaw_buffer[1024]
Support for translation of data formats. translate.c.
#define AST_FORMAT_G723_1
descriptor for a cli entry.
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
static struct format_map global_format_map
void ast_verbose(const char *fmt,...)
static int is_encoder(struct translator *zt)
struct translator::@127 entry
Configuration File Parser.
static void unregister_translators(void)
static struct ast_frame * fakesrc_sample(void)
static int dahdi_new(struct ast_trans_pvt *pvt)
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
struct ast_frame * ast_frisolate(struct ast_frame *fr)
Makes a frame independent of any static storage.
void ast_cli(int fd, const char *fmt,...)
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
static int find_transcoders(void)
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return * the previous value of *p. This can be used to handle reference co...
struct ast_frame *(* frameout)(struct ast_trans_pvt *pvt)
static void dahdi_write_frame(struct codec_dahdi_pvt *dahdip, const uint8_t *buffer, const ssize_t count)
uint16_t required_samples
static int load_module(void)
static void dahdi_wait_for_packet(int fd)
#define ast_debug(level,...)
Log a DEBUG message.
u-Law to Signed linear conversion
General Asterisk PBX channel definitions.
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
static int dahdi_decoder_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
#define ast_register_translator(t)
See __ast_register_translator()
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
int ast_unregister_translator(struct ast_translator *t)
Unregister a translator Unregisters the given tranlator.
A set of macros to manage forward-linked lists.
static struct channel_usage channels
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
int buf_size
size of outbuf, in bytes. Mandatory. The wrapper code will also allocate an AST_FRIENDLY_OFFSET space...
#define AST_LIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a list of specified type, statically initialized.
static struct ast_cli_entry cli[]
static void build_translators(struct format_map *map, unsigned int dstfmts, unsigned int srcfmts)
char * ast_getformatname(format_t format)
Get the name of a format.
void ast_ulaw_init(void)
Set up mu-law conversion table.
static int dahdi_translate(struct ast_trans_pvt *pvt, int dest, int source)
static int unload_module(void)
Default structure for translators, with the basic fields and buffers, all allocated as part of the sa...
int(* newpvt)(struct ast_trans_pvt *)
static int dahdi_encoder_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
uint16_t samples_in_buffer
static int ulawtolin(struct ast_trans_pvt *pvt, int samples)
#define AST_FORMAT_SLINEAR
static void dahdi_destroy(struct ast_trans_pvt *pvt)
static void drop_translator(int dst, int src)
Standard Command Line Interface.
int(* framein)(struct ast_trans_pvt *pvt, struct ast_frame *in)
int ast_codec_get_samples(struct ast_frame *f)
Returns the number of samples contained in the frame.
int ast_cli_register_multiple(struct ast_cli_entry *e, int len)
Register multiple commands.
Data structure associated with a single frame of data.
static struct ast_frame * dahdi_decoder_frameout(struct ast_trans_pvt *pvt)
struct ast_translator * t
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
enum ast_frame_type frametype
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
union ast_frame::@172 data
static int lintoulaw(struct ast_trans_pvt *pvt, struct ast_frame *f)
static char * handle_cli_transcoder_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
uint16_t samples_written_to_hardware
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
void(* destroy)(struct ast_trans_pvt *pvt)
int buffer_samples
size of outbuf, in samples. Leave it 0 if you want the framein callback deal with the frame...