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: 267539 $")
00029
00030 #include <fcntl.h>
00031 #include <netinet/in.h>
00032 #include <stdio.h>
00033 #include <stdlib.h>
00034 #include <string.h>
00035 #include <unistd.h>
00036
00037 #include "asterisk/lock.h"
00038 #include "asterisk/logger.h"
00039 #include "asterisk/module.h"
00040 #include "asterisk/config.h"
00041 #include "asterisk/options.h"
00042 #include "asterisk/translate.h"
00043 #include "asterisk/channel.h"
00044 #include "asterisk/alaw.h"
00045 #include "asterisk/utils.h"
00046
00047 #define BUFFER_SAMPLES 8096
00048
00049
00050
00051 #include "slin_ulaw_ex.h"
00052 #include "ulaw_slin_ex.h"
00053
00054
00055 static int alawtolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
00056 {
00057 int i = f->samples;
00058 unsigned char *src = f->data;
00059 int16_t *dst = (int16_t *)pvt->outbuf + pvt->samples;
00060
00061 pvt->samples += i;
00062 pvt->datalen += i * 2;
00063
00064 while (i--)
00065 *dst++ = AST_ALAW(*src++);
00066
00067 return 0;
00068 }
00069
00070
00071 static int lintoalaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
00072 {
00073 int i = f->samples;
00074 char *dst = pvt->outbuf + pvt->samples;
00075 int16_t *src = f->data;
00076
00077 pvt->samples += i;
00078 pvt->datalen += i;
00079
00080 while (i--)
00081 *dst++ = AST_LIN2A(*src++);
00082
00083 return 0;
00084 }
00085
00086
00087 static struct ast_frame *alawtolin_sample(void)
00088 {
00089 static struct ast_frame f;
00090 f.frametype = AST_FRAME_VOICE;
00091 f.subclass = AST_FORMAT_ALAW;
00092 f.datalen = sizeof(ulaw_slin_ex);
00093 f.samples = sizeof(ulaw_slin_ex);
00094 f.mallocd = 0;
00095 f.offset = 0;
00096 f.src = __PRETTY_FUNCTION__;
00097 f.data = ulaw_slin_ex;
00098 return &f;
00099 }
00100
00101
00102 static struct ast_frame *lintoalaw_sample(void)
00103 {
00104 static struct ast_frame f;
00105 f.frametype = AST_FRAME_VOICE;
00106 f.subclass = AST_FORMAT_SLINEAR;
00107 f.datalen = sizeof(slin_ulaw_ex);
00108 f.samples = sizeof(slin_ulaw_ex) / 2;
00109 f.mallocd = 0;
00110 f.offset = 0;
00111 f.src = __PRETTY_FUNCTION__;
00112 f.data = slin_ulaw_ex;
00113 return &f;
00114 }
00115
00116 static struct ast_translator alawtolin = {
00117 .name = "alawtolin",
00118 .srcfmt = AST_FORMAT_ALAW,
00119 .dstfmt = AST_FORMAT_SLINEAR,
00120 .framein = alawtolin_framein,
00121 .sample = alawtolin_sample,
00122 .buffer_samples = BUFFER_SAMPLES,
00123 .buf_size = BUFFER_SAMPLES * 2,
00124 };
00125
00126 static struct ast_translator lintoalaw = {
00127 "lintoalaw",
00128 .srcfmt = AST_FORMAT_SLINEAR,
00129 .dstfmt = AST_FORMAT_ALAW,
00130 .framein = lintoalaw_framein,
00131 .sample = lintoalaw_sample,
00132 .buffer_samples = BUFFER_SAMPLES,
00133 .buf_size = BUFFER_SAMPLES,
00134 };
00135
00136
00137
00138 static int reload(void)
00139 {
00140 return 0;
00141 }
00142
00143 static int unload_module(void)
00144 {
00145 int res;
00146
00147 res = ast_unregister_translator(&lintoalaw);
00148 res |= ast_unregister_translator(&alawtolin);
00149
00150 return res;
00151 }
00152
00153 static int load_module(void)
00154 {
00155 int res;
00156
00157 res = ast_register_translator(&alawtolin);
00158 if (!res)
00159 res = ast_register_translator(&lintoalaw);
00160 else
00161 ast_unregister_translator(&alawtolin);
00162
00163 return res;
00164 }
00165
00166 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "A-law Coder/Decoder",
00167 .load = load_module,
00168 .unload = unload_module,
00169 .reload = reload,
00170 );