From 4b2fc9d3e738dbb2e7dd297de2f35e571e350691 Mon Sep 17 00:00:00 2001 From: tilghman Date: Tue, 6 Nov 2007 22:51:48 +0000 Subject: Commit some cleanups to the format type code. - Remove the AST_FORMAT_MAX_* types, as these are consuming 3 out of our available 32 bits. - Add a native slin16 type, so that 16kHz codecs can translate without losing resolution. (This doesn't affect anything immediately, until another codec has wb support.) git-svn-id: http://svn.digium.com/svn/asterisk/trunk@89071 f38db490-d61c-443f-a65b-d21fe96a405b --- codecs/codec_g722.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) (limited to 'codecs') diff --git a/codecs/codec_g722.c b/codecs/codec_g722.c index 00e36fb33..54802dc8b 100644 --- a/codecs/codec_g722.c +++ b/codecs/codec_g722.c @@ -74,6 +74,15 @@ static int lintog722_new(struct ast_trans_pvt *pvt) return 0; } +static int lin16tog722_new(struct ast_trans_pvt *pvt) +{ + struct g722_encoder_pvt *tmp = pvt->pvt; + + g722_encode_init(&tmp->g722, 64000, 0); + + return 0; +} + /*! \brief init a new instance of g722_encoder_pvt. */ static int g722tolin_new(struct ast_trans_pvt *pvt) { @@ -84,6 +93,15 @@ static int g722tolin_new(struct ast_trans_pvt *pvt) return 0; } +static int g722tolin16_new(struct ast_trans_pvt *pvt) +{ + struct g722_decoder_pvt *tmp = pvt->pvt; + + g722_decode_init(&tmp->g722, 64000, 0); + + return 0; +} + static int g722tolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) { struct g722_decoder_pvt *tmp = pvt->pvt; @@ -125,6 +143,20 @@ static struct ast_frame *g722tolin_sample(void) return &f; } +static struct ast_frame *g722tolin16_sample(void) +{ + static struct ast_frame f = { + .frametype = AST_FRAME_VOICE, + .subclass = AST_FORMAT_G722, + .datalen = sizeof(slin_g722_ex), + .samples = sizeof(slin_g722_ex) / sizeof(slin_g722_ex[0]), + .src = __PRETTY_FUNCTION__, + .data = slin_g722_ex, + }; + + return &f; +} + static struct ast_frame *lintog722_sample (void) { static struct ast_frame f = { @@ -139,6 +171,20 @@ static struct ast_frame *lintog722_sample (void) return &f; } +static struct ast_frame *lin16tog722_sample (void) +{ + static struct ast_frame f = { + .frametype = AST_FRAME_VOICE, + .subclass = AST_FORMAT_SLINEAR16, + .datalen = sizeof(slin_g722_ex), + .samples = sizeof(slin_g722_ex) / sizeof(slin_g722_ex[0]), + .src = __PRETTY_FUNCTION__, + .data = slin_g722_ex, + }; + + return &f; +} + static struct ast_translator g722tolin = { .name = "g722tolin", .srcfmt = AST_FORMAT_G722, @@ -164,6 +210,31 @@ static struct ast_translator lintog722 = { .buf_size = BUFFER_SAMPLES, }; +static struct ast_translator g722tolin16 = { + .name = "g722tolin16", + .srcfmt = AST_FORMAT_G722, + .dstfmt = AST_FORMAT_SLINEAR16, + .newpvt = g722tolin16_new, /* same for both directions */ + .framein = g722tolin_framein, + .sample = g722tolin16_sample, + .desc_size = sizeof(struct g722_decoder_pvt), + .buffer_samples = BUFFER_SAMPLES, + .buf_size = BUFFER_SAMPLES, + .plc_samples = 160, +}; + +static struct ast_translator lin16tog722 = { + .name = "lin16tog722", + .srcfmt = AST_FORMAT_SLINEAR16, + .dstfmt = AST_FORMAT_G722, + .newpvt = lin16tog722_new, /* same for both directions */ + .framein = lintog722_framein, + .sample = lin16tog722_sample, + .desc_size = sizeof(struct g722_encoder_pvt), + .buffer_samples = BUFFER_SAMPLES, + .buf_size = BUFFER_SAMPLES, +}; + static int parse_config(int reload) { struct ast_variable *var; @@ -198,6 +269,8 @@ static int unload_module(void) res |= ast_unregister_translator(&g722tolin); res |= ast_unregister_translator(&lintog722); + res |= ast_unregister_translator(&g722tolin16); + res |= ast_unregister_translator(&lin16tog722); return res; } @@ -206,12 +279,13 @@ static int load_module(void) { int res = 0; - if (parse_config(0)) return AST_MODULE_LOAD_DECLINE; res |= ast_register_translator(&g722tolin); res |= ast_register_translator(&lintog722); + res |= ast_register_translator(&g722tolin16); + res |= ast_register_translator(&lin16tog722); if (res) { unload_module(); -- cgit v1.2.3