00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "asterisk.h"
00027
00028 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 89516 $")
00029
00030 #include "asterisk/module.h"
00031 #include "asterisk/translate.h"
00032 #include "asterisk/alaw.h"
00033 #include "asterisk/ulaw.h"
00034 #include "asterisk/utils.h"
00035
00036 #define BUFFER_SAMPLES 8000
00037
00038 static unsigned char mu2a[256];
00039 static unsigned char a2mu[256];
00040
00041
00042
00043 #include "ulaw_slin_ex.h"
00044
00045
00046 static int alawtoulaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
00047 {
00048 int x = f->samples;
00049 unsigned char *src = f->data;
00050 unsigned char *dst = (unsigned char *)pvt->outbuf + pvt->samples;
00051
00052 pvt->samples += x;
00053 pvt->datalen += x;
00054
00055 while (x--)
00056 *dst++ = a2mu[*src++];
00057
00058 return 0;
00059 }
00060
00061
00062 static int ulawtoalaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
00063 {
00064 int x = f->samples;
00065 unsigned char *src = f->data;
00066 unsigned char *dst = (unsigned char *)pvt->outbuf + pvt->samples;
00067
00068 pvt->samples += x;
00069 pvt->datalen += x;
00070
00071 while (x--)
00072 *dst++ = mu2a[*src++];
00073
00074 return 0;
00075 }
00076
00077
00078
00079
00080 static struct ast_frame *alawtoulaw_sample(void)
00081 {
00082 static struct ast_frame f;
00083 f.frametype = AST_FRAME_VOICE;
00084 f.subclass = AST_FORMAT_ALAW;
00085 f.datalen = sizeof(ulaw_slin_ex);
00086 f.samples = sizeof(ulaw_slin_ex);
00087 f.mallocd = 0;
00088 f.offset = 0;
00089 f.src = __PRETTY_FUNCTION__;
00090 f.data = ulaw_slin_ex;
00091 return &f;
00092 }
00093
00094 static struct ast_frame *ulawtoalaw_sample(void)
00095 {
00096 static struct ast_frame f;
00097 f.frametype = AST_FRAME_VOICE;
00098 f.subclass = AST_FORMAT_ULAW;
00099 f.datalen = sizeof(ulaw_slin_ex);
00100 f.samples = sizeof(ulaw_slin_ex);
00101 f.mallocd = 0;
00102 f.offset = 0;
00103 f.src = __PRETTY_FUNCTION__;
00104 f.data = ulaw_slin_ex;
00105 return &f;
00106 }
00107
00108 static struct ast_translator alawtoulaw = {
00109 .name = "alawtoulaw",
00110 .srcfmt = AST_FORMAT_ALAW,
00111 .dstfmt = AST_FORMAT_ULAW,
00112 .framein = alawtoulaw_framein,
00113 .sample = alawtoulaw_sample,
00114 .buffer_samples = BUFFER_SAMPLES,
00115 .buf_size = BUFFER_SAMPLES,
00116 };
00117
00118 static struct ast_translator ulawtoalaw = {
00119 .name = "ulawtoalaw",
00120 .srcfmt = AST_FORMAT_ULAW,
00121 .dstfmt = AST_FORMAT_ALAW,
00122 .framein = ulawtoalaw_framein,
00123 .sample = ulawtoalaw_sample,
00124 .buffer_samples = BUFFER_SAMPLES,
00125 .buf_size = BUFFER_SAMPLES,
00126 };
00127
00128
00129
00130 static int unload_module(void)
00131 {
00132 int res;
00133
00134 res = ast_unregister_translator(&ulawtoalaw);
00135 res |= ast_unregister_translator(&alawtoulaw);
00136
00137 return res;
00138 }
00139
00140 static int load_module(void)
00141 {
00142 int res;
00143 int x;
00144
00145 for (x=0;x<256;x++) {
00146 mu2a[x] = AST_LIN2A(AST_MULAW(x));
00147 a2mu[x] = AST_LIN2MU(AST_ALAW(x));
00148 }
00149 res = ast_register_translator(&alawtoulaw);
00150 if (!res)
00151 res = ast_register_translator(&ulawtoalaw);
00152 else
00153 ast_unregister_translator(&alawtoulaw);
00154 if (res)
00155 return AST_MODULE_LOAD_FAILURE;
00156 return AST_MODULE_LOAD_SUCCESS;
00157 }
00158
00159 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "A-law and Mulaw direct Coder/Decoder");