]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add checking for successful re-sampler allocation. Add ifdefs to disable build with...
authorMichael Jerris <mike@jerris.com>
Wed, 28 Mar 2007 18:21:00 +0000 (18:21 +0000)
committerMichael Jerris <mike@jerris.com>
Wed, 28 Mar 2007 18:21:00 +0000 (18:21 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4782 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/applications/mod_conference/mod_conference.c
src/switch_core.c
src/switch_resample.c

index fb025066ddf5e093b67f8f3eba44bf08309ebbf5..a040e86ab8189f86011490cea5f0a369b78158a4 100644 (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) {
index 2ab13817e8fefae6ce5e748f2c4c31ca49b2a4e7..789221a0b8268ecfdabf99986b68df2179e01af3 100644 (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:
index 20c6729d607505909ba60f648d82c3b482c85e68..bfe4feb78abb4e0ae954dbbe278a9c9f0da79b6b 100644 (file)
  */
 #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
 }