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/alaw.h"
00034 #include "asterisk/utils.h"
00035
00036 #define BUFFER_SAMPLES 8096
00037
00038
00039 #include "asterisk/slin.h"
00040 #include "ex_alaw.h"
00041
00042
00043 static int alawtolin_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 while (i--)
00053 *dst++ = AST_ALAW(*src++);
00054
00055 return 0;
00056 }
00057
00058
00059 static int lintoalaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
00060 {
00061 int i = f->samples;
00062 char *dst = pvt->outbuf.c + pvt->samples;
00063 int16_t *src = f->data.ptr;
00064
00065 pvt->samples += i;
00066 pvt->datalen += i;
00067
00068 while (i--)
00069 *dst++ = AST_LIN2A(*src++);
00070
00071 return 0;
00072 }
00073
00074 static struct ast_translator alawtolin = {
00075 .name = "alawtolin",
00076 .srcfmt = AST_FORMAT_ALAW,
00077 .dstfmt = AST_FORMAT_SLINEAR,
00078 .framein = alawtolin_framein,
00079 .sample = alaw_sample,
00080 .buffer_samples = BUFFER_SAMPLES,
00081 .buf_size = BUFFER_SAMPLES * 2,
00082 };
00083
00084 static struct ast_translator lintoalaw = {
00085 "lintoalaw",
00086 .srcfmt = AST_FORMAT_SLINEAR,
00087 .dstfmt = AST_FORMAT_ALAW,
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 res = ast_register_translator(&alawtolin);
00116 if (!res)
00117 res = ast_register_translator(&lintoalaw);
00118 else
00119 ast_unregister_translator(&alawtolin);
00120 if (res)
00121 return AST_MODULE_LOAD_FAILURE;
00122 return AST_MODULE_LOAD_SUCCESS;
00123 }
00124
00125 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "A-law Coder/Decoder",
00126 .load = load_module,
00127 .unload = unload_module,
00128 .reload = reload,
00129 );