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 #include "asterisk.h"
00027
00028 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 267507 $")
00029
00030 #include "asterisk/module.h"
00031 #include "asterisk/config.h"
00032 #include "asterisk/translate.h"
00033 #include "asterisk/ulaw.h"
00034 #include "asterisk/utils.h"
00035
00036 #define BUFFER_SAMPLES 8096
00037
00038
00039 #include "asterisk/slin.h"
00040 #include "ex_ulaw.h"
00041
00042
00043 static int ulawtolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
00044 {
00045 int i = f->samples;
00046 unsigned char *src = f->data.ptr;
00047 int16_t *dst = pvt->outbuf.i16 + pvt->samples;
00048
00049 pvt->samples += i;
00050 pvt->datalen += i * 2;
00051
00052
00053 while (i--)
00054 *dst++ = AST_MULAW(*src++);
00055
00056 return 0;
00057 }
00058
00059
00060 static int lintoulaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
00061 {
00062 int i = f->samples;
00063 char *dst = pvt->outbuf.c + pvt->samples;
00064 int16_t *src = f->data.ptr;
00065
00066 pvt->samples += i;
00067 pvt->datalen += i;
00068
00069 while (i--)
00070 *dst++ = AST_LIN2MU(*src++);
00071
00072 return 0;
00073 }
00074
00075
00076
00077
00078
00079 static struct ast_translator ulawtolin = {
00080 .name = "ulawtolin",
00081 .srcfmt = AST_FORMAT_ULAW,
00082 .dstfmt = AST_FORMAT_SLINEAR,
00083 .framein = ulawtolin_framein,
00084 .sample = ulaw_sample,
00085 .buffer_samples = BUFFER_SAMPLES,
00086 .buf_size = BUFFER_SAMPLES * 2,
00087 };
00088
00089
00090
00091
00092
00093 static struct ast_translator lintoulaw = {
00094 .name = "lintoulaw",
00095 .srcfmt = AST_FORMAT_SLINEAR,
00096 .dstfmt = AST_FORMAT_ULAW,
00097 .framein = lintoulaw_framein,
00098 .sample = slin8_sample,
00099 .buf_size = BUFFER_SAMPLES,
00100 .buffer_samples = BUFFER_SAMPLES,
00101 };
00102
00103 static int reload(void)
00104 {
00105 return AST_MODULE_LOAD_SUCCESS;
00106 }
00107
00108 static int unload_module(void)
00109 {
00110 int res;
00111
00112 res = ast_unregister_translator(&lintoulaw);
00113 res |= ast_unregister_translator(&ulawtolin);
00114
00115 return res;
00116 }
00117
00118 static int load_module(void)
00119 {
00120 int res;
00121
00122 res = ast_register_translator(&ulawtolin);
00123 if (!res)
00124 res = ast_register_translator(&lintoulaw);
00125 else
00126 ast_unregister_translator(&ulawtolin);
00127 if (res)
00128 return AST_MODULE_LOAD_FAILURE;
00129 return AST_MODULE_LOAD_SUCCESS;
00130 }
00131
00132 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "mu-Law Coder/Decoder",
00133 .load = load_module,
00134 .unload = unload_module,
00135 .reload = reload,
00136 );