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
This commit is contained in:
Michael Jerris 2007-03-28 18:21:00 +00:00
parent 0958553f39
commit e5dff3e822
3 changed files with 33 additions and 4 deletions

View File

@ -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) {

View File

@ -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:

View File

@ -31,7 +31,12 @@
*/
#include <switch.h>
#include <switch_resample.h>
#ifndef WIN32
#include <switch_private.h>
#endif
#ifndef DISABLE_RESAMPLE
#include <libresample.h>
#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
}