45 typedef uint16_t ilbc_bytes;
46 typedef int16_t ilbc_block;
49 #include "ilbc/iLBC_encode.h"
50 #include "ilbc/iLBC_decode.h"
51 typedef unsigned char ilbc_bytes;
52 typedef float ilbc_block;
56 #include "asterisk/ilbc.h"
58 #define USE_ILBC_ENHANCER 0
59 #define BUFFER_SAMPLES 8000
62 #include "asterisk/slin.h"
69 int16_t buf[BUFFER_SAMPLES];
77 const unsigned int mode = attr ? attr->mode : 30;
79 initEncode(&tmp->enc, mode);
98 const unsigned int mode = attr ? attr->mode : 30;
100 const unsigned int samples_per_frame = mode * sample_rate / 1000;
101 const unsigned int octets_per_frame = (mode == 20) ? 38 : 50;
108 int16_t *dst = pvt->outbuf.i16;
109 ilbc_block tmpf[samples_per_frame];
111 if (!f->
data.ptr && datalen) {
112 ast_debug(1,
"issue 16070, ILIB ERROR. data = NULL datalen = %d src = %s\n", datalen, f->
src ? f->
src :
"no src set");
118 datalen = octets_per_frame;
119 f->
samples = samples_per_frame;
121 pvt->
samples += samples_per_frame;
124 if (datalen % octets_per_frame) {
125 ast_log(LOG_WARNING,
"Huh? An ilbc frame that isn't a multiple of %u bytes long from %s (%d)?\n", octets_per_frame, f->
src, datalen);
130 initDecode(&tmp->dec, mode, USE_ILBC_ENHANCER);
134 for (x = 0; x < datalen; x += octets_per_frame) {
135 if (pvt->
samples + samples_per_frame > BUFFER_SAMPLES) {
136 ast_log(LOG_WARNING,
"Out of buffer space\n");
139 iLBC_decode(tmpf, plc_mode ? f->
data.ptr + x : NULL, &tmp->dec, plc_mode);
140 for (i = 0; i < samples_per_frame; i++)
141 dst[pvt->
samples + i] = tmpf[i];
142 pvt->
samples += samples_per_frame;
143 pvt->
datalen += samples_per_frame * 2;
171 const unsigned int mode = attr ? attr->mode : 30;
173 const unsigned int samples_per_frame = mode * sample_rate / 1000;
174 const unsigned int octets_per_frame = (mode == 20) ? 38 : 50;
176 while (pvt->
samples >= samples_per_frame) {
178 ilbc_block tmpf[samples_per_frame];
182 for (i = 0; i < samples_per_frame; i++)
183 tmpf[i] = tmp->buf[samples + i];
184 iLBC_encode((ilbc_bytes *) pvt->outbuf.BUF_TYPE, tmpf, &tmp->enc);
186 samples += samples_per_frame;
187 pvt->
samples -= samples_per_frame;
202 memmove(tmp->buf, tmp->buf + samples, pvt->
samples * 2);
212 .type = AST_MEDIA_TYPE_AUDIO,
217 .type = AST_MEDIA_TYPE_AUDIO,
221 .newpvt = ilbctolin_new,
223 .sample = ilbc_sample,
225 .buf_size = BUFFER_SAMPLES * 2,
233 .type = AST_MEDIA_TYPE_AUDIO,
238 .type = AST_MEDIA_TYPE_AUDIO,
242 .newpvt = lintoilbc_new,
245 .sample = slin8_sample,
248 .buf_size = (BUFFER_SAMPLES * 38 + 160 - 1) / 160,
251 static int unload_module(
void)
261 static int load_module(
void)
struct ast_frame * ast_trans_frameout(struct ast_trans_pvt *pvt, int datalen, int samples)
generic frameout function
int datalen
actual space used in outbuf
Asterisk main include file. File version handling, generic pbx functions.
Descriptor of a translator.
Support for translation of data formats. translate.c.
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
struct ast_frame_subclass subclass
#define ast_register_translator(t)
See __ast_register_translator()
Asterisk internal frame definitions.
int ast_unregister_translator(struct ast_translator *t)
Unregister a translator Unregisters the given translator.
A set of macros to manage forward-linked lists.
#define ast_debug(level,...)
Log a DEBUG message.
static int ilbctolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
decode a frame and store in outbuf
struct ast_codec dst_codec
struct ast_format * explicit_dst
Default structure for translators, with the basic fields and buffers, all allocated as part of the sa...
union ast_frame::@224 data
Support for logging to various files, console and syslog Configuration in file logger.conf.
Module has failed to load, may be in an inconsistent state.
unsigned int sample_rate
Sample rate (number of samples carried in a second)
static struct ast_frame * lintoilbc_frameout(struct ast_trans_pvt *pvt)
encode the temporary buffer and generate a frame
Data structure associated with a single frame of data.
static int lintoilbc_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
store a frame into a temporary buffer, for later decoding
struct ast_format * format
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.