Remove unnecessary code relating to PLC.
[asterisk/asterisk.git] / codecs / codec_ulaw.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * Mark Spencer <markster@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18
19 /*! \file
20  *
21  * \brief codec_ulaw.c - translate between signed linear and ulaw
22  * 
23  * \ingroup codecs
24  */
25
26 #include "asterisk.h"
27
28 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
29
30 #include "asterisk/module.h"
31 #include "asterisk/config.h"
32 #include "asterisk/translate.h"
33 #include "asterisk/ulaw.h"
34 #include "asterisk/utils.h"
35
36 #define BUFFER_SAMPLES   8096   /* size for the translation buffers */
37
38 /* Sample frame data */
39 #include "asterisk/slin.h"
40 #include "ex_ulaw.h"
41
42 /*! \brief convert and store samples in outbuf */
43 static int ulawtolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
44 {
45         int i = f->samples;
46         unsigned char *src = f->data.ptr;
47         int16_t *dst = pvt->outbuf.i16 + pvt->samples;
48
49         pvt->samples += i;
50         pvt->datalen += i * 2;  /* 2 bytes/sample */
51
52         /* convert and copy in outbuf */
53         while (i--)
54                 *dst++ = AST_MULAW(*src++);
55
56         return 0;
57 }
58
59 /*! \brief convert and store samples in outbuf */
60 static int lintoulaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
61 {
62         int i = f->samples;
63         char *dst = pvt->outbuf.c + pvt->samples;
64         int16_t *src = f->data.ptr;
65
66         pvt->samples += i;
67         pvt->datalen += i;      /* 1 byte/sample */
68
69         while (i--)
70                 *dst++ = AST_LIN2MU(*src++);
71
72         return 0;
73 }
74
75 /*!
76  * \brief The complete translator for ulawToLin.
77  */
78
79 static struct ast_translator ulawtolin = {
80         .name = "ulawtolin",
81         .srcfmt = AST_FORMAT_ULAW,
82         .dstfmt = AST_FORMAT_SLINEAR,
83         .framein = ulawtolin_framein,
84         .sample = ulaw_sample,
85         .buffer_samples = BUFFER_SAMPLES,
86         .buf_size = BUFFER_SAMPLES * 2,
87 };
88
89 static struct ast_translator testlawtolin = {
90         .name = "testlawtolin",
91         .srcfmt = AST_FORMAT_TESTLAW,
92         .dstfmt = AST_FORMAT_SLINEAR,
93         .framein = ulawtolin_framein,
94         .sample = ulaw_sample,
95         .buffer_samples = BUFFER_SAMPLES,
96         .buf_size = BUFFER_SAMPLES * 2,
97 };
98
99 /*!
100  * \brief The complete translator for LinToulaw.
101  */
102
103 static struct ast_translator lintoulaw = {
104         .name = "lintoulaw",
105         .srcfmt = AST_FORMAT_SLINEAR,
106         .dstfmt = AST_FORMAT_ULAW,
107         .framein = lintoulaw_framein,
108         .sample = slin8_sample,
109         .buf_size = BUFFER_SAMPLES,
110         .buffer_samples = BUFFER_SAMPLES,
111 };
112
113 static struct ast_translator lintotestlaw = {
114         .name = "lintotestlaw",
115         .srcfmt = AST_FORMAT_SLINEAR,
116         .dstfmt = AST_FORMAT_TESTLAW,
117         .framein = lintoulaw_framein,
118         .sample = slin8_sample,
119         .buf_size = BUFFER_SAMPLES,
120         .buffer_samples = BUFFER_SAMPLES,
121 };
122
123 static int reload(void)
124 {
125         return AST_MODULE_LOAD_SUCCESS;
126 }
127
128 static int unload_module(void)
129 {
130         int res;
131
132         res = ast_unregister_translator(&lintoulaw);
133         res |= ast_unregister_translator(&ulawtolin);
134         res |= ast_unregister_translator(&testlawtolin);
135         res |= ast_unregister_translator(&lintotestlaw);
136
137         return res;
138 }
139
140 static int load_module(void)
141 {
142         int res;
143
144         res = ast_register_translator(&ulawtolin);
145         if (!res) {
146                 res = ast_register_translator(&lintoulaw);
147                 res |= ast_register_translator(&lintotestlaw);
148                 res |= ast_register_translator(&testlawtolin);
149         } else
150                 ast_unregister_translator(&ulawtolin);
151         if (res)
152                 return AST_MODULE_LOAD_FAILURE;
153         return AST_MODULE_LOAD_SUCCESS;
154 }
155
156 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "mu-Law Coder/Decoder",
157                 .load = load_module,
158                 .unload = unload_module,
159                 .reload = reload,
160                );