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
00027
00028
00029
00030 #include "asterisk.h"
00031
00032 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
00033
00034 #include "asterisk/module.h"
00035 #include "asterisk/translate.h"
00036 #include "asterisk/alaw.h"
00037 #include "asterisk/ulaw.h"
00038 #include "asterisk/utils.h"
00039
00040 #define BUFFER_SAMPLES 8000
00041
00042 static unsigned char mu2a[256];
00043 static unsigned char a2mu[256];
00044
00045
00046 #include "ex_ulaw.h"
00047 #include "ex_alaw.h"
00048
00049
00050 static int alawtoulaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
00051 {
00052 int x = f->samples;
00053 unsigned char *src = f->data.ptr;
00054 unsigned char *dst = pvt->outbuf.uc + pvt->samples;
00055
00056 pvt->samples += x;
00057 pvt->datalen += x;
00058
00059 while (x--)
00060 *dst++ = a2mu[*src++];
00061
00062 return 0;
00063 }
00064
00065
00066 static int ulawtoalaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
00067 {
00068 int x = f->samples;
00069 unsigned char *src = f->data.ptr;
00070 unsigned char *dst = pvt->outbuf.uc + pvt->samples;
00071
00072 pvt->samples += x;
00073 pvt->datalen += x;
00074
00075 while (x--)
00076 *dst++ = mu2a[*src++];
00077
00078 return 0;
00079 }
00080
00081 static struct ast_translator alawtoulaw = {
00082 .name = "alawtoulaw",
00083 .srcfmt = AST_FORMAT_ALAW,
00084 .dstfmt = AST_FORMAT_ULAW,
00085 .framein = alawtoulaw_framein,
00086 .sample = alaw_sample,
00087 .buffer_samples = BUFFER_SAMPLES,
00088 .buf_size = BUFFER_SAMPLES,
00089 };
00090
00091 static struct ast_translator ulawtoalaw = {
00092 .name = "ulawtoalaw",
00093 .srcfmt = AST_FORMAT_ULAW,
00094 .dstfmt = AST_FORMAT_ALAW,
00095 .framein = ulawtoalaw_framein,
00096 .sample = ulaw_sample,
00097 .buffer_samples = BUFFER_SAMPLES,
00098 .buf_size = BUFFER_SAMPLES,
00099 };
00100
00101
00102
00103 static int unload_module(void)
00104 {
00105 int res;
00106
00107 res = ast_unregister_translator(&ulawtoalaw);
00108 res |= ast_unregister_translator(&alawtoulaw);
00109
00110 return res;
00111 }
00112
00113 static int load_module(void)
00114 {
00115 int res;
00116 int x;
00117
00118 for (x=0;x<256;x++) {
00119 mu2a[x] = AST_LIN2A(AST_MULAW(x));
00120 a2mu[x] = AST_LIN2MU(AST_ALAW(x));
00121 }
00122 res = ast_register_translator(&alawtoulaw);
00123 if (!res)
00124 res = ast_register_translator(&ulawtoalaw);
00125 else
00126 ast_unregister_translator(&alawtoulaw);
00127 if (res)
00128 return AST_MODULE_LOAD_FAILURE;
00129 return AST_MODULE_LOAD_SUCCESS;
00130 }
00131
00132 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "A-law and Mulaw direct Coder/Decoder");