39 #include <netinet/in.h> 40 #include <sys/ioctl.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) 105 static 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;
291 uint8_t ulaw_buffer[1024];
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");
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++) {
818 ast_verb(2,
"Found transcoder '%s'.\n", info.name);
842 ast_verb(2,
"No hardware transcoders found.\n");
static const struct ast_codec * get_dahdi_codec(uint32_t dahdi_fmt)
struct dahdi_transcoder_formats fmts
int datalen
actual space used in outbuf
static int register_translator(uint32_t dst_dahdi_fmt, uint32_t src_dahdi_fmt)
#define AST_CLI_DEFINE(fn, txt,...)
#define AST_LIST_LOCK(head)
Locks a list.
Asterisk locking-related definitions:
const char * name
Name for this codec.
Asterisk main include file. File version handling, generic pbx functions.
static int dahdi_translate(struct ast_trans_pvt *pvt, uint32_t dst_dahdi_fmt, uint32_t src_dahdi_fmt)
int(* newpvt)(struct ast_trans_pvt *)
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.
descriptor for a cli entry.
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
static void build_translators(uint32_t dstfmts, uint32_t srcfmts)
#define DAHDI_FORMAT_G723_1
#define ast_cli_register_multiple(e, len)
Register multiple commands.
static void unregister_translators(void)
static struct ast_frame * fakesrc_sample(void)
static int dahdi_new(struct ast_trans_pvt *pvt)
void ast_cli(int fd, const char *fmt,...)
#define DAHDI_FORMAT_LPC10
#define ast_verb(level,...)
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.
struct ast_frame_subclass subclass
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)
Configuration File Parser.
#define DAHDI_FORMAT_SPEEX
#define ast_fd_set_flags(fd, flags)
Set flags on the given file descriptor.
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.
static int dahdi_decoder_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
#define DAHDI_FORMAT_G729A
#define DAHDI_FORMAT_ULAW
#define ast_register_translator(t)
See __ast_register_translator()
int ast_unregister_translator(struct ast_translator *t)
Unregister a translator Unregisters the given tranlator.
unsigned int ast_codec_samples_count(struct ast_frame *frame)
Get the number of samples contained within a frame.
static struct ast_format * dahdi_format_to_cached(int format)
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.
#define DAHDI_FORMAT_SLINEAR
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[]
union ast_trans_pvt::@327 outbuf
void(* destroy)(struct ast_trans_pvt *pvt)
struct ast_codec dst_codec
static int unload_module(void)
Default structure for translators, with the basic fields and buffers, all allocated as part of the sa...
static int dahdi_encoder_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
struct ast_codec src_codec
#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_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
#define container_of(ptr, type, member)
#define ast_calloc(num, len)
A wrapper for calloc()
#define DAHDI_FORMAT_G726
#define ast_frisolate(fr)
Makes a frame independent of any static storage.
struct ast_frame *(* sample)(void)
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
static bool is_encoder(uint32_t src_dahdi_fmt)
#define DAHDI_FORMAT_ALAW
uint16_t samples_in_buffer
static int ulawtolin(struct ast_trans_pvt *pvt, int samples)
static void dahdi_destroy(struct ast_trans_pvt *pvt)
Standard Command Line Interface.
#define DAHDI_FORMAT_ADPCM
struct ast_frame *(* frameout)(struct ast_trans_pvt *pvt)
Data structure associated with a single frame of data.
#define DAHDI_FORMAT_ILBC
static struct ast_frame * dahdi_decoder_frameout(struct ast_trans_pvt *pvt)
struct ast_translator * t
union ast_frame::@263 data
enum ast_frame_type frametype
struct ast_format * format
#define ASTERISK_GPL_KEY
The text the key() function should return.
static bool is_already_registered(uint32_t dstfmt, uint32_t srcfmt)
Asterisk module definitions.
static snd_pcm_format_t format
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
Represents a media codec within Asterisk.
int(* framein)(struct ast_trans_pvt *pvt, struct ast_frame *in)
int buffer_samples
size of outbuf, in samples. Leave it 0 if you want the framein callback deal with the frame...