Several changes to codec_dahdi to play nice with G723.
[asterisk/asterisk.git] / codecs / codec_dahdi.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * DAHDI native transcoding support
5  *
6  * Copyright (C) 1999 - 2008, Digium, Inc.
7  *
8  * Mark Spencer <markster@digium.com>
9  * Kevin P. Fleming <kpfleming@digium.com>
10  *
11  * See http://www.asterisk.org for more information about
12  * the Asterisk project. Please do not directly contact
13  * any of the maintainers of this project for assistance;
14  * the project provides a web site, mailing lists and IRC
15  * channels for your use.
16  *
17  * This program is free software, distributed under the terms of
18  * the GNU General Public License Version 2. See the LICENSE file
19  * at the top of the source tree.
20  */
21
22 /*! \file
23  *
24  * \brief Translate between various formats natively through DAHDI transcoding
25  *
26  * \ingroup codecs
27  */
28
29 /*** MODULEINFO
30         <depend>dahdi</depend>
31  ***/
32
33 #include "asterisk.h"
34
35 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
36
37 #include <fcntl.h>
38 #include <netinet/in.h>
39 #include <sys/ioctl.h>
40 #include <sys/mman.h>
41 #include <sys/poll.h>
42 #include <dahdi/user.h>
43
44 #include "asterisk/lock.h"
45 #include "asterisk/translate.h"
46 #include "asterisk/config.h"
47 #include "asterisk/module.h"
48 #include "asterisk/cli.h"
49 #include "asterisk/channel.h"
50 #include "asterisk/utils.h"
51 #include "asterisk/linkedlists.h"
52 #include "asterisk/ulaw.h"
53
54 #define BUFFER_SIZE 8000
55
56 #define G723_SAMPLES 240
57 #define G729_SAMPLES 160
58
59 static unsigned int global_useplc = 0;
60
61 static struct channel_usage {
62         int total;
63         int encoders;
64         int decoders;
65 } channels;
66
67 static char *handle_cli_transcoder_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
68
69 static struct ast_cli_entry cli[] = {
70         AST_CLI_DEFINE(handle_cli_transcoder_show, "Display DAHDI transcoder utilization.")
71 };
72
73 struct format_map {
74         unsigned int map[32][32];
75 };
76
77 static struct format_map global_format_map = { { { 0 } } };
78
79 struct translator {
80         struct ast_translator t;
81         AST_LIST_ENTRY(translator) entry;
82 };
83
84 static AST_LIST_HEAD_STATIC(translators, translator);
85
86 struct codec_dahdi_pvt {
87         int fd;
88         struct dahdi_transcoder_formats fmts;
89         unsigned int softslin:1;
90         unsigned int fake:2;
91         uint16_t required_samples;
92         uint16_t samples_in_buffer;
93         uint8_t ulaw_buffer[1024];
94 };
95
96 /* Only used by a decoder */
97 static int ulawtolin(struct ast_trans_pvt *pvt)
98 {
99         struct codec_dahdi_pvt *dahdip = pvt->pvt;
100         int i = dahdip->required_samples;
101         uint8_t *src = &dahdip->ulaw_buffer[0];
102         int16_t *dst = pvt->outbuf.i16 + pvt->datalen;
103
104         /* convert and copy in outbuf */
105         while (i--) {
106                 *dst++ = AST_MULAW(*src++);
107         }
108
109         return 0;
110 }
111
112 /* Only used by an encoder. */
113 static int lintoulaw(struct ast_trans_pvt *pvt, struct ast_frame *f)
114 {
115         struct codec_dahdi_pvt *dahdip = pvt->pvt;
116         int i = f->samples;
117         uint8_t *dst = &dahdip->ulaw_buffer[dahdip->samples_in_buffer];
118         int16_t *src = f->data.ptr;
119
120         if (dahdip->samples_in_buffer + i > sizeof(dahdip->ulaw_buffer)) {
121                 ast_log(LOG_ERROR, "Out of buffer space!\n");
122                 return -i;
123         }
124
125         while (i--) {
126                 *dst++ = AST_LIN2MU(*src++);
127         }
128
129         dahdip->samples_in_buffer += f->samples;
130         return 0;
131 }
132
133 static char *handle_cli_transcoder_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
134 {
135         struct channel_usage copy;
136
137         switch (cmd) {
138         case CLI_INIT:
139                 e->command = "transcoder show";
140                 e->usage =
141                         "Usage: transcoder show\n"
142                         "       Displays channel utilization of DAHDI transcoder(s).\n";
143                 return NULL;
144         case CLI_GENERATE:
145                 return NULL;
146         }
147
148         if (a->argc != 2)
149                 return CLI_SHOWUSAGE;
150
151         copy = channels;
152
153         if (copy.total == 0)
154                 ast_cli(a->fd, "No DAHDI transcoders found.\n");
155         else
156                 ast_cli(a->fd, "%d/%d encoders/decoders of %d channels are in use.\n", copy.encoders, copy.decoders, copy.total);
157
158         return CLI_SUCCESS;
159 }
160
161 static void dahdi_write_frame(struct codec_dahdi_pvt *dahdip, const uint8_t *buffer, const ssize_t count)
162 {
163         int res;
164         struct pollfd p = {0};
165         if (!count) return;
166         res = write(dahdip->fd, buffer, count);
167         if (option_verbose > 10) {
168                 if (-1 == res) {
169                         ast_log(LOG_ERROR, "Failed to write to transcoder: %s\n", strerror(errno));
170                 }
171                 if (count != res) {
172                         ast_log(LOG_ERROR, "Requested write of %zd bytes, but only wrote %d bytes.\n", count, res);
173                 }
174         }
175         p.fd = dahdip->fd;
176         p.events = POLLOUT;
177         res = poll(&p, 1, 50);
178 }
179
180 static int dahdi_encoder_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
181 {
182         struct codec_dahdi_pvt *dahdip = pvt->pvt;
183
184         if (!f->subclass) {
185                 /* We're just faking a return for calculation purposes. */
186                 dahdip->fake = 2;
187                 pvt->samples = f->samples;
188                 return 0;
189         }
190
191         /* Buffer up the packets and send them to the hardware if we
192          * have enough samples set up. */
193         if (dahdip->softslin) {
194                 if (lintoulaw(pvt, f)) {
195                          return -1;
196                 }
197         } else {
198                 /* NOTE:  If softslin support is not needed, and the sample
199                  * size is equal to the required sample size, we wouldn't
200                  * need this copy operation.  But at the time this was
201                  * written, only softslin is supported. */
202                 if (dahdip->samples_in_buffer + f->samples > sizeof(dahdip->ulaw_buffer)) {
203                         ast_log(LOG_ERROR, "Out of buffer space.\n");
204                         return -1;
205                 }
206                 memcpy(&dahdip->ulaw_buffer[dahdip->samples_in_buffer], f->data.ptr, f->samples);
207                 dahdip->samples_in_buffer += f->samples;
208         }
209
210         while (dahdip->samples_in_buffer > dahdip->required_samples) {
211                 dahdi_write_frame(dahdip, dahdip->ulaw_buffer, dahdip->required_samples);
212                 dahdip->samples_in_buffer -= dahdip->required_samples;
213                 if (dahdip->samples_in_buffer) {
214                         /* Shift any remaining bytes down. */
215                         memmove(dahdip->ulaw_buffer, &dahdip->ulaw_buffer[dahdip->required_samples],
216                                 dahdip->samples_in_buffer);
217                 }
218         }
219         pvt->samples += f->samples;
220         pvt->datalen = 0;
221         return -1;
222 }
223
224 static struct ast_frame *dahdi_encoder_frameout(struct ast_trans_pvt *pvt)
225 {
226         struct codec_dahdi_pvt *dahdip = pvt->pvt;
227         int res;
228
229         if (2 == dahdip->fake) {
230                 dahdip->fake = 1;
231                 pvt->f.frametype = AST_FRAME_VOICE;
232                 pvt->f.subclass = 0;
233                 pvt->f.samples = dahdip->required_samples;
234                 pvt->f.data.ptr = NULL;
235                 pvt->f.offset = 0;
236                 pvt->f.datalen = 0;
237                 pvt->f.mallocd = 0;
238                 ast_set_flag(&pvt->f, AST_FRFLAG_FROM_TRANSLATOR);
239                 pvt->samples = 0;
240
241                 return &pvt->f;
242
243         } else if (1 == dahdip->fake) {
244                 dahdip->fake = 0;
245                 return NULL;
246         }
247
248         res = read(dahdip->fd, pvt->outbuf.c + pvt->datalen, pvt->t->buf_size - pvt->datalen);
249         if (-1 == res) {
250                 if (EWOULDBLOCK == errno) {
251                         /* Nothing waiting... */
252                         return NULL;
253                 } else {
254                         ast_log(LOG_ERROR, "Failed to read from transcoder: %s\n", strerror(errno));
255                         return NULL;
256                 }
257         } else {
258                 pvt->f.datalen = res;
259                 pvt->f.samples = dahdip->required_samples;
260                 pvt->f.frametype = AST_FRAME_VOICE;
261                 pvt->f.subclass = 1 <<  (pvt->t->dstfmt);
262                 pvt->f.mallocd = 0;
263                 pvt->f.offset = AST_FRIENDLY_OFFSET;
264                 pvt->f.src = pvt->t->name;
265                 pvt->f.data.ptr = pvt->outbuf.c;
266                 ast_set_flag(&pvt->f, AST_FRFLAG_FROM_TRANSLATOR);
267
268                 pvt->samples = 0;
269                 pvt->datalen = 0;
270                 return &pvt->f;
271         }
272
273         /* Shouldn't get here... */
274         return NULL;
275 }
276
277 static int dahdi_decoder_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
278 {
279         struct codec_dahdi_pvt *dahdip = pvt->pvt;
280
281         if (!f->subclass) {
282                 /* We're just faking a return for calculation purposes. */
283                 dahdip->fake = 2;
284                 pvt->samples = f->samples;
285                 return 0;
286         }
287
288         if (!f->datalen) {
289                 if (f->samples != dahdip->required_samples) {
290                         ast_log(LOG_ERROR, "%d != %d %d\n", f->samples, dahdip->required_samples, f->datalen);
291                 }
292         }
293         dahdi_write_frame(dahdip, f->data.ptr, f->datalen);
294         pvt->samples += f->samples;
295         pvt->datalen = 0;
296         return -1;
297 }
298
299 static struct ast_frame *dahdi_decoder_frameout(struct ast_trans_pvt *pvt)
300 {
301         int res;
302         struct codec_dahdi_pvt *dahdip = pvt->pvt;
303
304         if (2 == dahdip->fake) {
305                 dahdip->fake = 1;
306                 pvt->f.frametype = AST_FRAME_VOICE;
307                 pvt->f.subclass = 0;
308                 pvt->f.samples = dahdip->required_samples;
309                 pvt->f.data.ptr = NULL;
310                 pvt->f.offset = 0;
311                 pvt->f.datalen = 0;
312                 pvt->f.mallocd = 0;
313                 ast_set_flag(&pvt->f, AST_FRFLAG_FROM_TRANSLATOR);
314                 pvt->samples = 0;
315                 return &pvt->f;
316         } else if (1 == dahdip->fake) {
317                 pvt->samples = 0;
318                 dahdip->fake = 0;
319                 return NULL;
320         }
321
322         /* Let's check to see if there is a new frame for us.... */
323         if (dahdip->softslin) {
324                 res = read(dahdip->fd, dahdip->ulaw_buffer, sizeof(dahdip->ulaw_buffer));
325         } else {
326                 res = read(dahdip->fd, pvt->outbuf.c + pvt->datalen, pvt->t->buf_size - pvt->datalen);
327         }
328
329         if (-1 == res) {
330                 if (EWOULDBLOCK == errno) {
331                         /* Nothing waiting... */
332                         return NULL;
333                 } else {
334                         ast_log(LOG_ERROR, "Failed to read from transcoder: %s\n", strerror(errno));
335                         return NULL;
336                 }
337         } else {
338                 if (dahdip->softslin) {
339                         ulawtolin(pvt);
340                         pvt->f.datalen = res * 2;
341                 } else {
342                         pvt->f.datalen = res;
343                 }
344                 pvt->datalen = 0;
345                 pvt->f.frametype = AST_FRAME_VOICE;
346                 pvt->f.subclass = 1 <<  (pvt->t->dstfmt);
347                 pvt->f.mallocd = 0;
348                 pvt->f.offset = AST_FRIENDLY_OFFSET;
349                 pvt->f.src = pvt->t->name;
350                 pvt->f.data.ptr = pvt->outbuf.c;
351                 pvt->f.samples = dahdip->required_samples;
352                 ast_set_flag(&pvt->f, AST_FRFLAG_FROM_TRANSLATOR);
353                 pvt->samples = 0;
354
355                 return &pvt->f;
356         }
357
358         /* Shouldn't get here... */
359         return NULL;
360 }
361
362
363 static void dahdi_destroy(struct ast_trans_pvt *pvt)
364 {
365         struct codec_dahdi_pvt *dahdip = pvt->pvt;
366
367         switch (dahdip->fmts.dstfmt) {
368         case AST_FORMAT_G729A:
369         case AST_FORMAT_G723_1:
370                 ast_atomic_fetchadd_int(&channels.encoders, -1);
371                 break;
372         default:
373                 ast_atomic_fetchadd_int(&channels.decoders, -1);
374                 break;
375         }
376
377         close(dahdip->fd);
378 }
379
380 static int dahdi_translate(struct ast_trans_pvt *pvt, int dest, int source)
381 {
382         /* Request translation through zap if possible */
383         int fd;
384         struct codec_dahdi_pvt *dahdip = pvt->pvt;
385         int flags;
386         int tried_once = 0;
387         const char *dev_filename = "/dev/dahdi/transcode";
388
389         if ((fd = open(dev_filename, O_RDWR)) < 0) {
390                 ast_log(LOG_ERROR, "Failed to open %s: %s\n", dev_filename, strerror(errno));
391                 return -1;
392         }
393
394         dahdip->fmts.srcfmt = (1 << source);
395         dahdip->fmts.dstfmt = (1 << dest);
396
397         ast_log(LOG_DEBUG, "Opening transcoder channel from %d to %d.\n", source, dest);
398
399 retry:
400         if (ioctl(fd, DAHDI_TC_ALLOCATE, &dahdip->fmts)) {
401                 if ((ENODEV == errno) && !tried_once) {
402                         /* We requested to translate to/from an unsupported
403                          * format.  Most likely this is because signed linear
404                          * was not supported by any hardware devices even
405                          * though this module always registers signed linear
406                          * support. In this case we'll retry, requesting
407                          * support for ULAW instead of signed linear and then
408                          * we'll just convert from ulaw to signed linear in
409                          * software. */
410                         if (AST_FORMAT_SLINEAR == dahdip->fmts.srcfmt) {
411                                 ast_log(LOG_DEBUG, "Using soft_slin support on source\n");
412                                 dahdip->softslin = 1;
413                                 dahdip->fmts.srcfmt = AST_FORMAT_ULAW;
414                         } else if (AST_FORMAT_SLINEAR == dahdip->fmts.dstfmt) {
415                                 ast_log(LOG_DEBUG, "Using soft_slin support on destination\n");
416                                 dahdip->softslin = 1;
417                                 dahdip->fmts.dstfmt = AST_FORMAT_ULAW;
418                         }
419                         tried_once = 1;
420                         goto retry;
421                 }
422                 ast_log(LOG_ERROR, "Unable to attach to transcoder: %s\n", strerror(errno));
423                 close(fd);
424
425                 return -1;
426         }
427
428         flags = fcntl(fd, F_GETFL);
429         if (flags > - 1) {
430                 if (fcntl(fd, F_SETFL, flags | O_NONBLOCK))
431                         ast_log(LOG_WARNING, "Could not set non-block mode!\n");
432         }
433
434         dahdip->fd = fd;
435
436         dahdip->required_samples = ((dahdip->fmts.dstfmt|dahdip->fmts.srcfmt)&AST_FORMAT_G723_1) ? G723_SAMPLES : G729_SAMPLES;
437
438         switch (dahdip->fmts.dstfmt) {
439         case AST_FORMAT_G729A:
440                 ast_atomic_fetchadd_int(&channels.encoders, +1);
441                 break;
442         case AST_FORMAT_G723_1:
443                 ast_atomic_fetchadd_int(&channels.encoders, +1);
444                 break;
445         default:
446                 ast_atomic_fetchadd_int(&channels.decoders, +1);
447                 break;
448         }
449
450         return 0;
451 }
452
453 static int dahdi_new(struct ast_trans_pvt *pvt)
454 {
455         return dahdi_translate(pvt, pvt->t->dstfmt, pvt->t->srcfmt);
456 }
457
458 static struct ast_frame *fakesrc_sample(void)
459 {
460         /* Don't bother really trying to test hardware ones. */
461         static struct ast_frame f = {
462                 .frametype = AST_FRAME_VOICE,
463                 .samples = 160,
464                 .src = __PRETTY_FUNCTION__
465         };
466
467         return &f;
468 }
469
470 static int is_encoder(struct translator *zt)
471 {
472         if (zt->t.srcfmt&(AST_FORMAT_ULAW|AST_FORMAT_ALAW|AST_FORMAT_SLINEAR)) {
473                 return 1;
474         } else {
475                 return 0;
476         }
477 }
478
479 static int register_translator(int dst, int src)
480 {
481         struct translator *zt;
482         int res;
483
484         if (!(zt = ast_calloc(1, sizeof(*zt)))) {
485                 return -1;
486         }
487
488         snprintf((char *) (zt->t.name), sizeof(zt->t.name), "zap%sto%s",
489                  ast_getformatname((1 << src)), ast_getformatname((1 << dst)));
490         zt->t.srcfmt = (1 << src);
491         zt->t.dstfmt = (1 << dst);
492         zt->t.buf_size = BUFFER_SIZE;
493         if (is_encoder(zt)) {
494                 zt->t.framein = dahdi_encoder_framein;
495                 zt->t.frameout = dahdi_encoder_frameout;
496 #if 0
497                 zt->t.buffer_samples = 0;
498 #endif
499         } else {
500                 zt->t.framein = dahdi_decoder_framein;
501                 zt->t.frameout = dahdi_decoder_frameout;
502 #if 0
503                 if (AST_FORMAT_G723_1 == zt->t.srcfmt) {
504                         zt->t.plc_samples = G723_SAMPLES;
505                 } else {
506                         zt->t.plc_samples = G729_SAMPLES;
507                 }
508                 zt->t.buffer_samples = zt->t.plc_samples * 8;
509 #endif
510         }
511         zt->t.destroy = dahdi_destroy;
512         zt->t.buffer_samples = 0;
513         zt->t.newpvt = dahdi_new;
514         zt->t.sample = fakesrc_sample;
515 #if 0
516         zt->t.useplc = global_useplc;
517 #endif
518         zt->t.useplc = 0;
519         zt->t.native_plc = 0;
520
521         zt->t.desc_size = sizeof(struct codec_dahdi_pvt);
522         if ((res = ast_register_translator(&zt->t))) {
523                 ast_free(zt);
524                 return -1;
525         }
526
527         AST_LIST_LOCK(&translators);
528         AST_LIST_INSERT_HEAD(&translators, zt, entry);
529         AST_LIST_UNLOCK(&translators);
530
531         global_format_map.map[dst][src] = 1;
532
533         return res;
534 }
535
536 static void drop_translator(int dst, int src)
537 {
538         struct translator *cur;
539
540         AST_LIST_LOCK(&translators);
541         AST_LIST_TRAVERSE_SAFE_BEGIN(&translators, cur, entry) {
542                 if (cur->t.srcfmt != src)
543                         continue;
544
545                 if (cur->t.dstfmt != dst)
546                         continue;
547
548                 AST_LIST_REMOVE_CURRENT(entry);
549                 ast_unregister_translator(&cur->t);
550                 ast_free(cur);
551                 global_format_map.map[dst][src] = 0;
552                 break;
553         }
554         AST_LIST_TRAVERSE_SAFE_END;
555         AST_LIST_UNLOCK(&translators);
556 }
557
558 static void unregister_translators(void)
559 {
560         struct translator *cur;
561
562         AST_LIST_LOCK(&translators);
563         while ((cur = AST_LIST_REMOVE_HEAD(&translators, entry))) {
564                 ast_unregister_translator(&cur->t);
565                 ast_free(cur);
566         }
567         AST_LIST_UNLOCK(&translators);
568 }
569
570 static int parse_config(int reload)
571 {
572         struct ast_variable *var;
573         struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
574         struct ast_config *cfg = ast_config_load("codecs.conf", config_flags);
575
576         if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID)
577                 return 0;
578
579         for (var = ast_variable_browse(cfg, "plc"); var; var = var->next) {
580                if (!strcasecmp(var->name, "genericplc")) {
581                        global_useplc = ast_true(var->value);
582                        ast_verb(3, "codec_dahdi: %susing generic PLC\n",
583                                 global_useplc ? "" : "not ");
584                }
585         }
586
587         ast_config_destroy(cfg);
588         return 0;
589 }
590
591 static void build_translators(struct format_map *map, unsigned int dstfmts, unsigned int srcfmts)
592 {
593         unsigned int src, dst;
594
595         for (src = 0; src < 32; src++) {
596                 for (dst = 0; dst < 32; dst++) {
597                         if (!(srcfmts & (1 << src)))
598                                 continue;
599
600                         if (!(dstfmts & (1 << dst)))
601                                 continue;
602
603                         if (global_format_map.map[dst][src])
604                                 continue;
605
606                         if (!register_translator(dst, src))
607                                 map->map[dst][src] = 1;
608                 }
609         }
610 }
611
612 static int find_transcoders(void)
613 {
614         struct dahdi_transcoder_info info = { 0, };
615         struct format_map map = { { { 0 } } };
616         int fd, res;
617         unsigned int x, y;
618
619         if ((fd = open("/dev/dahdi/transcode", O_RDWR)) < 0) {
620                 ast_log(LOG_ERROR, "Failed to open /dev/dahdi/transcode: %s\n", strerror(errno));
621                 return 0;
622         }
623
624         for (info.tcnum = 0; !(res = ioctl(fd, DAHDI_TC_GETINFO, &info)); info.tcnum++) {
625                 if (option_verbose > 1)
626                         ast_verbose(VERBOSE_PREFIX_2 "Found transcoder '%s'.\n", info.name);
627
628                 /* Complex codecs need to support signed linear.  If the
629                  * hardware transcoder does not natively support signed linear
630                  * format, we will emulate it in software directly in this
631                  * module. Also, do not allow direct ulaw/alaw to complex
632                  * codec translation, since that will prevent the generic PLC
633                  * functions from working. */
634                 if (info.dstfmts & (AST_FORMAT_ULAW | AST_FORMAT_ALAW)) {
635                         info.dstfmts |= AST_FORMAT_SLINEAR;
636                         info.dstfmts &= ~(AST_FORMAT_ULAW | AST_FORMAT_ALAW);
637                 }
638                 if (info.srcfmts & (AST_FORMAT_ULAW | AST_FORMAT_ALAW)) {
639                         info.srcfmts |= AST_FORMAT_SLINEAR;
640                         info.srcfmts &= ~(AST_FORMAT_ULAW | AST_FORMAT_ALAW);
641                 }
642
643                 build_translators(&map, info.dstfmts, info.srcfmts);
644                 ast_atomic_fetchadd_int(&channels.total, info.numchannels / 2);
645
646         }
647
648         close(fd);
649
650         if (!info.tcnum && (option_verbose > 1))
651                 ast_verbose(VERBOSE_PREFIX_2 "No hardware transcoders found.\n");
652
653         for (x = 0; x < 32; x++) {
654                 for (y = 0; y < 32; y++) {
655                         if (!map.map[x][y] && global_format_map.map[x][y])
656                                 drop_translator(x, y);
657                 }
658         }
659
660         return 0;
661 }
662
663 static int reload(void)
664 {
665         struct translator *cur;
666
667         if (parse_config(1))
668                 return AST_MODULE_LOAD_DECLINE;
669
670         AST_LIST_LOCK(&translators);
671         AST_LIST_TRAVERSE(&translators, cur, entry)
672                 cur->t.useplc = global_useplc;
673         AST_LIST_UNLOCK(&translators);
674
675         return AST_MODULE_LOAD_SUCCESS;
676 }
677
678 static int unload_module(void)
679 {
680         ast_cli_unregister_multiple(cli, ARRAY_LEN(cli));
681         unregister_translators();
682
683         return 0;
684 }
685
686 static int load_module(void)
687 {
688         ast_ulaw_init();
689         if (parse_config(0))
690                 return AST_MODULE_LOAD_DECLINE;
691         find_transcoders();
692         ast_cli_register_multiple(cli, ARRAY_LEN(cli));
693         return AST_MODULE_LOAD_SUCCESS;
694 }
695
696 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Generic DAHDI Transcoder Codec Translator",
697                 .load = load_module,
698                 .unload = unload_module,
699                 .reload = reload,
700                );