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: 229284 $")
00033
00034 #include "asterisk/lock.h"
00035 #include "asterisk/linkedlists.h"
00036 #include "asterisk/module.h"
00037 #include "asterisk/config.h"
00038 #include "asterisk/translate.h"
00039 #include "asterisk/utils.h"
00040
00041 #define WANT_ASM
00042 #include "log2comp.h"
00043
00044
00045
00046
00047 #if defined(NOT_BLI)
00048 # if defined(_MSC_VER)
00049 typedef __int64 sint64;
00050 # elif defined(__GNUC__)
00051 typedef long long sint64;
00052 # else
00053 # error 64-bit integer type is not defined for your compiler/platform
00054 # endif
00055 #endif
00056
00057 #define BUFFER_SAMPLES 8096
00058 #define BUF_SHIFT 5
00059
00060
00061
00062 #include "slin_g726_ex.h"
00063 #include "g726_slin_ex.h"
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 struct g726_state {
00075 long yl;
00076 int yu;
00077 int dms;
00078 int dml;
00079 int ap;
00080 int a[2];
00081
00082 int b[6];
00083
00084 int pk[2];
00085
00086 int dq[6];
00087
00088
00089 int sr[2];
00090
00091
00092 int td;
00093 };
00094
00095 static int qtab_721[7] = {-124, 80, 178, 246, 300, 349, 400};
00096
00097
00098
00099
00100 static int _dqlntab[16] = {-2048, 4, 135, 213, 273, 323, 373, 425,
00101 425, 373, 323, 273, 213, 135, 4, -2048};
00102
00103
00104 static int _witab[16] = {-12, 18, 41, 64, 112, 198, 355, 1122,
00105 1122, 355, 198, 112, 64, 41, 18, -12};
00106
00107
00108
00109
00110
00111 static int _fitab[16] = {0, 0, 0, 0x200, 0x200, 0x200, 0x600, 0xE00,
00112 0xE00, 0x600, 0x200, 0x200, 0x200, 0, 0, 0};
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 static void g726_init_state(struct g726_state *state_ptr)
00123 {
00124 int cnta;
00125
00126 state_ptr->yl = 34816;
00127 state_ptr->yu = 544;
00128 state_ptr->dms = 0;
00129 state_ptr->dml = 0;
00130 state_ptr->ap = 0;
00131 for (cnta = 0; cnta < 2; cnta++) {
00132 state_ptr->a[cnta] = 0;
00133 state_ptr->pk[cnta] = 0;
00134 #ifdef NOT_BLI
00135 state_ptr->sr[cnta] = 1;
00136 #else
00137 state_ptr->sr[cnta] = 32;
00138 #endif
00139 }
00140 for (cnta = 0; cnta < 6; cnta++) {
00141 state_ptr->b[cnta] = 0;
00142 #ifdef NOT_BLI
00143 state_ptr->dq[cnta] = 1;
00144 #else
00145 state_ptr->dq[cnta] = 32;
00146 #endif
00147 }
00148 state_ptr->td = 0;
00149 }
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 static int quan(int val, int *table, int size)
00160 {
00161 int i;
00162
00163 for (i = 0; i < size && val >= *table; ++i, ++table)
00164 ;
00165 return (i);
00166 }
00167
00168 #ifdef NOT_BLI
00169
00170
00171
00172
00173
00174
00175
00176 static int predictor_zero(struct g726_state *state_ptr)
00177 {
00178 int i;
00179 sint64 sezi;
00180 for (sezi = 0, i = 0; i < 6; i++)
00181 sezi += (sint64)state_ptr->b[i] * state_ptr->dq[i];
00182 return (int)(sezi >> 13) / 2 ;
00183 }
00184
00185
00186
00187
00188
00189
00190
00191 static int predictor_pole(struct g726_state *state_ptr)
00192 {
00193 return (int)(((sint64)state_ptr->a[1] * state_ptr->sr[1] +
00194 (sint64)state_ptr->a[0] * state_ptr->sr[0]) >> 13) / 2 ;
00195 }
00196
00197 #else
00198
00199
00200
00201
00202
00203
00204 static int fmult(int an, int srn)
00205 {
00206 int anmag, anexp, anmant;
00207 int wanexp, wanmant;
00208 int retval;
00209
00210 anmag = (an > 0) ? an : ((-an) & 0x1FFF);
00211 anexp = ilog2(anmag) - 5;
00212 anmant = (anmag == 0) ? 32 :
00213 (anexp >= 0) ? anmag >> anexp : anmag << -anexp;
00214 wanexp = anexp + ((srn >> 6) & 0xF) - 13;
00215
00216 wanmant = (anmant * (srn & 077) + 0x30) >> 4;
00217 retval = (wanexp >= 0) ? ((wanmant << wanexp) & 0x7FFF) :
00218 (wanmant >> -wanexp);
00219
00220 return (((an ^ srn) < 0) ? -retval : retval);
00221 }
00222
00223 static int predictor_zero(struct g726_state *state_ptr)
00224 {
00225 int i;
00226 int sezi;
00227 for (sezi = 0, i = 0; i < 6; i++)
00228 sezi += fmult(state_ptr->b[i] >> 2, state_ptr->dq[i]);
00229 return sezi;
00230 }
00231
00232 static int predictor_pole(struct g726_state *state_ptr)
00233 {
00234 return (fmult(state_ptr->a[1] >> 2, state_ptr->sr[1]) +
00235 fmult(state_ptr->a[0] >> 2, state_ptr->sr[0]));
00236 }
00237
00238 #endif
00239
00240
00241
00242
00243
00244
00245
00246 static int step_size(struct g726_state *state_ptr)
00247 {
00248 int y;
00249 int dif;
00250 int al;
00251
00252 if (state_ptr->ap >= 256)
00253 return (state_ptr->yu);
00254 else {
00255 y = state_ptr->yl >> 6;
00256 dif = state_ptr->yu - y;
00257 al = state_ptr->ap >> 2;
00258 if (dif > 0)
00259 y += (dif * al) >> 6;
00260 else if (dif < 0)
00261 y += (dif * al + 0x3F) >> 6;
00262 return (y);
00263 }
00264 }
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275 static int quantize(
00276 int d,
00277 int y,
00278 int *table,
00279 int size)
00280 {
00281 int dqm;
00282 int exp;
00283 int mant;
00284 int dl;
00285 int dln;
00286 int i;
00287
00288
00289
00290
00291
00292
00293 dqm = abs(d);
00294 exp = ilog2(dqm);
00295 if (exp < 0)
00296 exp = 0;
00297 mant = ((dqm << 7) >> exp) & 0x7F;
00298 dl = (exp << 7) | mant;
00299
00300
00301
00302
00303
00304
00305 dln = dl - (y >> 2);
00306
00307
00308
00309
00310
00311
00312 i = quan(dln, table, size);
00313 if (d < 0)
00314 return ((size << 1) + 1 - i);
00315 else if (i == 0)
00316 return ((size << 1) + 1);
00317 else
00318 return (i);
00319 }
00320
00321
00322
00323
00324
00325
00326
00327
00328 static int reconstruct(
00329 int sign,
00330 int dqln,
00331 int y)
00332 {
00333 int dql;
00334 int dex;
00335 int dqt;
00336 int dq;
00337
00338 dql = dqln + (y >> 2);
00339
00340 if (dql < 0) {
00341 #ifdef NOT_BLI
00342 return (sign) ? -1 : 1;
00343 #else
00344 return (sign) ? -0x8000 : 0;
00345 #endif
00346 } else {
00347 dex = (dql >> 7) & 15;
00348 dqt = 128 + (dql & 127);
00349 #ifdef NOT_BLI
00350 dq = ((dqt << 19) >> (14 - dex));
00351 return (sign) ? -dq : dq;
00352 #else
00353 dq = (dqt << 7) >> (14 - dex);
00354 return (sign) ? (dq - 0x8000) : dq;
00355 #endif
00356 }
00357 }
00358
00359
00360
00361
00362
00363
00364 static void update(
00365 int code_size,
00366 int y,
00367 int wi,
00368 int fi,
00369 int dq,
00370 int sr,
00371 int dqsez,
00372 struct g726_state *state_ptr)
00373 {
00374 int cnt;
00375 int mag;
00376 #ifndef NOT_BLI
00377 int exp;
00378 #endif
00379 int a2p=0;
00380 int a1ul;
00381 int pks1;
00382 int fa1;
00383 int tr;
00384 int ylint, thr2, dqthr;
00385 int ylfrac, thr1;
00386 int pk0;
00387
00388 pk0 = (dqsez < 0) ? 1 : 0;
00389
00390 #ifdef NOT_BLI
00391 mag = abs(dq / 0x1000);
00392 #else
00393 mag = dq & 0x7FFF;
00394 #endif
00395
00396 ylint = state_ptr->yl >> 15;
00397 ylfrac = (state_ptr->yl >> 10) & 0x1F;
00398 thr1 = (32 + ylfrac) << ylint;
00399 thr2 = (ylint > 9) ? 31 << 10 : thr1;
00400 dqthr = (thr2 + (thr2 >> 1)) >> 1;
00401 if (state_ptr->td == 0)
00402 tr = 0;
00403 else if (mag <= dqthr)
00404 tr = 0;
00405 else
00406 tr = 1;
00407
00408
00409
00410
00411
00412
00413
00414 state_ptr->yu = y + ((wi - y) >> 5);
00415
00416
00417 if (state_ptr->yu < 544)
00418 state_ptr->yu = 544;
00419 else if (state_ptr->yu > 5120)
00420 state_ptr->yu = 5120;
00421
00422
00423
00424 state_ptr->yl += state_ptr->yu + ((-state_ptr->yl) >> 6);
00425
00426
00427
00428
00429 if (tr == 1) {
00430 state_ptr->a[0] = 0;
00431 state_ptr->a[1] = 0;
00432 state_ptr->b[0] = 0;
00433 state_ptr->b[1] = 0;
00434 state_ptr->b[2] = 0;
00435 state_ptr->b[3] = 0;
00436 state_ptr->b[4] = 0;
00437 state_ptr->b[5] = 0;
00438 } else {
00439 pks1 = pk0 ^ state_ptr->pk[0];
00440
00441
00442 a2p = state_ptr->a[1] - (state_ptr->a[1] >> 7);
00443 if (dqsez != 0) {
00444 fa1 = (pks1) ? state_ptr->a[0] : -state_ptr->a[0];
00445 if (fa1 < -8191)
00446 a2p -= 0x100;
00447 else if (fa1 > 8191)
00448 a2p += 0xFF;
00449 else
00450 a2p += fa1 >> 5;
00451
00452 if (pk0 ^ state_ptr->pk[1])
00453
00454 if (a2p <= -12160)
00455 a2p = -12288;
00456 else if (a2p >= 12416)
00457 a2p = 12288;
00458 else
00459 a2p -= 0x80;
00460 else if (a2p <= -12416)
00461 a2p = -12288;
00462 else if (a2p >= 12160)
00463 a2p = 12288;
00464 else
00465 a2p += 0x80;
00466 }
00467
00468
00469 state_ptr->a[1] = a2p;
00470
00471
00472
00473 state_ptr->a[0] -= state_ptr->a[0] >> 8;
00474 if (dqsez != 0) {
00475 if (pks1 == 0)
00476 state_ptr->a[0] += 192;
00477 else
00478 state_ptr->a[0] -= 192;
00479 }
00480
00481 a1ul = 15360 - a2p;
00482 if (state_ptr->a[0] < -a1ul)
00483 state_ptr->a[0] = -a1ul;
00484 else if (state_ptr->a[0] > a1ul)
00485 state_ptr->a[0] = a1ul;
00486
00487
00488 for (cnt = 0; cnt < 6; cnt++) {
00489 if (code_size == 5)
00490 state_ptr->b[cnt] -= state_ptr->b[cnt] >> 9;
00491 else
00492 state_ptr->b[cnt] -= state_ptr->b[cnt] >> 8;
00493 if (mag)
00494 {
00495 if ((dq ^ state_ptr->dq[cnt]) >= 0)
00496 state_ptr->b[cnt] += 128;
00497 else
00498 state_ptr->b[cnt] -= 128;
00499 }
00500 }
00501 }
00502
00503 for (cnt = 5; cnt > 0; cnt--)
00504 state_ptr->dq[cnt] = state_ptr->dq[cnt-1];
00505 #ifdef NOT_BLI
00506 state_ptr->dq[0] = dq;
00507 #else
00508
00509 if (mag == 0) {
00510 state_ptr->dq[0] = (dq >= 0) ? 0x20 : 0x20 - 0x400;
00511 } else {
00512 exp = ilog2(mag) + 1;
00513 state_ptr->dq[0] = (dq >= 0) ?
00514 (exp << 6) + ((mag << 6) >> exp) :
00515 (exp << 6) + ((mag << 6) >> exp) - 0x400;
00516 }
00517 #endif
00518
00519 state_ptr->sr[1] = state_ptr->sr[0];
00520 #ifdef NOT_BLI
00521 state_ptr->sr[0] = sr;
00522 #else
00523
00524 if (sr == 0) {
00525 state_ptr->sr[0] = 0x20;
00526 } else if (sr > 0) {
00527 exp = ilog2(sr) + 1;
00528 state_ptr->sr[0] = (exp << 6) + ((sr << 6) >> exp);
00529 } else if (sr > -0x8000) {
00530 mag = -sr;
00531 exp = ilog2(mag) + 1;
00532 state_ptr->sr[0] = (exp << 6) + ((mag << 6) >> exp) - 0x400;
00533 } else
00534 state_ptr->sr[0] = 0x20 - 0x400;
00535 #endif
00536
00537
00538 state_ptr->pk[1] = state_ptr->pk[0];
00539 state_ptr->pk[0] = pk0;
00540
00541
00542 if (tr == 1)
00543 state_ptr->td = 0;
00544 else if (a2p < -11776)
00545 state_ptr->td = 1;
00546 else
00547 state_ptr->td = 0;
00548
00549
00550
00551
00552 state_ptr->dms += (fi - state_ptr->dms) >> 5;
00553 state_ptr->dml += (((fi << 2) - state_ptr->dml) >> 7);
00554
00555 if (tr == 1)
00556 state_ptr->ap = 256;
00557 else if (y < 1536)
00558 state_ptr->ap += (0x200 - state_ptr->ap) >> 4;
00559 else if (state_ptr->td == 1)
00560 state_ptr->ap += (0x200 - state_ptr->ap) >> 4;
00561 else if (abs((state_ptr->dms << 2) - state_ptr->dml) >=
00562 (state_ptr->dml >> 3))
00563 state_ptr->ap += (0x200 - state_ptr->ap) >> 4;
00564 else
00565 state_ptr->ap += (-state_ptr->ap) >> 4;
00566 }
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577 static int g726_decode(int i, struct g726_state *state_ptr)
00578 {
00579 int sezi, sez, se;
00580 int y;
00581 int sr;
00582 int dq;
00583 int dqsez;
00584
00585 i &= 0x0f;
00586 #ifdef NOT_BLI
00587 sezi = predictor_zero(state_ptr);
00588 sez = sezi;
00589 se = sezi + predictor_pole(state_ptr);
00590 #else
00591 sezi = predictor_zero(state_ptr);
00592 sez = sezi >> 1;
00593 se = (sezi + predictor_pole(state_ptr)) >> 1;
00594 #endif
00595
00596 y = step_size(state_ptr);
00597
00598 dq = reconstruct(i & 8, _dqlntab[i], y);
00599
00600 #ifdef NOT_BLI
00601 sr = se + dq;
00602 dqsez = dq + sez;
00603 #else
00604 sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq;
00605 dqsez = sr - se + sez;
00606 #endif
00607
00608 update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr);
00609
00610 #ifdef NOT_BLI
00611 return (sr >> 10);
00612 #else
00613 return (sr << 2);
00614 #endif
00615 }
00616
00617
00618
00619
00620
00621
00622
00623 static int g726_encode(int sl, struct g726_state *state_ptr)
00624 {
00625 int sezi, se, sez;
00626 int d;
00627 int sr;
00628 int y;
00629 int dqsez;
00630 int dq, i;
00631
00632 #ifdef NOT_BLI
00633 sl <<= 10;
00634
00635 sezi = predictor_zero(state_ptr);
00636 sez = sezi;
00637 se = sezi + predictor_pole(state_ptr);
00638 #else
00639 sl >>= 2;
00640
00641 sezi = predictor_zero(state_ptr);
00642 sez = sezi >> 1;
00643 se = (sezi + predictor_pole(state_ptr)) >> 1;
00644 #endif
00645
00646 d = sl - se;
00647
00648
00649 y = step_size(state_ptr);
00650 #ifdef NOT_BLI
00651 d /= 0x1000;
00652 #endif
00653 i = quantize(d, y, qtab_721, 7);
00654
00655 dq = reconstruct(i & 8, _dqlntab[i], y);
00656
00657 #ifdef NOT_BLI
00658 sr = se + dq;
00659 dqsez = dq + sez;
00660 #else
00661 sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq;
00662 dqsez = sr - se + sez;
00663 #endif
00664
00665 update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr);
00666
00667 return (i);
00668 }
00669
00670
00671
00672
00673
00674
00675 struct g726_coder_pvt {
00676
00677 unsigned char next_flag;
00678 struct g726_state g726;
00679 };
00680
00681
00682 static int lintog726_new(struct ast_trans_pvt *pvt)
00683 {
00684 struct g726_coder_pvt *tmp = pvt->pvt;
00685
00686 g726_init_state(&tmp->g726);
00687
00688 return 0;
00689 }
00690
00691
00692 static int g726aal2tolin_framein (struct ast_trans_pvt *pvt, struct ast_frame *f)
00693 {
00694 struct g726_coder_pvt *tmp = pvt->pvt;
00695 unsigned char *src = f->data.ptr;
00696 int16_t *dst = pvt->outbuf.i16 + pvt->samples;
00697 unsigned int i;
00698
00699 for (i = 0; i < f->datalen; i++) {
00700 *dst++ = g726_decode((src[i] >> 4) & 0xf, &tmp->g726);
00701 *dst++ = g726_decode(src[i] & 0x0f, &tmp->g726);
00702 }
00703
00704 pvt->samples += f->samples;
00705 pvt->datalen += 2 * f->samples;
00706
00707 return 0;
00708 }
00709
00710
00711 static int lintog726aal2_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
00712 {
00713 struct g726_coder_pvt *tmp = pvt->pvt;
00714 int16_t *src = f->data.ptr;
00715 unsigned int i;
00716
00717 for (i = 0; i < f->samples; i++) {
00718 unsigned char d = g726_encode(src[i], &tmp->g726);
00719
00720 if (tmp->next_flag & 0x80) {
00721 pvt->outbuf.c[pvt->datalen++] = ((tmp->next_flag & 0xf)<< 4) | d;
00722 pvt->samples += 2;
00723 tmp->next_flag = 0;
00724 } else {
00725 tmp->next_flag = 0x80 | d;
00726 }
00727 }
00728
00729 return 0;
00730 }
00731
00732
00733 static int g726tolin_framein (struct ast_trans_pvt *pvt, struct ast_frame *f)
00734 {
00735 struct g726_coder_pvt *tmp = pvt->pvt;
00736 unsigned char *src = f->data.ptr;
00737 int16_t *dst = pvt->outbuf.i16 + pvt->samples;
00738 unsigned int i;
00739
00740 for (i = 0; i < f->datalen; i++) {
00741 *dst++ = g726_decode(src[i] & 0x0f, &tmp->g726);
00742 *dst++ = g726_decode((src[i] >> 4) & 0xf, &tmp->g726);
00743 }
00744
00745 pvt->samples += f->samples;
00746 pvt->datalen += 2 * f->samples;
00747
00748 return 0;
00749 }
00750
00751
00752 static int lintog726_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
00753 {
00754 struct g726_coder_pvt *tmp = pvt->pvt;
00755 int16_t *src = f->data.ptr;
00756 unsigned int i;
00757
00758 for (i = 0; i < f->samples; i++) {
00759 unsigned char d = g726_encode(src[i], &tmp->g726);
00760
00761 if (tmp->next_flag & 0x80) {
00762 pvt->outbuf.c[pvt->datalen++] = (d << 4) | (tmp->next_flag & 0xf);
00763 pvt->samples += 2;
00764 tmp->next_flag = 0;
00765 } else {
00766 tmp->next_flag = 0x80 | d;
00767 }
00768 }
00769
00770 return 0;
00771 }
00772
00773 static struct ast_frame *g726tolin_sample(void)
00774 {
00775 static struct ast_frame f = {
00776 .frametype = AST_FRAME_VOICE,
00777 .subclass = AST_FORMAT_G726,
00778 .datalen = sizeof(g726_slin_ex),
00779 .samples = sizeof(g726_slin_ex) * 2,
00780 .src = __PRETTY_FUNCTION__,
00781 .data.ptr = g726_slin_ex,
00782 };
00783
00784 return &f;
00785 }
00786
00787 static struct ast_frame *lintog726_sample (void)
00788 {
00789 static struct ast_frame f = {
00790 .frametype = AST_FRAME_VOICE,
00791 .subclass = AST_FORMAT_SLINEAR,
00792 .datalen = sizeof(slin_g726_ex),
00793 .samples = sizeof(slin_g726_ex) / 2,
00794 .src = __PRETTY_FUNCTION__,
00795 .data.ptr = slin_g726_ex,
00796 };
00797
00798 return &f;
00799 }
00800
00801 static struct ast_translator g726tolin = {
00802 .name = "g726tolin",
00803 .srcfmt = AST_FORMAT_G726,
00804 .dstfmt = AST_FORMAT_SLINEAR,
00805 .newpvt = lintog726_new,
00806 .framein = g726tolin_framein,
00807 .sample = g726tolin_sample,
00808 .desc_size = sizeof(struct g726_coder_pvt),
00809 .buffer_samples = BUFFER_SAMPLES,
00810 .buf_size = BUFFER_SAMPLES * 2,
00811 .plc_samples = 160,
00812 };
00813
00814 static struct ast_translator lintog726 = {
00815 .name = "lintog726",
00816 .srcfmt = AST_FORMAT_SLINEAR,
00817 .dstfmt = AST_FORMAT_G726,
00818 .newpvt = lintog726_new,
00819 .framein = lintog726_framein,
00820 .sample = lintog726_sample,
00821 .desc_size = sizeof(struct g726_coder_pvt),
00822 .buffer_samples = BUFFER_SAMPLES,
00823 .buf_size = BUFFER_SAMPLES/2,
00824 };
00825
00826 static struct ast_translator g726aal2tolin = {
00827 .name = "g726aal2tolin",
00828 .srcfmt = AST_FORMAT_G726_AAL2,
00829 .dstfmt = AST_FORMAT_SLINEAR,
00830 .newpvt = lintog726_new,
00831 .framein = g726aal2tolin_framein,
00832 .sample = g726tolin_sample,
00833 .desc_size = sizeof(struct g726_coder_pvt),
00834 .buffer_samples = BUFFER_SAMPLES,
00835 .buf_size = BUFFER_SAMPLES * 2,
00836 .plc_samples = 160,
00837 };
00838
00839 static struct ast_translator lintog726aal2 = {
00840 .name = "lintog726aal2",
00841 .srcfmt = AST_FORMAT_SLINEAR,
00842 .dstfmt = AST_FORMAT_G726_AAL2,
00843 .newpvt = lintog726_new,
00844 .framein = lintog726aal2_framein,
00845 .sample = lintog726_sample,
00846 .desc_size = sizeof(struct g726_coder_pvt),
00847 .buffer_samples = BUFFER_SAMPLES,
00848 .buf_size = BUFFER_SAMPLES / 2,
00849 };
00850
00851 static int parse_config(int reload)
00852 {
00853 struct ast_variable *var;
00854 struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
00855 struct ast_config *cfg = ast_config_load("codecs.conf", config_flags);
00856
00857 if (cfg == NULL)
00858 return 0;
00859 if (cfg == CONFIG_STATUS_FILEUNCHANGED)
00860 return 0;
00861 for (var = ast_variable_browse(cfg, "plc"); var; var = var->next) {
00862 if (!strcasecmp(var->name, "genericplc")) {
00863 g726tolin.useplc = ast_true(var->value) ? 1 : 0;
00864 ast_verb(3, "codec_g726: %susing generic PLC\n",
00865 g726tolin.useplc ? "" : "not ");
00866 }
00867 }
00868 ast_config_destroy(cfg);
00869 return 0;
00870 }
00871
00872 static int reload(void)
00873 {
00874 if (parse_config(1))
00875 return AST_MODULE_LOAD_DECLINE;
00876 return AST_MODULE_LOAD_SUCCESS;
00877 }
00878
00879 static int unload_module(void)
00880 {
00881 int res = 0;
00882
00883 res |= ast_unregister_translator(&g726tolin);
00884 res |= ast_unregister_translator(&lintog726);
00885
00886 res |= ast_unregister_translator(&g726aal2tolin);
00887 res |= ast_unregister_translator(&lintog726aal2);
00888
00889 return res;
00890 }
00891
00892 static int load_module(void)
00893 {
00894 int res = 0;
00895
00896
00897 if (parse_config(0))
00898 return AST_MODULE_LOAD_DECLINE;
00899
00900 res |= ast_register_translator(&g726tolin);
00901 res |= ast_register_translator(&lintog726);
00902
00903 res |= ast_register_translator(&g726aal2tolin);
00904 res |= ast_register_translator(&lintog726aal2);
00905
00906 if (res) {
00907 unload_module();
00908 return AST_MODULE_LOAD_FAILURE;
00909 }
00910
00911 return AST_MODULE_LOAD_SUCCESS;
00912 }
00913
00914 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "ITU G.726-32kbps G726 Transcoder",
00915 .load = load_module,
00916 .unload = unload_module,
00917 .reload = reload,
00918 );