diff options
Diffstat (limited to 'codecs')
-rw-r--r-- | codecs/codec_a_mu.c | 40 | ||||
-rw-r--r-- | codecs/codec_adpcm.c | 48 | ||||
-rw-r--r-- | codecs/codec_alaw.c | 49 | ||||
-rw-r--r-- | codecs/codec_dahdi.c | 399 | ||||
-rw-r--r-- | codecs/codec_g722.c | 62 | ||||
-rw-r--r-- | codecs/codec_g726.c | 62 | ||||
-rw-r--r-- | codecs/codec_gsm.c | 53 | ||||
-rw-r--r-- | codecs/codec_ilbc.c | 44 | ||||
-rw-r--r-- | codecs/codec_lpc10.c | 50 | ||||
-rw-r--r-- | codecs/codec_resample.c | 76 | ||||
-rw-r--r-- | codecs/codec_speex.c | 103 | ||||
-rw-r--r-- | codecs/codec_ulaw.c | 77 | ||||
-rw-r--r-- | codecs/ex_adpcm.h | 3 | ||||
-rw-r--r-- | codecs/ex_alaw.h | 2 | ||||
-rw-r--r-- | codecs/ex_g722.h | 2 | ||||
-rw-r--r-- | codecs/ex_g726.h | 2 | ||||
-rw-r--r-- | codecs/ex_gsm.h | 3 | ||||
-rw-r--r-- | codecs/ex_ilbc.h | 3 | ||||
-rw-r--r-- | codecs/ex_lpc10.h | 2 | ||||
-rw-r--r-- | codecs/ex_speex.h | 5 | ||||
-rw-r--r-- | codecs/ex_ulaw.h | 3 |
21 files changed, 803 insertions, 285 deletions
diff --git a/codecs/codec_a_mu.c b/codecs/codec_a_mu.c index 470f363e7..c21c706f5 100644 --- a/codecs/codec_a_mu.c +++ b/codecs/codec_a_mu.c @@ -80,6 +80,17 @@ static int ulawtoalaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) static struct ast_translator alawtoulaw = { .name = "alawtoulaw", + .src_codec = { + .name = "alaw", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .dst_codec = { + .name = "ulaw", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .format = "ulaw", .framein = alawtoulaw_framein, .sample = alaw_sample, .buffer_samples = BUFFER_SAMPLES, @@ -88,6 +99,17 @@ static struct ast_translator alawtoulaw = { static struct ast_translator ulawtoalaw = { .name = "ulawtoalaw", + .src_codec = { + .name = "ulaw", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .dst_codec = { + .name = "alaw", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .format = "alaw", .framein = ulawtoalaw_framein, .sample = ulaw_sample, .buffer_samples = BUFFER_SAMPLES, @@ -111,23 +133,19 @@ static int load_module(void) int res; int x; - ast_format_set(&alawtoulaw.src_format, AST_FORMAT_ALAW, 0); - ast_format_set(&alawtoulaw.dst_format, AST_FORMAT_ULAW, 0); - - ast_format_set(&ulawtoalaw.src_format, AST_FORMAT_ULAW, 0); - ast_format_set(&ulawtoalaw.dst_format, AST_FORMAT_ALAW, 0); - for (x=0;x<256;x++) { mu2a[x] = AST_LIN2A(AST_MULAW(x)); a2mu[x] = AST_LIN2MU(AST_ALAW(x)); } + res = ast_register_translator(&alawtoulaw); - if (!res) - res = ast_register_translator(&ulawtoalaw); - else - ast_unregister_translator(&alawtoulaw); - if (res) + res |= ast_register_translator(&ulawtoalaw); + + if (res) { + unload_module(); return AST_MODULE_LOAD_FAILURE; + } + return AST_MODULE_LOAD_SUCCESS; } diff --git a/codecs/codec_adpcm.c b/codecs/codec_adpcm.c index c48eb1ab2..03d2a4ab3 100644 --- a/codecs/codec_adpcm.c +++ b/codecs/codec_adpcm.c @@ -290,6 +290,17 @@ static struct ast_frame *lintoadpcm_frameout(struct ast_trans_pvt *pvt) static struct ast_translator adpcmtolin = { .name = "adpcmtolin", + .src_codec = { + .name = "adpcm", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .dst_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .format = "slin", .framein = adpcmtolin_framein, .sample = adpcm_sample, .desc_size = sizeof(struct adpcm_decoder_pvt), @@ -299,6 +310,17 @@ static struct ast_translator adpcmtolin = { static struct ast_translator lintoadpcm = { .name = "lintoadpcm", + .src_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .dst_codec = { + .name = "adpcm", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .format = "adpcm", .framein = lintoadpcm_framein, .frameout = lintoadpcm_frameout, .sample = slin8_sample, @@ -307,12 +329,6 @@ static struct ast_translator lintoadpcm = { .buf_size = BUFFER_SAMPLES/ 2, /* 2 samples per byte */ }; -/*! \brief standard module glue */ -static int reload(void) -{ - return AST_MODULE_LOAD_SUCCESS; -} - static int unload_module(void) { int res; @@ -325,26 +341,20 @@ static int unload_module(void) static int load_module(void) { - int res; - - ast_format_set(&adpcmtolin.src_format, AST_FORMAT_ADPCM, 0); - ast_format_set(&adpcmtolin.dst_format, AST_FORMAT_SLINEAR, 0); - - ast_format_set(&lintoadpcm.src_format, AST_FORMAT_SLINEAR, 0); - ast_format_set(&lintoadpcm.dst_format, AST_FORMAT_ADPCM, 0); + int res = 0; res = ast_register_translator(&adpcmtolin); - if (!res) - res = ast_register_translator(&lintoadpcm); - else - ast_unregister_translator(&adpcmtolin); - if (res) + res |= ast_register_translator(&lintoadpcm); + + if (res) { + unload_module(); return AST_MODULE_LOAD_FAILURE; + } + return AST_MODULE_LOAD_SUCCESS; } AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Adaptive Differential PCM Coder/Decoder", .load = load_module, .unload = unload_module, - .reload = reload, ); diff --git a/codecs/codec_alaw.c b/codecs/codec_alaw.c index 34a71388e..2ca577d7f 100644 --- a/codecs/codec_alaw.c +++ b/codecs/codec_alaw.c @@ -77,6 +77,17 @@ static int lintoalaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) static struct ast_translator alawtolin = { .name = "alawtolin", + .src_codec = { + .name = "alaw", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .dst_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .format = "slin", .framein = alawtolin_framein, .sample = alaw_sample, .buffer_samples = BUFFER_SAMPLES, @@ -84,20 +95,24 @@ static struct ast_translator alawtolin = { }; static struct ast_translator lintoalaw = { - "lintoalaw", + .name = "lintoalaw", + .src_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .dst_codec = { + .name = "alaw", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .format = "alaw", .framein = lintoalaw_framein, .sample = slin8_sample, .buffer_samples = BUFFER_SAMPLES, .buf_size = BUFFER_SAMPLES, }; -/*! \brief standard module stuff */ - -static int reload(void) -{ - return AST_MODULE_LOAD_SUCCESS; -} - static int unload_module(void) { int res; @@ -112,24 +127,18 @@ static int load_module(void) { int res; - ast_format_set(&lintoalaw.src_format, AST_FORMAT_SLINEAR, 0); - ast_format_set(&lintoalaw.dst_format, AST_FORMAT_ALAW, 0); - - ast_format_set(&alawtolin.src_format, AST_FORMAT_ALAW, 0); - ast_format_set(&alawtolin.dst_format, AST_FORMAT_SLINEAR, 0); - res = ast_register_translator(&alawtolin); - if (!res) - res = ast_register_translator(&lintoalaw); - else - ast_unregister_translator(&alawtolin); - if (res) + res |= ast_register_translator(&lintoalaw); + + if (res) { + unload_module(); return AST_MODULE_LOAD_FAILURE; + } + return AST_MODULE_LOAD_SUCCESS; } AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "A-law Coder/Decoder", .load = load_module, .unload = unload_module, - .reload = reload, ); diff --git a/codecs/codec_dahdi.c b/codecs/codec_dahdi.c index caaf99cdf..64f220eef 100644 --- a/codecs/codec_dahdi.c +++ b/codecs/codec_dahdi.c @@ -51,6 +51,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/utils.h" #include "asterisk/linkedlists.h" #include "asterisk/ulaw.h" +#include "asterisk/format_compatibility.h" #define BUFFER_SIZE 8000 @@ -58,17 +59,29 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #define G729_SAMPLES 160 #define ULAW_SAMPLES 160 +/* Defines from DAHDI. */ #ifndef DAHDI_FORMAT_MAX_AUDIO +/*! G.723.1 compression */ #define DAHDI_FORMAT_G723_1 (1 << 0) +/*! GSM compression */ #define DAHDI_FORMAT_GSM (1 << 1) +/*! Raw mu-law data (G.711) */ #define DAHDI_FORMAT_ULAW (1 << 2) +/*! Raw A-law data (G.711) */ #define DAHDI_FORMAT_ALAW (1 << 3) +/*! ADPCM (G.726, 32kbps) */ #define DAHDI_FORMAT_G726 (1 << 4) +/*! ADPCM (IMA) */ #define DAHDI_FORMAT_ADPCM (1 << 5) +/*! Raw 16-bit Signed Linear (8000 Hz) PCM */ #define DAHDI_FORMAT_SLINEAR (1 << 6) +/*! LPC10, 180 samples/frame */ #define DAHDI_FORMAT_LPC10 (1 << 7) +/*! G.729A audio */ #define DAHDI_FORMAT_G729A (1 << 8) +/*! SpeeX Free Compression */ #define DAHDI_FORMAT_SPEEX (1 << 9) +/*! iLBC Free Compression */ #define DAHDI_FORMAT_ILBC (1 << 10) #endif @@ -78,6 +91,233 @@ static struct channel_usage { int decoders; } channels; +#if defined(NOT_NEEDED) +/*! + * \internal + * \brief Convert DAHDI format bitfield to old Asterisk format bitfield. + * \since 13.0.0 + * + * \param dahdi Bitfield from DAHDI to convert. + * + * \note They should be the same values but they don't have to be. + * + * \return Old Asterisk bitfield equivalent. + */ +static uint64_t bitfield_dahdi2ast(unsigned dahdi) +{ + uint64_t ast; + + switch (dahdi) { + case DAHDI_FORMAT_G723_1: + ast = AST_FORMAT_G723; + break; + case DAHDI_FORMAT_GSM: + ast = AST_FORMAT_GSM; + break; + case DAHDI_FORMAT_ULAW: + ast = AST_FORMAT_ULAW; + break; + case DAHDI_FORMAT_ALAW: + ast = AST_FORMAT_ALAW; + break; + case DAHDI_FORMAT_G726: + ast = AST_FORMAT_G726_AAL2; + break; + case DAHDI_FORMAT_ADPCM: + ast = AST_FORMAT_ADPCM; + break; + case DAHDI_FORMAT_SLINEAR: + ast = AST_FORMAT_SLIN; + break; + case DAHDI_FORMAT_LPC10: + ast = AST_FORMAT_LPC10; + break; + case DAHDI_FORMAT_G729A: + ast = AST_FORMAT_G729; + break; + case DAHDI_FORMAT_SPEEX: + ast = AST_FORMAT_SPEEX; + break; + case DAHDI_FORMAT_ILBC: + ast = AST_FORMAT_ILBC; + break; + default: + ast = 0; + break; + } + + return ast; +} +#endif /* defined(NOT_NEEDED) */ + +/*! + * \internal + * \brief Convert old Asterisk format bitfield to DAHDI format bitfield. + * \since 13.0.0 + * + * \param ast Old Asterisk bitfield to convert. + * + * \note They should be the same values but they don't have to be. + * + * \return DAHDI bitfield equivalent. + */ +static unsigned bitfield_ast2dahdi(uint64_t ast) +{ + unsigned dahdi; + + switch (ast) { + case AST_FORMAT_G723: + dahdi = DAHDI_FORMAT_G723_1; + break; + case AST_FORMAT_GSM: + dahdi = DAHDI_FORMAT_GSM; + break; + case AST_FORMAT_ULAW: + dahdi = DAHDI_FORMAT_ULAW; + break; + case AST_FORMAT_ALAW: + dahdi = DAHDI_FORMAT_ALAW; + break; + case AST_FORMAT_G726_AAL2: + dahdi = DAHDI_FORMAT_G726; + break; + case AST_FORMAT_ADPCM: + dahdi = DAHDI_FORMAT_ADPCM; + break; + case AST_FORMAT_SLIN: + dahdi = DAHDI_FORMAT_SLINEAR; + break; + case AST_FORMAT_LPC10: + dahdi = DAHDI_FORMAT_LPC10; + break; + case AST_FORMAT_G729: + dahdi = DAHDI_FORMAT_G729A; + break; + case AST_FORMAT_SPEEX: + dahdi = DAHDI_FORMAT_SPEEX; + break; + case AST_FORMAT_ILBC: + dahdi = DAHDI_FORMAT_ILBC; + break; + default: + dahdi = 0; + break; + } + + return dahdi; +} + +/*! + * \internal + * \brief Get the DAHDI codec by index. + * \since 13.0.0 + * + * \param idx Codex index (0-31). + * + * \return Specified codec if exists otherwise NULL. + */ +static const struct ast_codec *get_dahdi_codec(unsigned idx) +{ + const struct ast_codec *codec; + + static const struct ast_codec dahdi_g723_1 = { + .name = "g723", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }; + static const struct ast_codec dahdi_gsm = { + .name = "gsm", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }; + static const struct ast_codec dahdi_ulaw = { + .name = "ulaw", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }; + static const struct ast_codec dahdi_alaw = { + .name = "alaw", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }; + static const struct ast_codec dahdi_g726 = { + .name = "g726", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }; + static const struct ast_codec dahdi_adpcm = { + .name = "adpcm", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }; + static const struct ast_codec dahdi_slinear = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }; + static const struct ast_codec dahdi_lpc10 = { + .name = "lpc10", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }; + static const struct ast_codec dahdi_g729a = { + .name = "g729", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }; + static const struct ast_codec dahdi_speex = { + .name = "speex", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }; + static const struct ast_codec dahdi_ilbc = { + .name = "ilbc", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }; + + switch (1UL << idx) { + case DAHDI_FORMAT_G723_1: + codec = &dahdi_g723_1; + break; + case DAHDI_FORMAT_GSM: + codec = &dahdi_gsm; + break; + case DAHDI_FORMAT_ULAW: + codec = &dahdi_ulaw; + break; + case DAHDI_FORMAT_ALAW: + codec = &dahdi_alaw; + break; + case DAHDI_FORMAT_G726: + codec = &dahdi_g726; + break; + case DAHDI_FORMAT_ADPCM: + codec = &dahdi_adpcm; + break; + case DAHDI_FORMAT_SLINEAR: + codec = &dahdi_slinear; + break; + case DAHDI_FORMAT_LPC10: + codec = &dahdi_lpc10; + break; + case DAHDI_FORMAT_G729A: + codec = &dahdi_g729a; + break; + case DAHDI_FORMAT_SPEEX: + codec = &dahdi_speex; + break; + case DAHDI_FORMAT_ILBC: + codec = &dahdi_ilbc; + break; + default: + codec = NULL; + break; + } + + return codec; +} + static char *handle_cli_transcoder_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a); static struct ast_cli_entry cli[] = { @@ -190,7 +430,7 @@ static int dahdi_encoder_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) { struct codec_dahdi_pvt *dahdip = pvt->pvt; - if (!f->subclass.format.id) { + if (!f->subclass.format) { /* We're just faking a return for calculation purposes. */ dahdip->fake = 2; pvt->samples = f->samples; @@ -245,18 +485,16 @@ static struct ast_frame *dahdi_encoder_frameout(struct ast_trans_pvt *pvt) int res; if (2 == dahdip->fake) { + struct ast_frame frm = { + .frametype = AST_FRAME_VOICE, + .samples = dahdip->required_samples, + .src = pvt->t->name, + }; + dahdip->fake = 1; - pvt->f.frametype = AST_FRAME_VOICE; - ast_format_clear(&pvt->f.subclass.format); - pvt->f.samples = dahdip->required_samples; - pvt->f.data.ptr = NULL; - pvt->f.offset = 0; - pvt->f.datalen = 0; - pvt->f.mallocd = 0; pvt->samples = 0; - return ast_frisolate(&pvt->f); - + return ast_frisolate(&frm); } else if (1 == dahdip->fake) { dahdip->fake = 0; return NULL; @@ -277,13 +515,7 @@ static struct ast_frame *dahdi_encoder_frameout(struct ast_trans_pvt *pvt) } } else { pvt->f.datalen = res; - pvt->f.frametype = AST_FRAME_VOICE; - ast_format_copy(&pvt->f.subclass.format, &pvt->t->dst_format); - pvt->f.mallocd = 0; - pvt->f.offset = AST_FRIENDLY_OFFSET; - pvt->f.src = pvt->t->name; - pvt->f.data.ptr = pvt->outbuf.c; - pvt->f.samples = ast_codec_get_samples(&pvt->f); + pvt->f.samples = ast_codec_samples_count(&pvt->f); dahdip->samples_written_to_hardware = (dahdip->samples_written_to_hardware >= pvt->f.samples) ? @@ -302,7 +534,7 @@ static int dahdi_decoder_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) { struct codec_dahdi_pvt *dahdip = pvt->pvt; - if (!f->subclass.format.id) { + if (!f->subclass.format) { /* We're just faking a return for calculation purposes. */ dahdip->fake = 2; pvt->samples = f->samples; @@ -327,16 +559,16 @@ static struct ast_frame *dahdi_decoder_frameout(struct ast_trans_pvt *pvt) struct codec_dahdi_pvt *dahdip = pvt->pvt; if (2 == dahdip->fake) { + struct ast_frame frm = { + .frametype = AST_FRAME_VOICE, + .samples = dahdip->required_samples, + .src = pvt->t->name, + }; + dahdip->fake = 1; - pvt->f.frametype = AST_FRAME_VOICE; - ast_format_clear(&pvt->f.subclass.format); - pvt->f.samples = dahdip->required_samples; - pvt->f.data.ptr = NULL; - pvt->f.offset = 0; - pvt->f.datalen = 0; - pvt->f.mallocd = 0; pvt->samples = 0; - return ast_frisolate(&pvt->f); + + return ast_frisolate(&frm); } else if (1 == dahdip->fake) { pvt->samples = 0; dahdip->fake = 0; @@ -370,12 +602,6 @@ static struct ast_frame *dahdi_decoder_frameout(struct ast_trans_pvt *pvt) pvt->f.datalen = res; } pvt->datalen = 0; - pvt->f.frametype = AST_FRAME_VOICE; - ast_format_copy(&pvt->f.subclass.format, &pvt->t->dst_format); - pvt->f.mallocd = 0; - pvt->f.offset = AST_FRIENDLY_OFFSET; - pvt->f.src = pvt->t->name; - pvt->f.data.ptr = pvt->outbuf.c; pvt->f.samples = res; pvt->samples = 0; dahdip->samples_written_to_hardware = @@ -394,9 +620,9 @@ static void dahdi_destroy(struct ast_trans_pvt *pvt) { struct codec_dahdi_pvt *dahdip = pvt->pvt; - switch (ast_format_id_from_old_bitfield(dahdip->fmts.dstfmt)) { - case AST_FORMAT_G729A: - case AST_FORMAT_G723_1: + switch (dahdip->fmts.dstfmt) { + case DAHDI_FORMAT_G729A: + case DAHDI_FORMAT_G723_1: ast_atomic_fetchadd_int(&channels.encoders, -1); break; default: @@ -407,7 +633,39 @@ static void dahdi_destroy(struct ast_trans_pvt *pvt) close(dahdip->fd); } -static int dahdi_translate(struct ast_trans_pvt *pvt, struct ast_format *dst_format, struct ast_format *src_format) +static struct ast_format *dahdi_format_to_cached(int format) +{ + switch (format) { + case DAHDI_FORMAT_G723_1: + return ast_format_g723; + case DAHDI_FORMAT_GSM: + return ast_format_gsm; + case DAHDI_FORMAT_ULAW: + return ast_format_ulaw; + case DAHDI_FORMAT_ALAW: + return ast_format_alaw; + case DAHDI_FORMAT_G726: + return ast_format_g726; + case DAHDI_FORMAT_ADPCM: + return ast_format_adpcm; + case DAHDI_FORMAT_SLINEAR: + return ast_format_slin; + case DAHDI_FORMAT_LPC10: + return ast_format_lpc10; + case DAHDI_FORMAT_G729A: + return ast_format_g729; + case DAHDI_FORMAT_SPEEX: + return ast_format_speex; + case DAHDI_FORMAT_ILBC: + return ast_format_ilbc; + } + + /* This will never be reached */ + ast_assert(0); + return NULL; +} + +static int dahdi_translate(struct ast_trans_pvt *pvt, struct ast_codec *dst_codec, struct ast_codec *src_codec) { /* Request translation through zap if possible */ int fd; @@ -421,10 +679,13 @@ static int dahdi_translate(struct ast_trans_pvt *pvt, struct ast_format *dst_for return -1; } - dahdip->fmts.srcfmt = ast_format_to_old_bitfield(src_format); - dahdip->fmts.dstfmt = ast_format_to_old_bitfield(dst_format); + dahdip->fmts.srcfmt = bitfield_ast2dahdi(ast_format_compatibility_codec2bitfield(src_codec)); + dahdip->fmts.dstfmt = bitfield_ast2dahdi(ast_format_compatibility_codec2bitfield(dst_codec)); + + ast_assert(pvt->f.subclass.format == NULL); + pvt->f.subclass.format = ao2_bump(dahdi_format_to_cached(dahdip->fmts.dstfmt)); - ast_debug(1, "Opening transcoder channel from %s to %s.\n", ast_getformatname(src_format), ast_getformatname(dst_format)); + ast_debug(1, "Opening transcoder channel from %s to %s.\n", src_codec->name, dst_codec->name); retry: if (ioctl(fd, DAHDI_TC_ALLOCATE, &dahdip->fmts)) { @@ -437,14 +698,14 @@ retry: * support for ULAW instead of signed linear and then * we'll just convert from ulaw to signed linear in * software. */ - if (AST_FORMAT_SLINEAR == ast_format_id_from_old_bitfield(dahdip->fmts.srcfmt)) { + if (dahdip->fmts.srcfmt == DAHDI_FORMAT_SLINEAR) { ast_debug(1, "Using soft_slin support on source\n"); dahdip->softslin = 1; - dahdip->fmts.srcfmt = ast_format_id_to_old_bitfield(AST_FORMAT_ULAW); - } else if (AST_FORMAT_SLINEAR == ast_format_id_from_old_bitfield(dahdip->fmts.dstfmt)) { + dahdip->fmts.srcfmt = DAHDI_FORMAT_ULAW; + } else if (dahdip->fmts.dstfmt == DAHDI_FORMAT_SLINEAR) { ast_debug(1, "Using soft_slin support on destination\n"); dahdip->softslin = 1; - dahdip->fmts.dstfmt = ast_format_id_to_old_bitfield(AST_FORMAT_ULAW); + dahdip->fmts.dstfmt = DAHDI_FORMAT_ULAW; } tried_once = 1; goto retry; @@ -463,13 +724,13 @@ retry: dahdip->fd = fd; - dahdip->required_samples = ((dahdip->fmts.dstfmt|dahdip->fmts.srcfmt) & (ast_format_id_to_old_bitfield(AST_FORMAT_G723_1))) ? G723_SAMPLES : G729_SAMPLES; + dahdip->required_samples = ((dahdip->fmts.dstfmt|dahdip->fmts.srcfmt) & (DAHDI_FORMAT_G723_1)) ? G723_SAMPLES : G729_SAMPLES; - switch (ast_format_id_from_old_bitfield(dahdip->fmts.dstfmt)) { - case AST_FORMAT_G729A: + switch (dahdip->fmts.dstfmt) { + case DAHDI_FORMAT_G729A: ast_atomic_fetchadd_int(&channels.encoders, +1); break; - case AST_FORMAT_G723_1: + case DAHDI_FORMAT_G723_1: ast_atomic_fetchadd_int(&channels.encoders, +1); break; default: @@ -483,8 +744,8 @@ retry: static int dahdi_new(struct ast_trans_pvt *pvt) { return dahdi_translate(pvt, - &pvt->t->dst_format, - &pvt->t->src_format); + pvt->t->core_dst_codec, + pvt->t->core_src_codec); } static struct ast_frame *fakesrc_sample(void) @@ -501,33 +762,37 @@ static struct ast_frame *fakesrc_sample(void) static int is_encoder(struct translator *zt) { - if ((zt->t.src_format.id == AST_FORMAT_ULAW) || - (zt->t.src_format.id == AST_FORMAT_ALAW) || - (zt->t.src_format.id == AST_FORMAT_SLINEAR)) { + if ((zt->t.core_src_codec->id == ast_format_get_codec_id(ast_format_ulaw)) || + (zt->t.core_src_codec->id == ast_format_get_codec_id(ast_format_alaw)) || + (zt->t.core_src_codec->id == ast_format_get_codec_id(ast_format_slin))) { return 1; } else { return 0; } } -static int register_translator(int dst, int src) +static int register_translator(unsigned dst, unsigned src) { + const struct ast_codec *dst_codec; + const struct ast_codec *src_codec; struct translator *zt; int res; - struct ast_format dst_format; - struct ast_format src_format; - ast_format_from_old_bitfield(&dst_format, (1 << dst)); - ast_format_from_old_bitfield(&src_format, (1 << src)); + dst_codec = get_dahdi_codec(dst); + src_codec = get_dahdi_codec(src); + if (!dst_codec || !src_codec) { + return -1; + } if (!(zt = ast_calloc(1, sizeof(*zt)))) { return -1; } - snprintf((char *) (zt->t.name), sizeof(zt->t.name), "zap%sto%s", - ast_getformatname(&src_format), ast_getformatname(&dst_format)); - ast_format_copy(&zt->t.src_format, &src_format); - ast_format_copy(&zt->t.dst_format, &dst_format); + snprintf(zt->t.name, sizeof(zt->t.name), "dahdi_%s_to_%s", + src_codec->name, dst_codec->name); + + memcpy(&zt->t.src_codec, src_codec, sizeof(*src_codec)); + memcpy(&zt->t.dst_codec, dst_codec, sizeof(*dst_codec)); zt->t.buf_size = BUFFER_SIZE; if (is_encoder(zt)) { zt->t.framein = dahdi_encoder_framein; @@ -557,17 +822,20 @@ static int register_translator(int dst, int src) return res; } -static void drop_translator(int dst, int src) +static void drop_translator(unsigned dst, unsigned src) { struct translator *cur; AST_LIST_LOCK(&translators); AST_LIST_TRAVERSE_SAFE_BEGIN(&translators, cur, entry) { - if (cur->t.src_format.id != ast_format_id_from_old_bitfield((1 << src))) + if (bitfield_ast2dahdi(ast_format_compatibility_codec2bitfield(cur->t.core_src_codec)) + != (1U << src)) { continue; - - if (cur->t.dst_format.id != ast_format_id_from_old_bitfield((1 << dst))) + } + if (bitfield_ast2dahdi(ast_format_compatibility_codec2bitfield(cur->t.core_dst_codec)) + != (1U << dst)) { continue; + } AST_LIST_REMOVE_CURRENT(entry); ast_unregister_translator(&cur->t); @@ -678,7 +946,6 @@ static int unload_module(void) static int load_module(void) { - ast_ulaw_init(); find_transcoders(); ast_cli_register_multiple(cli, ARRAY_LEN(cli)); return AST_MODULE_LOAD_SUCCESS; diff --git a/codecs/codec_g722.c b/codecs/codec_g722.c index 89641f175..1eba8067f 100644 --- a/codecs/codec_g722.c +++ b/codecs/codec_g722.c @@ -138,6 +138,17 @@ static int lintog722_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) static struct ast_translator g722tolin = { .name = "g722tolin", + .src_codec = { + .name = "g722", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 16000, + }, + .dst_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .format = "slin", .newpvt = g722tolin_new, /* same for both directions */ .framein = g722tolin_framein, .sample = g722_sample, @@ -148,6 +159,17 @@ static struct ast_translator g722tolin = { static struct ast_translator lintog722 = { .name = "lintog722", + .src_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .dst_codec = { + .name = "g722", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 16000, + }, + .format = "g722", .newpvt = lintog722_new, /* same for both directions */ .framein = lintog722_framein, .sample = slin8_sample, @@ -158,6 +180,17 @@ static struct ast_translator lintog722 = { static struct ast_translator g722tolin16 = { .name = "g722tolin16", + .src_codec = { + .name = "g722", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 16000, + }, + .dst_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 16000, + }, + .format = "slin16", .newpvt = g722tolin16_new, /* same for both directions */ .framein = g722tolin_framein, .sample = g722_sample, @@ -168,6 +201,17 @@ static struct ast_translator g722tolin16 = { static struct ast_translator lin16tog722 = { .name = "lin16tog722", + .src_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 16000, + }, + .dst_codec = { + .name = "g722", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 16000, + }, + .format = "g722", .newpvt = lin16tog722_new, /* same for both directions */ .framein = lintog722_framein, .sample = slin16_sample, @@ -176,11 +220,6 @@ static struct ast_translator lin16tog722 = { .buf_size = BUFFER_SAMPLES, }; -static int reload(void) -{ - return AST_MODULE_LOAD_SUCCESS; -} - static int unload_module(void) { int res = 0; @@ -197,18 +236,6 @@ static int load_module(void) { int res = 0; - ast_format_set(&g722tolin.src_format, AST_FORMAT_G722, 0); - ast_format_set(&g722tolin.dst_format, AST_FORMAT_SLINEAR, 0); - - ast_format_set(&lintog722.src_format, AST_FORMAT_SLINEAR, 0); - ast_format_set(&lintog722.dst_format, AST_FORMAT_G722, 0); - - ast_format_set(&g722tolin16.src_format, AST_FORMAT_G722, 0); - ast_format_set(&g722tolin16.dst_format, AST_FORMAT_SLINEAR16, 0); - - ast_format_set(&lin16tog722.src_format, AST_FORMAT_SLINEAR16, 0); - ast_format_set(&lin16tog722.dst_format, AST_FORMAT_G722, 0); - res |= ast_register_translator(&g722tolin); res |= ast_register_translator(&lintog722); res |= ast_register_translator(&g722tolin16); @@ -225,5 +252,4 @@ static int load_module(void) AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "ITU G.722-64kbps G722 Transcoder", .load = load_module, .unload = unload_module, - .reload = reload, ); diff --git a/codecs/codec_g726.c b/codecs/codec_g726.c index 72e77f955..a41039d53 100644 --- a/codecs/codec_g726.c +++ b/codecs/codec_g726.c @@ -785,6 +785,17 @@ static int lintog726_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) static struct ast_translator g726tolin = { .name = "g726tolin", + .src_codec = { + .name = "g726", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .dst_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .format = "slin", .newpvt = lintog726_new, /* same for both directions */ .framein = g726tolin_framein, .sample = g726_sample, @@ -795,6 +806,17 @@ static struct ast_translator g726tolin = { static struct ast_translator lintog726 = { .name = "lintog726", + .src_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .dst_codec = { + .name = "g726", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .format = "g726", .newpvt = lintog726_new, /* same for both directions */ .framein = lintog726_framein, .sample = slin8_sample, @@ -805,6 +827,17 @@ static struct ast_translator lintog726 = { static struct ast_translator g726aal2tolin = { .name = "g726aal2tolin", + .src_codec = { + .name = "g726aal2", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .dst_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .format = "slin", .newpvt = lintog726_new, /* same for both directions */ .framein = g726aal2tolin_framein, .sample = g726_sample, @@ -815,6 +848,17 @@ static struct ast_translator g726aal2tolin = { static struct ast_translator lintog726aal2 = { .name = "lintog726aal2", + .src_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .dst_codec = { + .name = "g726aal2", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .format = "g726aal2", .newpvt = lintog726_new, /* same for both directions */ .framein = lintog726aal2_framein, .sample = slin8_sample, @@ -823,11 +867,6 @@ static struct ast_translator lintog726aal2 = { .buf_size = BUFFER_SAMPLES / 2, }; -static int reload(void) -{ - return AST_MODULE_LOAD_SUCCESS; -} - static int unload_module(void) { int res = 0; @@ -845,18 +884,6 @@ static int load_module(void) { int res = 0; - ast_format_set(&g726tolin.src_format, AST_FORMAT_G726, 0); - ast_format_set(&g726tolin.dst_format, AST_FORMAT_SLINEAR, 0); - - ast_format_set(&lintog726.src_format, AST_FORMAT_SLINEAR, 0); - ast_format_set(&lintog726.dst_format, AST_FORMAT_G726, 0); - - ast_format_set(&g726aal2tolin.src_format, AST_FORMAT_G726_AAL2, 0); - ast_format_set(&g726aal2tolin.dst_format, AST_FORMAT_SLINEAR, 0); - - ast_format_set(&lintog726aal2.src_format, AST_FORMAT_SLINEAR, 0); - ast_format_set(&lintog726aal2.dst_format, AST_FORMAT_G726_AAL2, 0); - res |= ast_register_translator(&g726tolin); res |= ast_register_translator(&lintog726); @@ -874,5 +901,4 @@ static int load_module(void) AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "ITU G.726-32kbps G726 Transcoder", .load = load_module, .unload = unload_module, - .reload = reload, ); diff --git a/codecs/codec_gsm.c b/codecs/codec_gsm.c index f42a5f1bd..49f672adb 100644 --- a/codecs/codec_gsm.c +++ b/codecs/codec_gsm.c @@ -168,7 +168,18 @@ static void gsm_destroy_stuff(struct ast_trans_pvt *pvt) } static struct ast_translator gsmtolin = { - .name = "gsmtolin", + .name = "gsmtolin", + .src_codec = { + .name = "gsm", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .dst_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .format = "slin", .newpvt = gsm_new, .framein = gsmtolin_framein, .destroy = gsm_destroy_stuff, @@ -179,7 +190,18 @@ static struct ast_translator gsmtolin = { }; static struct ast_translator lintogsm = { - .name = "lintogsm", + .name = "lintogsm", + .src_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .dst_codec = { + .name = "gsm", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .format = "gsm", .newpvt = gsm_new, .framein = lintogsm_framein, .frameout = lintogsm_frameout, @@ -189,19 +211,12 @@ static struct ast_translator lintogsm = { .buf_size = (BUFFER_SAMPLES * GSM_FRAME_LEN + GSM_SAMPLES - 1)/GSM_SAMPLES, }; -/*! \brief standard module glue */ -static int reload(void) -{ - return AST_MODULE_LOAD_SUCCESS; -} - static int unload_module(void) { int res; res = ast_unregister_translator(&lintogsm); - if (!res) - res = ast_unregister_translator(&gsmtolin); + res |= ast_unregister_translator(&gsmtolin); return res; } @@ -210,24 +225,18 @@ static int load_module(void) { int res; - ast_format_set(&gsmtolin.src_format, AST_FORMAT_GSM, 0); - ast_format_set(&gsmtolin.dst_format, AST_FORMAT_SLINEAR, 0); - - ast_format_set(&lintogsm.src_format, AST_FORMAT_SLINEAR, 0); - ast_format_set(&lintogsm.dst_format, AST_FORMAT_GSM, 0); - res = ast_register_translator(&gsmtolin); - if (!res) - res=ast_register_translator(&lintogsm); - else - ast_unregister_translator(&gsmtolin); - if (res) + res |= ast_register_translator(&lintogsm); + + if (res) { + unload_module(); return AST_MODULE_LOAD_FAILURE; + } + return AST_MODULE_LOAD_SUCCESS; } AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "GSM Coder/Decoder", .load = load_module, .unload = unload_module, - .reload = reload, ); diff --git a/codecs/codec_ilbc.c b/codecs/codec_ilbc.c index 632169589..af23b906d 100644 --- a/codecs/codec_ilbc.c +++ b/codecs/codec_ilbc.c @@ -178,7 +178,18 @@ static struct ast_frame *lintoilbc_frameout(struct ast_trans_pvt *pvt) } static struct ast_translator ilbctolin = { - .name = "ilbctolin", + .name = "ilbctolin", + .src_codec = { + .name = "ilbc", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .dst_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .format = "slin", .newpvt = ilbctolin_new, .framein = ilbctolin_framein, .sample = ilbc_sample, @@ -188,7 +199,18 @@ static struct ast_translator ilbctolin = { }; static struct ast_translator lintoilbc = { - .name = "lintoilbc", + .name = "lintoilbc", + .src_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .dst_codec = { + .name = "ilbc", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .format = "ilbc", .newpvt = lintoilbc_new, .framein = lintoilbc_framein, .frameout = lintoilbc_frameout, @@ -211,20 +233,14 @@ static int load_module(void) { int res; - ast_format_set(&ilbctolin.src_format, AST_FORMAT_ILBC, 0); - ast_format_set(&ilbctolin.dst_format, AST_FORMAT_SLINEAR, 0); - - ast_format_set(&lintoilbc.src_format, AST_FORMAT_SLINEAR, 0); - ast_format_set(&lintoilbc.dst_format, AST_FORMAT_ILBC, 0); - - res = ast_register_translator(&ilbctolin); - if (!res) - res=ast_register_translator(&lintoilbc); - else - ast_unregister_translator(&ilbctolin); - if (res) + res |= ast_register_translator(&lintoilbc); + + if (res) { + unload_module(); return AST_MODULE_LOAD_FAILURE; + } + return AST_MODULE_LOAD_SUCCESS; } diff --git a/codecs/codec_lpc10.c b/codecs/codec_lpc10.c index 5f2047a3f..0ef8856ff 100644 --- a/codecs/codec_lpc10.c +++ b/codecs/codec_lpc10.c @@ -196,7 +196,18 @@ static void lpc10_destroy(struct ast_trans_pvt *arg) } static struct ast_translator lpc10tolin = { - .name = "lpc10tolin", + .name = "lpc10tolin", + .src_codec = { + .name = "lpc10", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .dst_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .format = "slin", .newpvt = lpc10_dec_new, .framein = lpc10tolin_framein, .destroy = lpc10_destroy, @@ -207,7 +218,18 @@ static struct ast_translator lpc10tolin = { }; static struct ast_translator lintolpc10 = { - .name = "lintolpc10", + .name = "lintolpc10", + .src_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .dst_codec = { + .name = "lpc10", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .format = "lpc10", .newpvt = lpc10_enc_new, .framein = lintolpc10_framein, .frameout = lintolpc10_frameout, @@ -218,12 +240,6 @@ static struct ast_translator lintolpc10 = { .buf_size = LPC10_BYTES_IN_COMPRESSED_FRAME * (1 + BUFFER_SAMPLES / LPC10_SAMPLES_PER_FRAME), }; -static int reload(void) -{ - return AST_MODULE_LOAD_SUCCESS; -} - - static int unload_module(void) { int res; @@ -238,24 +254,18 @@ static int load_module(void) { int res; - ast_format_set(&lpc10tolin.src_format, AST_FORMAT_LPC10, 0); - ast_format_set(&lpc10tolin.dst_format, AST_FORMAT_SLINEAR, 0); - - ast_format_set(&lintolpc10.src_format, AST_FORMAT_SLINEAR, 0); - ast_format_set(&lintolpc10.dst_format, AST_FORMAT_LPC10, 0); - res = ast_register_translator(&lpc10tolin); - if (!res) - res = ast_register_translator(&lintolpc10); - else - ast_unregister_translator(&lpc10tolin); - if (res) + res |= ast_register_translator(&lintolpc10); + + if (res) { + unload_module(); return AST_MODULE_LOAD_FAILURE; + } + return AST_MODULE_LOAD_SUCCESS; } AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "LPC10 2.4kbps Coder/Decoder", .load = load_module, .unload = unload_module, - .reload = reload, ); diff --git a/codecs/codec_resample.c b/codecs/codec_resample.c index 29d95a798..26b1f0e08 100644 --- a/codecs/codec_resample.c +++ b/codecs/codec_resample.c @@ -42,32 +42,72 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") static struct ast_translator *translators; static int trans_size; -static int id_list[] = { - AST_FORMAT_SLINEAR, - AST_FORMAT_SLINEAR12, - AST_FORMAT_SLINEAR16, - AST_FORMAT_SLINEAR24, - AST_FORMAT_SLINEAR32, - AST_FORMAT_SLINEAR44, - AST_FORMAT_SLINEAR48, - AST_FORMAT_SLINEAR96, - AST_FORMAT_SLINEAR192, +static struct ast_codec codec_list[] = { + { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 12000, + }, + { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 16000, + }, + { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 24000, + }, + { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 32000, + }, + { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 44100, + }, + { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 48000, + }, + { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 96000, + }, + { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 192000, + }, }; static int resamp_new(struct ast_trans_pvt *pvt) { int err; - if (!(pvt->pvt = speex_resampler_init(1, ast_format_rate(&pvt->t->src_format), ast_format_rate(&pvt->t->dst_format), 5, &err))) { + if (!(pvt->pvt = speex_resampler_init(1, pvt->t->src_codec.sample_rate, pvt->t->dst_codec.sample_rate, 5, &err))) { return -1; } + ast_assert(pvt->f.subclass.format == NULL); + pvt->f.subclass.format = ao2_bump(ast_format_cache_get_slin_by_rate(pvt->t->dst_codec.sample_rate)); + return 0; } static void resamp_destroy(struct ast_trans_pvt *pvt) { SpeexResamplerState *resamp_pvt = pvt->pvt; + speex_resampler_destroy(resamp_pvt); } @@ -113,13 +153,13 @@ static int load_module(void) int res = 0; int x, y, idx = 0; - trans_size = ARRAY_LEN(id_list) * (ARRAY_LEN(id_list) - 1); + trans_size = ARRAY_LEN(codec_list) * (ARRAY_LEN(codec_list) - 1); if (!(translators = ast_calloc(1, sizeof(struct ast_translator) * trans_size))) { return AST_MODULE_LOAD_FAILURE; } - for (x = 0; x < ARRAY_LEN(id_list); x++) { - for (y = 0; y < ARRAY_LEN(id_list); y++) { + for (x = 0; x < ARRAY_LEN(codec_list); x++) { + for (y = 0; y < ARRAY_LEN(codec_list); y++) { if (x == y) { continue; } @@ -129,10 +169,10 @@ static int load_module(void) translators[idx].desc_size = 0; translators[idx].buffer_samples = (OUTBUF_SIZE / sizeof(int16_t)); translators[idx].buf_size = OUTBUF_SIZE; - ast_format_set(&translators[idx].src_format, id_list[x], 0); - ast_format_set(&translators[idx].dst_format, id_list[y], 0); - snprintf(translators[idx].name, sizeof(translators[idx].name), "slin %dkhz -> %dkhz", - ast_format_rate(&translators[idx].src_format), ast_format_rate(&translators[idx].dst_format)); + memcpy(&translators[idx].src_codec, &codec_list[x], sizeof(struct ast_codec)); + memcpy(&translators[idx].dst_codec, &codec_list[y], sizeof(struct ast_codec)); + snprintf(translators[idx].name, sizeof(translators[idx].name), "slin %ukhz -> %ukhz", + translators[idx].src_codec.sample_rate, translators[idx].dst_codec.sample_rate); res |= ast_register_translator(&translators[idx]); idx++; } diff --git a/codecs/codec_speex.c b/codecs/codec_speex.c index 72e948057..8c2c3f395 100644 --- a/codecs/codec_speex.c +++ b/codecs/codec_speex.c @@ -308,10 +308,14 @@ static struct ast_frame *lintospeex_frameout(struct ast_trans_pvt *pvt) } else { tmp->silent_state = 1; speex_bits_reset(&tmp->bits); + +/* BUGBUG need to setup a new static frame to prevent destroying the translators normal static frame. */ + ao2_cleanup(pvt->f.subclass.format); memset(&pvt->f, 0, sizeof(pvt->f)); pvt->f.frametype = AST_FRAME_CNG; pvt->f.samples = samples; /* XXX what now ? format etc... */ +/* BUGBUG should return ast_frisolate(setup local static frame) here */ } } @@ -341,7 +345,18 @@ static void lintospeex_destroy(struct ast_trans_pvt *arg) } static struct ast_translator speextolin = { - .name = "speextolin", + .name = "speextolin", + .src_codec = { + .name = "speex", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .dst_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .format = "slin", .newpvt = speextolin_new, .framein = speextolin_framein, .destroy = speextolin_destroy, @@ -354,6 +369,17 @@ static struct ast_translator speextolin = { static struct ast_translator lintospeex = { .name = "lintospeex", + .src_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .dst_codec = { + .name = "speex", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .format = "speex", .newpvt = lintospeex_new, .framein = lintospeex_framein, .frameout = lintospeex_frameout, @@ -365,7 +391,18 @@ static struct ast_translator lintospeex = { }; static struct ast_translator speexwbtolin16 = { - .name = "speexwbtolin16", + .name = "speexwbtolin16", + .src_codec = { + .name = "speex", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 16000, + }, + .dst_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 16000, + }, + .format = "slin16", .newpvt = speexwbtolin16_new, .framein = speextolin_framein, .destroy = speextolin_destroy, @@ -377,7 +414,18 @@ static struct ast_translator speexwbtolin16 = { }; static struct ast_translator lin16tospeexwb = { - .name = "lin16tospeexwb", + .name = "lin16tospeexwb", + .src_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 16000, + }, + .dst_codec = { + .name = "speex", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 16000, + }, + .format = "speex16", .newpvt = lin16tospeexwb_new, .framein = lintospeex_framein, .frameout = lintospeex_frameout, @@ -389,7 +437,18 @@ static struct ast_translator lin16tospeexwb = { }; static struct ast_translator speexuwbtolin32 = { - .name = "speexuwbtolin32", + .name = "speexuwbtolin32", + .src_codec = { + .name = "speex", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 32000, + }, + .dst_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 32000, + }, + .format = "slin32", .newpvt = speexuwbtolin32_new, .framein = speextolin_framein, .destroy = speextolin_destroy, @@ -400,7 +459,18 @@ static struct ast_translator speexuwbtolin32 = { }; static struct ast_translator lin32tospeexuwb = { - .name = "lin32tospeexuwb", + .name = "lin32tospeexuwb", + .src_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 32000, + }, + .dst_codec = { + .name = "speex", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 32000, + }, + .format = "speex32", .newpvt = lin32tospeexuwb_new, .framein = lintospeex_framein, .frameout = lintospeex_frameout, @@ -534,25 +604,6 @@ static int load_module(void) if (parse_config(0)) return AST_MODULE_LOAD_DECLINE; - - ast_format_set(&speextolin.src_format, AST_FORMAT_SPEEX, 0); - ast_format_set(&speextolin.dst_format, AST_FORMAT_SLINEAR, 0); - - ast_format_set(&lintospeex.src_format, AST_FORMAT_SLINEAR, 0); - ast_format_set(&lintospeex.dst_format, AST_FORMAT_SPEEX, 0); - - ast_format_set(&speexwbtolin16.src_format, AST_FORMAT_SPEEX16, 0); - ast_format_set(&speexwbtolin16.dst_format, AST_FORMAT_SLINEAR16, 0); - - ast_format_set(&lin16tospeexwb.src_format, AST_FORMAT_SLINEAR16, 0); - ast_format_set(&lin16tospeexwb.dst_format, AST_FORMAT_SPEEX16, 0); - - ast_format_set(&speexuwbtolin32.src_format, AST_FORMAT_SPEEX32, 0); - ast_format_set(&speexuwbtolin32.dst_format, AST_FORMAT_SLINEAR32, 0); - - ast_format_set(&lin32tospeexuwb.src_format, AST_FORMAT_SLINEAR32, 0); - ast_format_set(&lin32tospeexuwb.dst_format, AST_FORMAT_SPEEX32, 0); - res |= ast_register_translator(&speextolin); res |= ast_register_translator(&lintospeex); res |= ast_register_translator(&speexwbtolin16); @@ -560,6 +611,10 @@ static int load_module(void) res |= ast_register_translator(&speexuwbtolin32); res |= ast_register_translator(&lin32tospeexuwb); + if (res) { + unload_module(); + return res; + } return res; } diff --git a/codecs/codec_ulaw.c b/codecs/codec_ulaw.c index 86a0706c4..9d0aa3c14 100644 --- a/codecs/codec_ulaw.c +++ b/codecs/codec_ulaw.c @@ -82,6 +82,17 @@ static int lintoulaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) static struct ast_translator ulawtolin = { .name = "ulawtolin", + .src_codec = { + .name = "ulaw", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .dst_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .format = "slin", .framein = ulawtolin_framein, .sample = ulaw_sample, .buffer_samples = BUFFER_SAMPLES, @@ -90,6 +101,17 @@ static struct ast_translator ulawtolin = { static struct ast_translator testlawtolin = { .name = "testlawtolin", + .src_codec = { + .name = "testlaw", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .dst_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .format = "slin", .framein = ulawtolin_framein, .sample = ulaw_sample, .buffer_samples = BUFFER_SAMPLES, @@ -102,6 +124,17 @@ static struct ast_translator testlawtolin = { static struct ast_translator lintoulaw = { .name = "lintoulaw", + .src_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .dst_codec = { + .name = "ulaw", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .format = "ulaw", .framein = lintoulaw_framein, .sample = slin8_sample, .buf_size = BUFFER_SAMPLES, @@ -110,17 +143,23 @@ static struct ast_translator lintoulaw = { static struct ast_translator lintotestlaw = { .name = "lintotestlaw", + .src_codec = { + .name = "slin", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .dst_codec = { + .name = "testlaw", + .type = AST_MEDIA_TYPE_AUDIO, + .sample_rate = 8000, + }, + .format = "testlaw", .framein = lintoulaw_framein, .sample = slin8_sample, .buf_size = BUFFER_SAMPLES, .buffer_samples = BUFFER_SAMPLES, }; -static int reload(void) -{ - return AST_MODULE_LOAD_SUCCESS; -} - static int unload_module(void) { int res; @@ -137,32 +176,20 @@ static int load_module(void) { int res; - ast_format_set(&lintoulaw.src_format, AST_FORMAT_SLINEAR, 0); - ast_format_set(&lintoulaw.dst_format, AST_FORMAT_ULAW, 0); - - ast_format_set(&lintotestlaw.src_format, AST_FORMAT_SLINEAR, 0); - ast_format_set(&lintotestlaw.dst_format, AST_FORMAT_TESTLAW, 0); - - ast_format_set(&ulawtolin.src_format, AST_FORMAT_ULAW, 0); - ast_format_set(&ulawtolin.dst_format, AST_FORMAT_SLINEAR, 0); - - ast_format_set(&testlawtolin.src_format, AST_FORMAT_TESTLAW, 0); - ast_format_set(&testlawtolin.dst_format, AST_FORMAT_SLINEAR, 0); - res = ast_register_translator(&ulawtolin); - if (!res) { - res = ast_register_translator(&lintoulaw); - res |= ast_register_translator(&lintotestlaw); - res |= ast_register_translator(&testlawtolin); - } else - ast_unregister_translator(&ulawtolin); - if (res) + res |= ast_register_translator(&lintoulaw); + res |= ast_register_translator(&lintotestlaw); + res |= ast_register_translator(&testlawtolin); + + if (res) { + unload_module(); return AST_MODULE_LOAD_FAILURE; + } + return AST_MODULE_LOAD_SUCCESS; } AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "mu-Law Coder/Decoder", .load = load_module, .unload = unload_module, - .reload = reload, ); diff --git a/codecs/ex_adpcm.h b/codecs/ex_adpcm.h index 96b7c51f8..360239789 100644 --- a/codecs/ex_adpcm.h +++ b/codecs/ex_adpcm.h @@ -26,7 +26,8 @@ static struct ast_frame *adpcm_sample(void) .src = __PRETTY_FUNCTION__, .data.ptr = ex_adpcm, }; - ast_format_set(&f.subclass.format, AST_FORMAT_ADPCM, 0); + + f.subclass.format = ast_format_adpcm; return &f; } diff --git a/codecs/ex_alaw.h b/codecs/ex_alaw.h index bbf8ad982..e8629be5e 100644 --- a/codecs/ex_alaw.h +++ b/codecs/ex_alaw.h @@ -31,6 +31,6 @@ static struct ast_frame *alaw_sample(void) .src = __PRETTY_FUNCTION__, .data.ptr = ex_alaw, }; - ast_format_set(&f.subclass.format, AST_FORMAT_ALAW, 0); + f.subclass.format = ast_format_alaw; return &f; } diff --git a/codecs/ex_g722.h b/codecs/ex_g722.h index 0e9f22686..390cc7b5c 100644 --- a/codecs/ex_g722.h +++ b/codecs/ex_g722.h @@ -42,7 +42,7 @@ static struct ast_frame *g722_sample(void) .data.ptr = ex_g722, }; - ast_format_set(&f.subclass.format, AST_FORMAT_G722, 0); + f.subclass.format = ast_format_slin; return &f; } diff --git a/codecs/ex_g726.h b/codecs/ex_g726.h index d5438c91a..f125253ee 100644 --- a/codecs/ex_g726.h +++ b/codecs/ex_g726.h @@ -27,7 +27,7 @@ static struct ast_frame *g726_sample(void) .data.ptr = ex_g726, }; - ast_format_set(&f.subclass.format, AST_FORMAT_G726, 0); + f.subclass.format = ast_format_g726; return &f; } diff --git a/codecs/ex_gsm.h b/codecs/ex_gsm.h index 8f8b4f9fe..006706038 100644 --- a/codecs/ex_gsm.h +++ b/codecs/ex_gsm.h @@ -27,6 +27,7 @@ static struct ast_frame *gsm_sample(void) .data.ptr = ex_gsm, }; - ast_format_set(&f.subclass.format, AST_FORMAT_GSM, 0); + f.subclass.format = ast_format_gsm; + return &f; } diff --git a/codecs/ex_ilbc.h b/codecs/ex_ilbc.h index 93cf5eacf..3a79b0918 100644 --- a/codecs/ex_ilbc.h +++ b/codecs/ex_ilbc.h @@ -28,6 +28,7 @@ static struct ast_frame *ilbc_sample(void) .data.ptr = ex_ilbc, }; - ast_format_set(&f.subclass.format, AST_FORMAT_ILBC, 0); + f.subclass.format = ast_format_ilbc; + return &f; } diff --git a/codecs/ex_lpc10.h b/codecs/ex_lpc10.h index a36e06add..2e271c005 100644 --- a/codecs/ex_lpc10.h +++ b/codecs/ex_lpc10.h @@ -25,7 +25,7 @@ static struct ast_frame *lpc10_sample(void) .data.ptr = ex_lpc10, }; - ast_format_set(&f.subclass.format, AST_FORMAT_LPC10, 0); + f.subclass.format = ast_format_lpc10; return &f; } diff --git a/codecs/ex_speex.h b/codecs/ex_speex.h index e9411e5d7..76e5925b8 100644 --- a/codecs/ex_speex.h +++ b/codecs/ex_speex.h @@ -27,7 +27,7 @@ static struct ast_frame *speex_sample(void) .data.ptr = ex_speex, }; - ast_format_set(&f.subclass.format, AST_FORMAT_SPEEX, 0); + f.subclass.format = ast_format_speex; return &f; } @@ -58,7 +58,8 @@ static struct ast_frame *speex16_sample(void) .src = __PRETTY_FUNCTION__, .data.ptr = ex_speex16, }; - ast_format_set(&f.subclass.format, AST_FORMAT_SPEEX16, 0); + + f.subclass.format = ast_format_speex16; return &f; } diff --git a/codecs/ex_ulaw.h b/codecs/ex_ulaw.h index 2ab9222fb..d18a08e9c 100644 --- a/codecs/ex_ulaw.h +++ b/codecs/ex_ulaw.h @@ -32,6 +32,7 @@ static struct ast_frame *ulaw_sample(void) .data.ptr = ex_ulaw, }; - ast_format_set(&f.subclass.format, AST_FORMAT_ULAW, 0); + f.subclass.format = ast_format_ulaw; + return &f; } |