From d262ce56ed1a6aa04e4a68a8fda60da1c0daf2b1 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 1 Feb 2008 19:20:22 +0000 Subject: [PATCH] stuff buffers into the bug to reduce stack allocation git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7467 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/private/switch_core_pvt.h | 2 ++ src/switch_core_media_bug.c | 11 +++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/include/private/switch_core_pvt.h b/src/include/private/switch_core_pvt.h index 11c7a8c80a..398ab157f2 100644 --- a/src/include/private/switch_core_pvt.h +++ b/src/include/private/switch_core_pvt.h @@ -152,6 +152,8 @@ struct switch_media_bug { void *user_data; uint32_t flags; uint8_t ready; + uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE]; + int16_t tmp[SWITCH_RECOMMENDED_BUFFER_SIZE]; time_t stop_time; switch_thread_id_t thread_id; struct switch_media_bug *next; diff --git a/src/switch_core_media_bug.c b/src/switch_core_media_bug.c index e81276a31e..19697b2a31 100644 --- a/src/switch_core_media_bug.c +++ b/src/switch_core_media_bug.c @@ -79,7 +79,6 @@ SWITCH_DECLARE(void *) switch_core_media_bug_get_user_data(switch_media_bug_t *b SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *bug, switch_frame_t *frame) { uint32_t bytes = 0; - uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE] = { 0 }; uint32_t datalen = 0; int16_t *dp, *fp; uint32_t x; @@ -102,7 +101,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *b return SWITCH_STATUS_FALSE; } - maxlen = sizeof(data) > frame->buflen ? frame->buflen : sizeof(data); + maxlen = SWITCH_RECOMMENDED_BUFFER_SIZE > frame->buflen ? frame->buflen : SWITCH_RECOMMENDED_BUFFER_SIZE; if ((rdlen = rlen > wlen ? wlen : rlen) > maxlen) { rdlen = maxlen; @@ -123,7 +122,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *b if (wlen) { switch_mutex_lock(bug->write_mutex); - datalen = (uint32_t) switch_buffer_read(bug->raw_write_buffer, data, rdlen); + datalen = (uint32_t) switch_buffer_read(bug->raw_write_buffer, bug->data, rdlen); switch_mutex_unlock(bug->write_mutex); } @@ -132,9 +131,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *b switch_assert( bytes <= maxlen ); if (bytes) { - int16_t tmp[SWITCH_RECOMMENDED_BUFFER_SIZE], *tp = tmp; + int16_t *tp = bug->tmp; - dp = (int16_t *) data; + dp = (int16_t *) bug->data; fp = (int16_t *) frame->data; rlen = frame->datalen / 2; wlen = datalen / 2; @@ -153,7 +152,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *b *(tp++) = 0; } } - memcpy(frame->data, tmp, bytes * 2); + memcpy(frame->data, bug->tmp, bytes * 2); } else { for (x = 0; x < blen; x++) { int32_t z = 0;