diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 6019e1166c..44e3146c1e 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -446,6 +446,7 @@ SWITCH_CODEC_FLAG_SILENCE_STOP = (1 << 3) - End period of silence SWITCH_CODEC_FLAG_SILENCE = (1 << 4) - Silence SWITCH_CODEC_FLAG_FREE_POOL = (1 << 5) - Free codec's pool on destruction SWITCH_CODEC_FLAG_AAL2 = (1 << 6) - USE AAL2 Bitpacking +SWITCH_CODEC_FLAG_PASSTHROUGH = (1 << 7) - Passthrough only */ typedef enum { @@ -455,7 +456,8 @@ typedef enum { SWITCH_CODEC_FLAG_SILENCE_STOP = (1 << 3), SWITCH_CODEC_FLAG_SILENCE = (1 << 4), SWITCH_CODEC_FLAG_FREE_POOL = (1 << 5), - SWITCH_CODEC_FLAG_AAL2 = (1 << 6) + SWITCH_CODEC_FLAG_AAL2 = (1 << 6), + SWITCH_CODEC_FLAG_PASSTHROUGH = (1 << 7) } switch_codec_flag_t; diff --git a/src/mod/codecs/mod_g729/mod_g729.c b/src/mod/codecs/mod_g729/mod_g729.c index 0880df76f7..5ebaa35a0b 100644 --- a/src/mod/codecs/mod_g729/mod_g729.c +++ b/src/mod/codecs/mod_g729/mod_g729.c @@ -31,20 +31,27 @@ * mod_g729.c -- G729 Codec Module * */ -#include "switch.h" -#include "g729.h" static const char modname[] = "mod_g729"; +#include "switch.h" + +#ifndef G729_PASSTHROUGH +#include "g729.h" + struct g729_context { struct dec_state decoder_object; struct cod_state encoder_object; }; +#endif static switch_status_t switch_g729_init(switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings) { - +#ifdef G729_PASSTHROUGH + codec->flags |= SWITCH_CODEC_FLAG_PASSTHROUGH; + return SWITCH_STATUS_SUCCESS; +#else struct g729_context *context = NULL; int encoding, decoding; @@ -68,11 +75,14 @@ static switch_status_t switch_g729_init(switch_codec_t *codec, switch_codec_flag return SWITCH_STATUS_SUCCESS; } +#endif } static switch_status_t switch_g729_destroy(switch_codec_t *codec) { +#ifndef G729_PASSTHROUGH codec->private_info = NULL; +#endif return SWITCH_STATUS_SUCCESS; } @@ -88,6 +98,10 @@ static switch_status_t switch_g729_encode(switch_codec_t *codec, uint32_t *encoded_rate, unsigned int *flag) { +#ifdef G729_PASSTHROUGH + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This codec is only usable in passthrough mode!\n"); + return SWITCH_STATUS_FALSE; +#else struct g729_context *context = codec->private_info; int cbret = 0; @@ -117,6 +131,7 @@ static switch_status_t switch_g729_encode(switch_codec_t *codec, } } return SWITCH_STATUS_SUCCESS; +#endif } static switch_status_t switch_g729_decode(switch_codec_t *codec, @@ -131,6 +146,10 @@ static switch_status_t switch_g729_decode(switch_codec_t *codec, uint32_t *decoded_rate, unsigned int *flag) { +#ifdef G729_PASSTHROUGH + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This codec is only usable in passthrough mode!\n"); + return SWITCH_STATUS_FALSE; +#else struct g729_context *context = codec->private_info; int divisor = 10; int plen = 10; @@ -194,6 +213,7 @@ static switch_status_t switch_g729_decode(switch_codec_t *codec, return SWITCH_STATUS_FALSE; } return SWITCH_STATUS_SUCCESS; +#endif } /* Registration */ diff --git a/src/switch_core.c b/src/switch_core.c index 6eb433fc97..1208ba665b 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -498,6 +498,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_init(switch_codec_t *codec, ch } switch_set_flag(codec, SWITCH_CODEC_FLAG_FREE_POOL); } + implementation->init(codec, flags, codec_settings); return SWITCH_STATUS_SUCCESS; diff --git a/src/switch_ivr.c b/src/switch_ivr.c index d062adbb3a..e0084a6a5e 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -1426,7 +1426,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess int32_t idx = -1; switch_codec_t write_codec = {0}; switch_frame_t write_frame = {0}; - uint8_t err = 0, fdata[1024]; + uint8_t err = 0, fdata[1024], pass = 0; char *file = NULL, *key = NULL, *odata, *var; write_frame.data = fdata; @@ -1630,24 +1630,26 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess read_codec = switch_core_session_get_read_codec(session); assert(read_codec != NULL); - if (switch_core_codec_init(&write_codec, - "L16", - read_codec->implementation->samples_per_second, - read_codec->implementation->microseconds_per_frame / 1000, - 1, - SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, - NULL, - pool) == SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Success L16@%uhz 1 channel %dms\n", - read_codec->implementation->samples_per_second, - read_codec->implementation->microseconds_per_frame / 1000); - write_frame.codec = &write_codec; - write_frame.datalen = read_codec->implementation->bytes_per_frame; - write_frame.samples = write_frame.datalen / 2; - memset(write_frame.data, 255, write_frame.datalen); - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec Error!"); - switch_channel_hangup(caller_channel, SWITCH_CAUSE_NORMAL_TEMPORARY_FAILURE); + if (!(pass = switch_test_flag(read_codec, SWITCH_CODEC_FLAG_PASSTHROUGH))) { + if (switch_core_codec_init(&write_codec, + "L16", + read_codec->implementation->samples_per_second, + read_codec->implementation->microseconds_per_frame / 1000, + 1, + SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, + NULL, + pool) == SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Success L16@%uhz 1 channel %dms\n", + read_codec->implementation->samples_per_second, + read_codec->implementation->microseconds_per_frame / 1000); + write_frame.codec = &write_codec; + write_frame.datalen = read_codec->implementation->bytes_per_frame; + write_frame.samples = write_frame.datalen / 2; + memset(write_frame.data, 255, write_frame.datalen); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec Error!"); + switch_channel_hangup(caller_channel, SWITCH_CAUSE_NORMAL_TEMPORARY_FAILURE); + } } } @@ -1661,7 +1663,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess if (!SWITCH_READ_ACCEPTABLE(status)) { break; } - if (read_frame) { + if (read_frame && !pass) { if (switch_core_session_write_frame(session, &write_frame, 1000, 0) != SWITCH_STATUS_SUCCESS) { break; } @@ -1718,7 +1720,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess if (odata) { free(odata); } - if (write_codec.implementation) { + if (!pass && write_codec.implementation) { switch_core_codec_destroy(&write_codec); } return status;