diff options
author | Benny Prijono <bennylp@teluu.com> | 2006-08-07 10:24:52 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2006-08-07 10:24:52 +0000 |
commit | c14e6bf7c11fb28266cab45ccaa477a54fe3fd59 (patch) | |
tree | f05279a71b587759964bb0c16fee5259422f2c43 | |
parent | 7786b1e99d249798e0e394bf473b954b3a612072 (diff) |
Change set_ec_tail() API to set_ec() in sound port, also change suppressor to reduce mic signal by division rather than zeroing the signal. Also moved out VAD and EC settings to config.h.
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@658 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r-- | pjmedia/include/pjmedia/config.h | 31 | ||||
-rw-r--r-- | pjmedia/include/pjmedia/silencedet.h | 7 | ||||
-rw-r--r-- | pjmedia/include/pjmedia/sound_port.h | 8 | ||||
-rw-r--r-- | pjmedia/src/pjmedia/echo_suppress.c | 18 | ||||
-rw-r--r-- | pjmedia/src/pjmedia/sound_port.c | 17 | ||||
-rw-r--r-- | pjsip-apps/src/pjsua_wince/pjsua_wince.cpp | 4 | ||||
-rw-r--r-- | pjsip/include/pjsua-lib/pjsua.h | 11 | ||||
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_media.c | 11 |
8 files changed, 75 insertions, 32 deletions
diff --git a/pjmedia/include/pjmedia/config.h b/pjmedia/include/pjmedia/config.h index 871177ae..344ef2c2 100644 --- a/pjmedia/include/pjmedia/config.h +++ b/pjmedia/include/pjmedia/config.h @@ -161,6 +161,16 @@ /** + * Suggested or default threshold to be set for fixed silence detection + * or as starting threshold for adaptive silence detection. The threshold + * has the range from zero to 255. + */ +#ifndef PJMEDIA_SILENCE_DET_THRESHOLD +# define PJMEDIA_SILENCE_DET_THRESHOLD 4 +#endif + + +/** * G.711 Appendix I Packet Lost Concealment (PLC). * Enabled only when floating point is enabled. */ @@ -179,6 +189,27 @@ /** + * Initial signal threshold to be applied to echo suppressor. When + * playback signal level is greater than this threshold, the microphone + * signal will be reduced or cut. + */ +#ifndef PJMEDIA_ECHO_SUPPRESS_THRESHOLD +# define PJMEDIA_ECHO_SUPPRESS_THRESHOLD PJMEDIA_SILENCE_DET_THRESHOLD +#endif + + +/** + * The signal reduction factor to be applied into the microphone signal + * when the mic signal needs to be reduced. Valid values are [1-16], where + * 1 will leave signal as it is (thus probably transmitting the echo) and + * 16 will effectively zero the signal. + */ +#ifndef PJMEDIA_ECHO_SUPPRESS_FACTOR +# define PJMEDIA_ECHO_SUPPRESS_FACTOR 4 +#endif + + +/** * Support for sending and decoding RTCP port in SDP (RFC 3605). * Default is yes. */ diff --git a/pjmedia/include/pjmedia/silencedet.h b/pjmedia/include/pjmedia/silencedet.h index 15cb8460..c4cfbaa8 100644 --- a/pjmedia/include/pjmedia/silencedet.h +++ b/pjmedia/include/pjmedia/silencedet.h @@ -44,13 +44,6 @@ PJ_BEGIN_DECL typedef struct pjmedia_silence_det pjmedia_silence_det; -/** - * Suggested or default threshold to be set for fixed silence detection - * or as starting threshold for adaptive silence detection. The threshold - * has the range from zero to 255. - */ -#define PJMEDIA_SILENCE_DET_THRESHOLD 4 - /** * Create voice activity detector with default settings. The default settings diff --git a/pjmedia/include/pjmedia/sound_port.h b/pjmedia/include/pjmedia/sound_port.h index 7653c35c..c65a11dc 100644 --- a/pjmedia/include/pjmedia/sound_port.h +++ b/pjmedia/include/pjmedia/sound_port.h @@ -197,12 +197,14 @@ PJ_DECL(pjmedia_snd_stream*) pjmedia_snd_port_get_snd_stream( * @param tail_ms Maximum echo tail length to be supported, in * miliseconds. If zero is specified, the EC would * be disabled. + * @param options The options to be passed to #pjmedia_echo_create(). * * @return PJ_SUCCESS on success. */ -PJ_DECL(pj_status_t) pjmedia_snd_port_set_ec_tail(pjmedia_snd_port *snd_port, - pj_pool_t *pool, - unsigned tail_ms); +PJ_DECL(pj_status_t) pjmedia_snd_port_set_ec( pjmedia_snd_port *snd_port, + pj_pool_t *pool, + unsigned tail_ms, + unsigned options); /** diff --git a/pjmedia/src/pjmedia/echo_suppress.c b/pjmedia/src/pjmedia/echo_suppress.c index a3bf4bfb..39b59a64 100644 --- a/pjmedia/src/pjmedia/echo_suppress.c +++ b/pjmedia/src/pjmedia/echo_suppress.c @@ -27,7 +27,6 @@ #define THIS_FILE "echo_suppress.c" -#define PJMEDIA_ECHO_SUPPRESS_THRESHOLD PJMEDIA_SILENCE_DET_THRESHOLD /* @@ -159,7 +158,15 @@ PJ_DEF(pj_status_t) echo_supp_capture( void *state, delay_ms = PJ_TIME_VAL_MSEC(now); if (delay_ms < ec->tail_ms) { +#if defined(PJMEDIA_ECHO_SUPPRESS_FACTOR) && PJMEDIA_ECHO_SUPPRESS_FACTOR!=0 + unsigned i; + for (i=0; i<ec->samples_per_frame; ++i) { + rec_frm[i] = (pj_int16_t)(rec_frm[i] >> + PJMEDIA_ECHO_SUPPRESS_FACTOR); + } +#else pjmedia_zero_samples(rec_frm, ec->samples_per_frame); +#endif } return PJ_SUCCESS; @@ -185,10 +192,17 @@ PJ_DEF(pj_status_t) echo_supp_cancel_echo( void *state, ec->samples_per_frame, NULL); if (!silence) { +#if defined(PJMEDIA_ECHO_SUPPRESS_FACTOR) && PJMEDIA_ECHO_SUPPRESS_FACTOR!=0 + unsigned i; + for (i=0; i<ec->samples_per_frame; ++i) { + rec_frm[i] = (pj_int16_t)(rec_frm[i] >> + PJMEDIA_ECHO_SUPPRESS_FACTOR); + } +#else pjmedia_zero_samples(rec_frm, ec->samples_per_frame); +#endif } return PJ_SUCCESS; } - diff --git a/pjmedia/src/pjmedia/sound_port.c b/pjmedia/src/pjmedia/sound_port.c index dd08a338..ee60dbd9 100644 --- a/pjmedia/src/pjmedia/sound_port.c +++ b/pjmedia/src/pjmedia/sound_port.c @@ -249,14 +249,6 @@ static pj_status_t start_sound_device( pj_pool_t *pool, } } - /* Create AEC only when direction is full duplex */ - if (snd_port->dir == PJMEDIA_DIR_CAPTURE_PLAYBACK) { - status = pjmedia_snd_port_set_ec_tail(snd_port, pool, AEC_TAIL); - if (status != PJ_SUCCESS) { - PJ_LOG(4,(THIS_FILE, "Unable to create AEC")); - snd_port->ec_state = NULL; - } - } /* Start sound stream. */ status = pjmedia_snd_stream_start(snd_port->snd_stream); @@ -432,9 +424,10 @@ PJ_DEF(pjmedia_snd_stream*) pjmedia_snd_port_get_snd_stream( /* * Enable AEC */ -PJ_DEF(pj_status_t) pjmedia_snd_port_set_ec_tail(pjmedia_snd_port *snd_port, - pj_pool_t *pool, - unsigned tail_ms) +PJ_DEF(pj_status_t) pjmedia_snd_port_set_ec( pjmedia_snd_port *snd_port, + pj_pool_t *pool, + unsigned tail_ms, + unsigned options) { pj_status_t status; @@ -454,7 +447,7 @@ PJ_DEF(pj_status_t) pjmedia_snd_port_set_ec_tail(pjmedia_snd_port *snd_port, if (tail_ms != 0) { status = pjmedia_echo_create(pool, snd_port->clock_rate, snd_port->samples_per_frame, - tail_ms, 0, &snd_port->ec_state); + tail_ms, options, &snd_port->ec_state); if (status != PJ_SUCCESS) snd_port->ec_state = NULL; } else { diff --git a/pjsip-apps/src/pjsua_wince/pjsua_wince.cpp b/pjsip-apps/src/pjsua_wince/pjsua_wince.cpp index 8e7fc02d..6ed02e3e 100644 --- a/pjsip-apps/src/pjsua_wince/pjsua_wince.cpp +++ b/pjsip-apps/src/pjsua_wince/pjsua_wince.cpp @@ -38,7 +38,7 @@ enum ID_BTN_ACTION, }; -#define DEFAULT_URI "sip:192.168.0.66" +#define DEFAULT_URI "sip:192.168.0.7" // Forward declarations of functions included in this code module: @@ -284,7 +284,7 @@ static BOOL OnInitStack(void) /* Setup media */ media_cfg.clock_rate = 8000; - //media_cfg.ec_tail_len = ; + media_cfg.ec_options = PJMEDIA_ECHO_SIMPLE; media_cfg.quality = 1; media_cfg.ptime = 20; diff --git a/pjsip/include/pjsua-lib/pjsua.h b/pjsip/include/pjsua-lib/pjsua.h index da921c44..e2ae3857 100644 --- a/pjsip/include/pjsua-lib/pjsua.h +++ b/pjsip/include/pjsua-lib/pjsua.h @@ -2133,6 +2133,13 @@ struct pjsua_media_config unsigned rx_drop_pct; /** + * Echo canceller options (see #pjmedia_echo_create()) + * + * Default: 0. + */ + unsigned ec_options; + + /** * Echo canceller tail length, in miliseconds. * * Default: 128 (PJSUA_DEFAULT_EC_TAIL_LEN) @@ -2506,10 +2513,12 @@ PJ_DECL(pjmedia_port*) pjsua_set_no_snd_dev(void); * * @param tail_ms The tail length, in miliseconds. Set to zero to * disable AEC. + * @param options Options to be passed to #pjmedia_echo_create(). + * Normally the value should be zero. * * @return PJ_SUCCESS on success. */ -PJ_DECL(pj_status_t) pjsua_set_ec_tail(unsigned tail_ms); +PJ_DECL(pj_status_t) pjsua_set_ec(unsigned tail_ms, unsigned options); /** diff --git a/pjsip/src/pjsua-lib/pjsua_media.c b/pjsip/src/pjsua-lib/pjsua_media.c index d3c3eb2e..849d1952 100644 --- a/pjsip/src/pjsua-lib/pjsua_media.c +++ b/pjsip/src/pjsua-lib/pjsua_media.c @@ -969,8 +969,9 @@ PJ_DEF(pj_status_t) pjsua_set_snd_dev( int capture_dev, pj_assert(conf_port != NULL); /* Set AEC */ - pjmedia_snd_port_set_ec_tail(pjsua_var.snd_port, pjsua_var.pool, - pjsua_var.media_cfg.ec_tail_len); + pjmedia_snd_port_set_ec( pjsua_var.snd_port, pjsua_var.pool, + pjsua_var.media_cfg.ec_tail_len, + pjsua_var.media_cfg.ec_options); /* Connect sound port to the bridge */ status = pjmedia_snd_port_connect(pjsua_var.snd_port, @@ -1044,13 +1045,13 @@ PJ_DEF(pjmedia_port*) pjsua_set_no_snd_dev(void) /* * Configure the AEC settings of the sound port. */ -PJ_DEF(pj_status_t) pjsua_set_ec_tail(unsigned tail_ms) +PJ_DEF(pj_status_t) pjsua_set_ec(unsigned tail_ms, unsigned options) { pjsua_var.media_cfg.ec_tail_len = tail_ms; if (pjsua_var.snd_port) - return pjmedia_snd_port_set_ec_tail(pjsua_var.snd_port, pjsua_var.pool, - tail_ms); + return pjmedia_snd_port_set_ec( pjsua_var.snd_port, pjsua_var.pool, + tail_ms, options); return PJ_SUCCESS; } |