From 2a29b40ed8544aae9143c3d49c1b1a725d5417ca Mon Sep 17 00:00:00 2001 From: Nanang Izzuddin Date: Wed, 27 Feb 2013 09:50:59 +0000 Subject: Re #1532: backported to 1.x git-svn-id: http://svn.pjsip.org/repos/pjproject/branches/1.x@4378 74dad513-b988-da41-8d7b-12977e46ad98 --- pjmedia/src/pjmedia/conference.c | 55 +++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/pjmedia/src/pjmedia/conference.c b/pjmedia/src/pjmedia/conference.c index 46dd4597..2aee1b9e 100644 --- a/pjmedia/src/pjmedia/conference.c +++ b/pjmedia/src/pjmedia/conference.c @@ -1800,15 +1800,18 @@ static pj_status_t get_frame(pjmedia_port *this_port, for (i=0, ci=0; imax_ports && ci < conf->port_cnt; ++i) { struct conf_port *conf_port = conf->ports[i]; - /* Skip empty slot. */ + /* Skip empty port. */ if (!conf_port) continue; + /* Var "ci" is to count how many ports have been visited so far. */ ++ci; - /* Reset buffer & auto adjustment level for mixed signal */ + /* Reset buffer (only necessary if more than one transmitter) and + * reset auto adjustment level for mixed signal. + */ conf_port->mix_adj = NORMAL_LEVEL; - if (conf_port->transmitter_cnt) { + if (conf_port->transmitter_cnt > 1) { pj_bzero(conf_port->mix_buf, conf->samples_per_frame*sizeof(conf_port->mix_buf[0])); } @@ -1817,7 +1820,7 @@ static pj_status_t get_frame(pjmedia_port *this_port, /* Get frames from all ports, and "mix" the signal * to mix_buf of all listeners of the port. */ - for (i=0, ci=0; imax_ports && ciport_cnt; ++i) { + for (i=0, ci=0; i < conf->max_ports && ci < conf->port_cnt; ++i) { struct conf_port *conf_port = conf->ports[i]; pj_int32_t level = 0; @@ -1945,23 +1948,33 @@ static pj_status_t get_frame(pjmedia_port *this_port, mix_buf = listener->mix_buf; - /* Mixing signals, - * and calculate appropriate level adjustment if there is - * any overflowed level in the mixed signal. - */ - for (k=0; ksamples_per_frame; ++k) { - mix_buf[k] += p_in[k]; - /* Check if normalization adjustment needed. */ - if (IS_OVERFLOW(mix_buf[k])) { - /* NORMAL_LEVEL * MAX_LEVEL / mix_buf[k]; */ - int tmp_adj = (MAX_LEVEL<<7) / mix_buf[k]; - if (tmp_adj<0) tmp_adj = -tmp_adj; - - if (tmp_adjmix_adj) - listener->mix_adj = tmp_adj; - - } /* if any overflow in the mixed signals */ - } /* loop mixing signals */ + if (listener->transmitter_cnt > 1) { + /* Mixing signals, + * and calculate appropriate level adjustment if there is + * any overflowed level in the mixed signal. + */ + for (k=0; k < conf->samples_per_frame; ++k) { + mix_buf[k] += p_in[k]; + /* Check if normalization adjustment needed. */ + if (IS_OVERFLOW(mix_buf[k])) { + /* NORMAL_LEVEL * MAX_LEVEL / mix_buf[k]; */ + int tmp_adj = (MAX_LEVEL<<7) / mix_buf[k]; + if (tmp_adj<0) tmp_adj = -tmp_adj; + + if (tmp_adjmix_adj) + listener->mix_adj = tmp_adj; + + } /* if any overflow in the mixed signals */ + } /* loop mixing signals */ + } else { + /* Only 1 transmitter: + * just copy the samples to the mix buffer + * no mixing and level adjustment needed + */ + for (k=0; ksamples_per_frame; ++k) { + mix_buf[k] = p_in[k]; + } + } } /* loop the listeners of conf port */ } /* loop of all conf ports */ -- cgit v1.2.3