| 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/translate.h" |
| 34 |
#include "asterisk/alaw.h" |
| 35 |
#include "asterisk/ulaw.h" |
| 36 |
#include "asterisk/utils.h" |
| 37 |
|
| 38 |
#define BUFFER_SAMPLES 8000 |
| 39 |
|
| 40 |
static unsigned char mu2a[256]; |
| 41 |
static unsigned char a2mu[256]; |
| 42 |
|
| 43 |
|
| 44 |
#include "ex_ulaw.h" |
| 45 |
#include "ex_alaw.h" |
| 46 |
|
| 47 |
|
| 48 |
static int alawtoulaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) |
| 49 |
{ |
| 50 |
int x = f->samples; |
| 51 |
unsigned char *src = f->data.ptr; |
| 52 |
unsigned char *dst = pvt->outbuf.uc + pvt->samples; |
| 53 |
|
| 54 |
pvt->samples += x; |
| 55 |
pvt->datalen += x; |
| 56 |
|
| 57 |
while (x--) |
| 58 |
*dst++ = a2mu[*src++]; |
| 59 |
|
| 60 |
return 0; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
static int ulawtoalaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) |
| 65 |
{ |
| 66 |
int x = f->samples; |
| 67 |
unsigned char *src = f->data.ptr; |
| 68 |
unsigned char *dst = pvt->outbuf.uc + pvt->samples; |
| 69 |
|
| 70 |
pvt->samples += x; |
| 71 |
pvt->datalen += x; |
| 72 |
|
| 73 |
while (x--) |
| 74 |
*dst++ = mu2a[*src++]; |
| 75 |
|
| 76 |
return 0; |
| 77 |
} |
| 78 |
|
| 79 |
static struct ast_translator alawtoulaw = { |
| 80 |
.name = "alawtoulaw", |
| 81 |
.src_codec = { |
| 82 |
.name = "alaw", |
| 83 |
.type = AST_MEDIA_TYPE_AUDIO, |
| 84 |
.sample_rate = 8000, |
| 85 |
}, |
| 86 |
.dst_codec = { |
| 87 |
.name = "ulaw", |
| 88 |
.type = AST_MEDIA_TYPE_AUDIO, |
| 89 |
.sample_rate = 8000, |
| 90 |
}, |
| 91 |
.format = "ulaw", |
| 92 |
.framein = alawtoulaw_framein, |
| 93 |
.sample = alaw_sample, |
| 94 |
.buffer_samples = BUFFER_SAMPLES, |
| 95 |
.buf_size = BUFFER_SAMPLES, |
| 96 |
}; |
| 97 |
|
| 98 |
static struct ast_translator ulawtoalaw = { |
| 99 |
.name = "ulawtoalaw", |
| 100 |
.src_codec = { |
| 101 |
.name = "ulaw", |
| 102 |
.type = AST_MEDIA_TYPE_AUDIO, |
| 103 |
.sample_rate = 8000, |
| 104 |
}, |
| 105 |
.dst_codec = { |
| 106 |
.name = "alaw", |
| 107 |
.type = AST_MEDIA_TYPE_AUDIO, |
| 108 |
.sample_rate = 8000, |
| 109 |
}, |
| 110 |
.format = "alaw", |
| 111 |
.framein = ulawtoalaw_framein, |
| 112 |
.sample = ulaw_sample, |
| 113 |
.buffer_samples = BUFFER_SAMPLES, |
| 114 |
.buf_size = BUFFER_SAMPLES, |
| 115 |
}; |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
static int unload_module(void) |
| 120 |
{ |
| 121 |
int res; |
| 122 |
|
| 123 |
res = ast_unregister_translator(&ulawtoalaw); |
| 124 |
res |= ast_unregister_translator(&alawtoulaw); |
| 125 |
|
| 126 |
return res; |
| 127 |
} |
| 128 |
|
| 129 |
static int load_module(void) |
| 130 |
{ |
| 131 |
int res; |
| 132 |
int x; |
| 133 |
|
| 134 |
for (x=0;x<256;x++) { |
| 135 |
mu2a[x] = AST_LIN2A(AST_MULAW(x)); |
| 136 |
a2mu[x] = AST_LIN2MU(AST_ALAW(x)); |
| 137 |
} |
| 138 |
|
| 139 |
res = ast_register_translator(&alawtoulaw); |
| 140 |
res |= ast_register_translator(&ulawtoalaw); |
| 141 |
|
| 142 |
if (res) { |
| 143 |
unload_module(); |
| 144 |
return AST_MODULE_LOAD_DECLINE; |
| 145 |
} |
| 146 |
|
| 147 |
return AST_MODULE_LOAD_SUCCESS; |
| 148 |
} |
| 149 |
|
| 150 |
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "A-law and Mulaw direct Coder/Decoder"); |