Go to the documentation of this file.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: 328259 $")
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 .framein = alawtoulaw_framein,
00084 .sample = alaw_sample,
00085 .buffer_samples = BUFFER_SAMPLES,
00086 .buf_size = BUFFER_SAMPLES,
00087 };
00088
00089 static struct ast_translator ulawtoalaw = {
00090 .name = "ulawtoalaw",
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 ast_format_set(&alawtoulaw.src_format, AST_FORMAT_ALAW, 0);
00115 ast_format_set(&alawtoulaw.dst_format, AST_FORMAT_ULAW, 0);
00116
00117 ast_format_set(&ulawtoalaw.src_format, AST_FORMAT_ULAW, 0);
00118 ast_format_set(&ulawtoalaw.dst_format, AST_FORMAT_ALAW, 0);
00119
00120 for (x=0;x<256;x++) {
00121 mu2a[x] = AST_LIN2A(AST_MULAW(x));
00122 a2mu[x] = AST_LIN2MU(AST_ALAW(x));
00123 }
00124 res = ast_register_translator(&alawtoulaw);
00125 if (!res)
00126 res = ast_register_translator(&ulawtoalaw);
00127 else
00128 ast_unregister_translator(&alawtoulaw);
00129 if (res)
00130 return AST_MODULE_LOAD_FAILURE;
00131 return AST_MODULE_LOAD_SUCCESS;
00132 }
00133
00134 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "A-law and Mulaw direct Coder/Decoder");