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: 150729 $")
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 #include "ex_ulaw.h"
00043 #include "ex_alaw.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.ptr;
00050 unsigned char *dst = pvt->outbuf.uc + 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.ptr;
00066 unsigned char *dst = pvt->outbuf.uc + 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 static struct ast_translator alawtoulaw = {
00078 .name = "alawtoulaw",
00079 .srcfmt = AST_FORMAT_ALAW,
00080 .dstfmt = AST_FORMAT_ULAW,
00081 .framein = alawtoulaw_framein,
00082 .sample = alaw_sample,
00083 .buffer_samples = BUFFER_SAMPLES,
00084 .buf_size = BUFFER_SAMPLES,
00085 };
00086
00087 static struct ast_translator ulawtoalaw = {
00088 .name = "ulawtoalaw",
00089 .srcfmt = AST_FORMAT_ULAW,
00090 .dstfmt = AST_FORMAT_ALAW,
00091 .framein = ulawtoalaw_framein,
00092 .sample = ulaw_sample,
00093 .buffer_samples = BUFFER_SAMPLES,
00094 .buf_size = BUFFER_SAMPLES,
00095 };
00096
00097
00098
00099 static int unload_module(void)
00100 {
00101 int res;
00102
00103 res = ast_unregister_translator(&ulawtoalaw);
00104 res |= ast_unregister_translator(&alawtoulaw);
00105
00106 return res;
00107 }
00108
00109 static int load_module(void)
00110 {
00111 int res;
00112 int x;
00113
00114 for (x=0;x<256;x++) {
00115 mu2a[x] = AST_LIN2A(AST_MULAW(x));
00116 a2mu[x] = AST_LIN2MU(AST_ALAW(x));
00117 }
00118 res = ast_register_translator(&alawtoulaw);
00119 if (!res)
00120 res = ast_register_translator(&ulawtoalaw);
00121 else
00122 ast_unregister_translator(&alawtoulaw);
00123 if (res)
00124 return AST_MODULE_LOAD_FAILURE;
00125 return AST_MODULE_LOAD_SUCCESS;
00126 }
00127
00128 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "A-law and Mulaw direct Coder/Decoder");