| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#include "asterisk.h" |
| 31 |
|
| 32 |
#include "asterisk/module.h" |
| 33 |
#include "asterisk/config.h" |
| 34 |
#include "asterisk/translate.h" |
| 35 |
#include "asterisk/alaw.h" |
| 36 |
#include "asterisk/utils.h" |
| 37 |
|
| 38 |
#define BUFFER_SAMPLES 8096 |
| 39 |
|
| 40 |
|
| 41 |
#include "asterisk/slin.h" |
| 42 |
#include "ex_alaw.h" |
| 43 |
|
| 44 |
|
| 45 |
static int alawtolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) |
| 46 |
{ |
| 47 |
int i = f->samples; |
| 48 |
unsigned char *src = f->data.ptr; |
| 49 |
int16_t *dst = pvt->outbuf.i16 + pvt->samples; |
| 50 |
|
| 51 |
pvt->samples += i; |
| 52 |
pvt->datalen += i * 2; |
| 53 |
|
| 54 |
while (i--) |
| 55 |
*dst++ = AST_ALAW(*src++); |
| 56 |
|
| 57 |
return 0; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
static int lintoalaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) |
| 62 |
{ |
| 63 |
int i = f->samples; |
| 64 |
char *dst = pvt->outbuf.c + pvt->samples; |
| 65 |
int16_t *src = f->data.ptr; |
| 66 |
|
| 67 |
pvt->samples += i; |
| 68 |
pvt->datalen += i; |
| 69 |
|
| 70 |
while (i--) |
| 71 |
*dst++ = AST_LIN2A(*src++); |
| 72 |
|
| 73 |
return 0; |
| 74 |
} |
| 75 |
|
| 76 |
static struct ast_translator alawtolin = { |
| 77 |
.name = "alawtolin", |
| 78 |
.src_codec = { |
| 79 |
.name = "alaw", |
| 80 |
.type = AST_MEDIA_TYPE_AUDIO, |
| 81 |
.sample_rate = 8000, |
| 82 |
}, |
| 83 |
.dst_codec = { |
| 84 |
.name = "slin", |
| 85 |
.type = AST_MEDIA_TYPE_AUDIO, |
| 86 |
.sample_rate = 8000, |
| 87 |
}, |
| 88 |
.format = "slin", |
| 89 |
.framein = alawtolin_framein, |
| 90 |
.sample = alaw_sample, |
| 91 |
.buffer_samples = BUFFER_SAMPLES, |
| 92 |
.buf_size = BUFFER_SAMPLES * 2, |
| 93 |
}; |
| 94 |
|
| 95 |
static struct ast_translator lintoalaw = { |
| 96 |
.name = "lintoalaw", |
| 97 |
.src_codec = { |
| 98 |
.name = "slin", |
| 99 |
.type = AST_MEDIA_TYPE_AUDIO, |
| 100 |
.sample_rate = 8000, |
| 101 |
}, |
| 102 |
.dst_codec = { |
| 103 |
.name = "alaw", |
| 104 |
.type = AST_MEDIA_TYPE_AUDIO, |
| 105 |
.sample_rate = 8000, |
| 106 |
}, |
| 107 |
.format = "alaw", |
| 108 |
.framein = lintoalaw_framein, |
| 109 |
.sample = slin8_sample, |
| 110 |
.buffer_samples = BUFFER_SAMPLES, |
| 111 |
.buf_size = BUFFER_SAMPLES, |
| 112 |
}; |
| 113 |
|
| 114 |
static int unload_module(void) |
| 115 |
{ |
| 116 |
int res; |
| 117 |
|
| 118 |
res = ast_unregister_translator(&lintoalaw); |
| 119 |
res |= ast_unregister_translator(&alawtolin); |
| 120 |
|
| 121 |
return res; |
| 122 |
} |
| 123 |
|
| 124 |
static int load_module(void) |
| 125 |
{ |
| 126 |
int res; |
| 127 |
|
| 128 |
res = ast_register_translator(&alawtolin); |
| 129 |
res |= ast_register_translator(&lintoalaw); |
| 130 |
|
| 131 |
if (res) { |
| 132 |
unload_module(); |
| 133 |
return AST_MODULE_LOAD_DECLINE; |
| 134 |
} |
| 135 |
|
| 136 |
return AST_MODULE_LOAD_SUCCESS; |
| 137 |
} |
| 138 |
|
| 139 |
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "A-law Coder/Decoder", |
| 140 |
.support_level = AST_MODULE_SUPPORT_CORE, |
| 141 |
.load = load_module, |
| 142 |
.unload = unload_module, |
| 143 |
); |