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