From 4d108dde272ab26fc4cc441137ae1dd7c20c8465 Mon Sep 17 00:00:00 2001 From: Nanang Izzuddin Date: Wed, 20 Mar 2013 06:56:19 +0000 Subject: Misc (re #1630): Added compile-time setting to configure audio switchboard buffer size. git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4443 74dad513-b988-da41-8d7b-12977e46ad98 --- pjmedia/include/pjmedia/config.h | 15 +++++++++++++++ pjmedia/src/pjmedia/conf_switch.c | 11 ++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'pjmedia') diff --git a/pjmedia/include/pjmedia/config.h b/pjmedia/include/pjmedia/config.h index 0005fcbc..b3becbc7 100644 --- a/pjmedia/include/pjmedia/config.h +++ b/pjmedia/include/pjmedia/config.h @@ -60,6 +60,21 @@ # define PJMEDIA_CONF_USE_SWITCH_BOARD 0 #endif +/** + * Specify buffer size for audio switch board, in bytes. This buffer will + * be used for transmitting/receiving audio frame data (and some overheads, + * i.e: pjmedia_frame structure) among conference ports in the audio + * switch board. For example, if a port uses PCM format @44100Hz mono + * and frame time 20ms, the PCM audio data will require 1764 bytes, + * so with overhead, a safe buffer size will be ~1900 bytes. + * + * Default: PJMEDIA_MAX_MTU + */ +#ifndef PJMEDIA_CONF_SWITCH_BOARD_BUF_SIZE +# define PJMEDIA_CONF_SWITCH_BOARD_BUF_SIZE PJMEDIA_MAX_MTU +#endif + + /* * Types of sound stream backends. */ diff --git a/pjmedia/src/pjmedia/conf_switch.c b/pjmedia/src/pjmedia/conf_switch.c index 85a884c5..114b48a0 100644 --- a/pjmedia/src/pjmedia/conf_switch.c +++ b/pjmedia/src/pjmedia/conf_switch.c @@ -50,7 +50,7 @@ #define NORMAL_LEVEL 128 #define SLOT_TYPE unsigned #define INVALID_SLOT ((SLOT_TYPE)-1) -#define BUFFER_SIZE PJMEDIA_MAX_MTU +#define BUFFER_SIZE PJMEDIA_CONF_SWITCH_BOARD_BUF_SIZE #define MAX_LEVEL (32767) #define MIN_LEVEL (-32768) @@ -144,6 +144,15 @@ static pj_status_t create_conf_port( pj_pool_t *pool, PJ_ASSERT_RETURN(pool && conf && port && name && p_conf_port, PJ_EINVAL); + /* Check port's buffer size */ + if (port->info.fmt.id == PJMEDIA_FORMAT_PCM && + PJMEDIA_PIA_SPF(&port->info)*2 > BUFFER_SIZE - sizeof(pjmedia_frame)) + { + pj_assert(!"Too small buffer size for audio switchboard. " + "Try increase PJMEDIA_CONF_SWITCH_BOARD_BUF_SIZE"); + return PJ_ETOOSMALL; + } + /* Create port. */ conf_port = PJ_POOL_ZALLOC_T(pool, struct conf_port); -- cgit v1.2.3