39#include <netinet/in.h>
42#include <dahdi/user.h>
55#define BUFFER_SIZE 8000
57#define G723_SAMPLES 240
58#define G729_SAMPLES 160
59#define ULAW_SAMPLES 160
62#ifndef DAHDI_FORMAT_MAX_AUDIO
64#define DAHDI_FORMAT_G723_1 (1 << 0)
66#define DAHDI_FORMAT_GSM (1 << 1)
68#define DAHDI_FORMAT_ULAW (1 << 2)
70#define DAHDI_FORMAT_ALAW (1 << 3)
72#define DAHDI_FORMAT_G726 (1 << 4)
74#define DAHDI_FORMAT_ADPCM (1 << 5)
76#define DAHDI_FORMAT_SLINEAR (1 << 6)
78#define DAHDI_FORMAT_LPC10 (1 << 7)
80#define DAHDI_FORMAT_G729A (1 << 8)
82#define DAHDI_FORMAT_SPEEX (1 << 9)
84#define DAHDI_FORMAT_ILBC (1 << 10)
93#if defined(NOT_NEEDED)
105static uint64_t bitfield_dahdi2ast(
unsigned dahdi)
165 static const struct ast_codec dahdi_g723_1 = {
170 static const struct ast_codec dahdi_gsm = {
175 static const struct ast_codec dahdi_ulaw = {
180 static const struct ast_codec dahdi_alaw = {
185 static const struct ast_codec dahdi_g726 = {
190 static const struct ast_codec dahdi_adpcm = {
195 static const struct ast_codec dahdi_slinear = {
200 static const struct ast_codec dahdi_lpc10 = {
205 static const struct ast_codec dahdi_g729a = {
210 static const struct ast_codec dahdi_speex = {
215 static const struct ast_codec dahdi_ilbc = {
223 codec = &dahdi_g723_1;
238 codec = &dahdi_adpcm;
241 codec = &dahdi_slinear;
244 codec = &dahdi_lpc10;
247 codec = &dahdi_g729a;
250 codec = &dahdi_speex;
277#define container_of(ptr, type, member) \
278 ((type *)((char *)(ptr) - offsetof(type, member)))
285 struct dahdi_transcoder_formats
fmts;
337 e->
command =
"transcoder show";
339 "Usage: transcoder show\n"
340 " Displays channel utilization of DAHDI transcoder(s).\n";
352 ast_cli(
a->fd,
"No DAHDI transcoders found.\n");
354 ast_cli(
a->fd,
"%d/%d encoders/decoders of %d channels are in use.\n",
copy.encoders,
copy.decoders,
copy.total);
363 res = write(dahdip->
fd, buffer, count);
368 ast_log(
LOG_ERROR,
"Requested write of %zd bytes, but only wrote %d bytes.\n", count, res);
419 struct pollfd p = {0};
430 if (2 == dahdip->
fake) {
441 }
else if (1 == dahdip->
fake) {
452 if (EWOULDBLOCK ==
errno) {
504 if (2 == dahdip->
fake) {
515 }
else if (1 == dahdip->
fake) {
533 if (EWOULDBLOCK ==
errno) {
566 switch (dahdip->
fmts.dstfmt) {
617 const char *dev_filename =
"/dev/dahdi/transcode";
619 if ((
fd = open(dev_filename, O_RDWR)) < 0) {
624 dahdip->
fmts.srcfmt = src_dahdi_fmt;
625 dahdip->
fmts.dstfmt = dst_dahdi_fmt;
633 if (ioctl(
fd, DAHDI_TC_ALLOCATE, &dahdip->
fmts)) {
634 if ((ENODEV ==
errno) && !tried_once) {
644 ast_debug(1,
"Using soft_slin support on source\n");
648 ast_debug(1,
"Using soft_slin support on destination\n");
667 switch (dahdip->
fmts.dstfmt) {
695 .src = __PRETTY_FUNCTION__
716 if (!dst_codec || !src_codec) {
727 snprintf(zt->
t.
name,
sizeof(zt->
t.
name),
"dahdi_%s_to_%s",
730 memcpy(&zt->
t.
src_codec, src_codec,
sizeof(*src_codec));
731 memcpy(&zt->
t.
dst_codec, dst_codec,
sizeof(*dst_codec));
792 for (srcfmt = 1; srcfmt != 0; srcfmt <<= 1) {
793 for (dstfmt = 1; dstfmt != 0; dstfmt <<= 1) {
794 if (!(dstfmts & dstfmt) || !(srcfmts & srcfmt)) {
809 struct dahdi_transcoder_info
info = { 0, };
812 if ((fd = open(
"/dev/dahdi/transcode", O_RDWR)) < 0) {
817 for (
info.tcnum = 0; !ioctl(fd, DAHDI_TC_GETINFO, &
info);
info.tcnum++) {
842 ast_verb(2,
"No hardware transcoders found.\n");
static int copy(char *infile, char *outfile)
Utility function to copy a file.
Asterisk main include file. File version handling, generic pbx functions.
#define ast_calloc(num, len)
A wrapper for calloc()
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
General Asterisk PBX channel definitions.
Standard Command Line Interface.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
#define AST_CLI_DEFINE(fn, txt,...)
void ast_cli(int fd, const char *fmt,...)
#define ast_cli_register_multiple(e, len)
Register multiple commands.
unsigned int ast_codec_samples_count(struct ast_frame *frame)
Get the number of samples contained within a frame.
static int dahdi_new(struct ast_trans_pvt *pvt)
static int register_translator(uint32_t dst_dahdi_fmt, uint32_t src_dahdi_fmt)
static struct ast_frame * dahdi_encoder_frameout(struct ast_trans_pvt *pvt)
static struct channel_usage channels
static char * handle_cli_transcoder_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int lintoulaw(struct ast_trans_pvt *pvt, struct ast_frame *f)
#define DAHDI_FORMAT_SPEEX
#define DAHDI_FORMAT_SLINEAR
static struct ast_frame * dahdi_decoder_frameout(struct ast_trans_pvt *pvt)
static int ulawtolin(struct ast_trans_pvt *pvt, int samples)
static int dahdi_decoder_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
static bool is_encoder(uint32_t src_dahdi_fmt)
#define DAHDI_FORMAT_ULAW
static bool is_already_registered(uint32_t dstfmt, uint32_t srcfmt)
static void build_translators(uint32_t dstfmts, uint32_t srcfmts)
#define DAHDI_FORMAT_ADPCM
#define DAHDI_FORMAT_G729A
#define DAHDI_FORMAT_LPC10
static const struct ast_codec * get_dahdi_codec(uint32_t dahdi_fmt)
static void dahdi_wait_for_packet(int fd)
static void dahdi_write_frame(struct codec_dahdi_pvt *dahdip, const uint8_t *buffer, const ssize_t count)
static struct ast_cli_entry cli[]
static int load_module(void)
#define DAHDI_FORMAT_ILBC
#define DAHDI_FORMAT_G723_1
static int unload_module(void)
static struct ast_frame * fakesrc_sample(void)
static void dahdi_destroy(struct ast_trans_pvt *pvt)
static int find_transcoders(void)
#define DAHDI_FORMAT_ALAW
#define DAHDI_FORMAT_G726
static void unregister_translators(void)
static int dahdi_encoder_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
static struct ast_format * dahdi_format_to_cached(int format)
#define container_of(ptr, type, member)
static int dahdi_translate(struct ast_trans_pvt *pvt, uint32_t dst_dahdi_fmt, uint32_t src_dahdi_fmt)
Configuration File Parser.
#define ast_frisolate(fr)
Makes a frame independent of any static storage.
#define ast_debug(level,...)
Log a DEBUG message.
#define ast_verb(level,...)
A set of macros to manage forward-linked lists.
#define AST_LIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a list of specified type, statically initialized.
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
#define AST_LIST_LOCK(head)
Locks a list.
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Asterisk locking-related definitions:
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Asterisk module definitions.
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
@ AST_MODULE_SUPPORT_CORE
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
descriptor for a cli entry.
Represents a media codec within Asterisk.
const char * name
Name for this codec.
struct ast_format * format
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
union ast_frame::@226 data
enum ast_frame_type frametype
Default structure for translators, with the basic fields and buffers, all allocated as part of the sa...
struct ast_translator * t
int datalen
actual space used in outbuf
union ast_trans_pvt::@287 outbuf
Descriptor of a translator.
void(* destroy)(struct ast_trans_pvt *pvt)
struct ast_frame *(* sample)(void)
int buffer_samples
size of outbuf, in samples. Leave it 0 if you want the framein callback deal with the frame....
int buf_size
size of outbuf, in bytes. Mandatory. The wrapper code will also allocate an AST_FRIENDLY_OFFSET space...
int(* framein)(struct ast_trans_pvt *pvt, struct ast_frame *in)
struct ast_codec src_codec
struct ast_frame *(* frameout)(struct ast_trans_pvt *pvt)
int(* newpvt)(struct ast_trans_pvt *)
struct ast_codec dst_codec
struct dahdi_transcoder_formats fmts
uint8_t ulaw_buffer[1024]
uint16_t required_samples
uint16_t samples_written_to_hardware
uint16_t samples_in_buffer
struct translator::@145 entry
Support for translation of data formats. translate.c.
#define ast_register_translator(t)
See __ast_register_translator()
int ast_unregister_translator(struct ast_translator *t)
Unregister a translator Unregisters the given translator.
u-Law to Signed linear conversion
#define ast_fd_set_flags(fd, flags)
Set flags on the given file descriptor.