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