From e5dff3e822cb0b138c51122cfbb8ba3316df9cbf Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 28 Mar 2007 18:21:00 +0000 Subject: [PATCH] add checking for successful re-sampler allocation. Add ifdefs to disable build with re-sampler. git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4782 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- .../applications/mod_conference/mod_conference.c | 7 +++++-- src/switch_core.c | 14 ++++++++++++-- src/switch_resample.c | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c index fb025066dd..a040e86ab8 100644 --- a/src/mod/applications/mod_conference/mod_conference.c +++ b/src/mod/applications/mod_conference/mod_conference.c @@ -4070,12 +4070,15 @@ static void conference_function(switch_core_session_t *session, char *data) switch_audio_resampler_t **resampler = read_codec->implementation->samples_per_second > conference->rate ? &member.read_resampler : &member.mux_resampler; - switch_resample_create(resampler, + if (switch_resample_create(resampler, read_codec->implementation->samples_per_second, read_codec->implementation->samples_per_second * 20, conference->rate, conference->rate * 20, - member.pool); + member.pool) != SWITCH_STATUS_SUCCESS){ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to crete resampler!\n"); + goto done; + } /* Setup an audio buffer for the resampled audio */ if (switch_buffer_create_dynamic(&member.resample_buffer, CONF_DBLOCK_SIZE, CONF_DBUFFER_SIZE, CONF_DBUFFER_MAX) != SWITCH_STATUS_SUCCESS) { diff --git a/src/switch_core.c b/src/switch_core.c index 2ab13817e8..789221a0b8 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -2174,11 +2174,15 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi switch (status) { case SWITCH_STATUS_RESAMPLE: if (!session->read_resampler) { - switch_resample_create(&session->read_resampler, + if (switch_resample_create(&session->read_resampler, read_frame->codec->implementation->samples_per_second, read_frame->codec->implementation->bytes_per_frame * 20, session->read_codec->implementation->samples_per_second, - session->read_codec->implementation->bytes_per_frame * 20, session->pool); + session->read_codec->implementation->bytes_per_frame * 20, session->pool) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to allocate resampler\n"); + status = SWITCH_STATUS_FALSE; + goto done; + } } case SWITCH_STATUS_SUCCESS: session->raw_read_frame.samples = session->raw_read_frame.datalen / sizeof(int16_t); @@ -2448,6 +2452,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess session->write_codec->implementation->samples_per_second, session->write_codec->implementation->bytes_per_frame * 20, session->pool); + if (status != SWITCH_STATUS_SUCCESS) { + goto done; + } } break; case SWITCH_STATUS_SUCCESS: @@ -2652,6 +2659,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess session->write_codec->implementation->samples_per_second, session->write_codec->implementation->bytes_per_frame * 20, session->pool); + if (status != SWITCH_STATUS_SUCCESS) { + goto done; + } } break; case SWITCH_STATUS_SUCCESS: diff --git a/src/switch_resample.c b/src/switch_resample.c index 20c6729d60..bfe4feb78a 100644 --- a/src/switch_resample.c +++ b/src/switch_resample.c @@ -31,7 +31,12 @@ */ #include #include +#ifndef WIN32 +#include +#endif +#ifndef DISABLE_RESAMPLE #include +#endif #define NORMFACT (float)0x8000 #define MAXSAMPLE (float)0x7FFF #define MAXSAMPLEC (char)0x7F @@ -52,6 +57,10 @@ SWITCH_DECLARE(switch_status_t) switch_resample_create(switch_audio_resampler_t switch_size_t from_size, int to_rate, uint32_t to_size, switch_memory_pool_t *pool) { +#ifdef DISABLE_RESAMPLE + *new_resampler = NULL; + return SWITCH_STATUS_NOTIMPL; +#else switch_audio_resampler_t *resampler; double lto_rate, lfrom_rate; @@ -75,12 +84,16 @@ SWITCH_DECLARE(switch_status_t) switch_resample_create(switch_audio_resampler_t *new_resampler = resampler; return SWITCH_STATUS_SUCCESS; +#endif } SWITCH_DECLARE(uint32_t) switch_resample_process(switch_audio_resampler_t *resampler, float *src, int srclen, float *dst, uint32_t dstlen, int last) { +#ifdef DISABLE_RESAMPLE + return 0; +#else int o = 0, srcused = 0, srcpos = 0, out = 0; for (;;) { @@ -99,11 +112,14 @@ SWITCH_DECLARE(uint32_t) switch_resample_process(switch_audio_resampler_t *resam } } return out; +#endif } SWITCH_DECLARE(void) switch_resample_destroy(switch_audio_resampler_t *resampler) { +#ifndef DISABLE_RESAMPLE resample_close(resampler->resampler); +#endif }