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/config.h"
00036 #include "asterisk/translate.h"
00037 #include "asterisk/alaw.h"
00038 #include "asterisk/utils.h"
00039
00040 #define BUFFER_SAMPLES 8096
00041
00042
00043 #include "asterisk/slin.h"
00044 #include "ex_alaw.h"
00045
00046
00047 static int alawtolin_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 while (i--)
00057 *dst++ = AST_ALAW(*src++);
00058
00059 return 0;
00060 }
00061
00062
00063 static int lintoalaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
00064 {
00065 int i = f->samples;
00066 char *dst = pvt->outbuf.c + pvt->samples;
00067 int16_t *src = f->data.ptr;
00068
00069 pvt->samples += i;
00070 pvt->datalen += i;
00071
00072 while (i--)
00073 *dst++ = AST_LIN2A(*src++);
00074
00075 return 0;
00076 }
00077
00078 static struct ast_translator alawtolin = {
00079 .name = "alawtolin",
00080 .framein = alawtolin_framein,
00081 .sample = alaw_sample,
00082 .buffer_samples = BUFFER_SAMPLES,
00083 .buf_size = BUFFER_SAMPLES * 2,
00084 };
00085
00086 static struct ast_translator lintoalaw = {
00087 "lintoalaw",
00088 .framein = lintoalaw_framein,
00089 .sample = slin8_sample,
00090 .buffer_samples = BUFFER_SAMPLES,
00091 .buf_size = BUFFER_SAMPLES,
00092 };
00093
00094
00095
00096 static int reload(void)
00097 {
00098 return AST_MODULE_LOAD_SUCCESS;
00099 }
00100
00101 static int unload_module(void)
00102 {
00103 int res;
00104
00105 res = ast_unregister_translator(&lintoalaw);
00106 res |= ast_unregister_translator(&alawtolin);
00107
00108 return res;
00109 }
00110
00111 static int load_module(void)
00112 {
00113 int res;
00114
00115 ast_format_set(&lintoalaw.src_format, AST_FORMAT_SLINEAR, 0);
00116 ast_format_set(&lintoalaw.dst_format, AST_FORMAT_ALAW, 0);
00117
00118 ast_format_set(&alawtolin.src_format, AST_FORMAT_ALAW, 0);
00119 ast_format_set(&alawtolin.dst_format, AST_FORMAT_SLINEAR, 0);
00120
00121 res = ast_register_translator(&alawtolin);
00122 if (!res)
00123 res = ast_register_translator(&lintoalaw);
00124 else
00125 ast_unregister_translator(&alawtolin);
00126 if (res)
00127 return AST_MODULE_LOAD_FAILURE;
00128 return AST_MODULE_LOAD_SUCCESS;
00129 }
00130
00131 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "A-law Coder/Decoder",
00132 .load = load_module,
00133 .unload = unload_module,
00134 .reload = reload,
00135 );