Changeset 4161 for pjproject


Ignore:
Timestamp:
Jun 7, 2012 9:28:48 AM (12 years ago)
Author:
nanang
Message:

Close #1532: optimization in conference bridge get_frame().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia/conference.c

    r3664 r4161  
    17981798    pj_mutex_lock(conf->mutex); 
    17991799 
    1800     /* Reset port source count. We will only reset port's mix 
    1801      * buffer when we have someone transmitting to it. 
    1802      */ 
    1803     for (i=0, ci=0; i<conf->max_ports && ci < conf->port_cnt; ++i) { 
     1800    /* Get frames from all ports, and "mix" the signal  
     1801     * to mix_buf of all listeners of the port. 
     1802     */ 
     1803    for (i=0, ci=0; i < conf->max_ports && ci < conf->port_cnt; ++i) { 
    18041804        struct conf_port *conf_port = conf->ports[i]; 
    1805  
    1806         /* Skip empty slot. */ 
     1805        pj_int32_t level = 0; 
     1806 
     1807        /* Skip empty port. */ 
    18071808        if (!conf_port) 
    18081809            continue; 
    18091810 
     1811        /* Var "ci" is to count how many ports have been visited so far. */ 
    18101812        ++ci; 
    18111813 
    1812         /* Reset buffer & auto adjustment level for mixed signal */ 
     1814        /* Reset buffer (only necessary if more than one transmitter) & 
     1815         * reset auto adjustment level for mixed signal */ 
    18131816        conf_port->mix_adj = NORMAL_LEVEL; 
    1814         if (conf_port->transmitter_cnt) { 
     1817        if (conf_port->transmitter_cnt > 1) { 
    18151818            pj_bzero(conf_port->mix_buf, 
    18161819                     conf->samples_per_frame*sizeof(conf_port->mix_buf[0])); 
    18171820        } 
    1818     } 
    1819  
    1820     /* Get frames from all ports, and "mix" the signal  
    1821      * to mix_buf of all listeners of the port. 
    1822      */ 
    1823     for (i=0, ci=0; i<conf->max_ports && ci<conf->port_cnt; ++i) { 
    1824         struct conf_port *conf_port = conf->ports[i]; 
    1825         pj_int32_t level = 0; 
    1826  
    1827         /* Skip empty port. */ 
    1828         if (!conf_port) 
    1829             continue; 
    1830  
    1831         /* Var "ci" is to count how many ports have been visited so far. */ 
    1832         ++ci; 
    18331821 
    18341822        /* Skip if we're not allowed to receive from this port. */ 
     
    19491937            mix_buf = listener->mix_buf; 
    19501938 
    1951             /* Mixing signals, 
    1952              * and calculate appropriate level adjustment if there is 
    1953              * any overflowed level in the mixed signal. 
    1954              */ 
    1955             for (k=0; k<conf->samples_per_frame; ++k) { 
    1956                 mix_buf[k] += p_in[k]; 
    1957                 /* Check if normalization adjustment needed. */ 
    1958                 if (IS_OVERFLOW(mix_buf[k])) { 
    1959                     /* NORMAL_LEVEL * MAX_LEVEL / mix_buf[k]; */ 
    1960                     int tmp_adj = (MAX_LEVEL<<7) / mix_buf[k]; 
    1961                     if (tmp_adj<0) tmp_adj = -tmp_adj; 
    1962  
    1963                     if (tmp_adj<listener->mix_adj) 
    1964                         listener->mix_adj = tmp_adj; 
    1965  
    1966                 } /* if any overflow in the mixed signals */ 
    1967             } /* loop mixing signals */ 
     1939            if (listener->transmitter_cnt > 1) { 
     1940                /* Mixing signals, 
     1941                 * and calculate appropriate level adjustment if there is 
     1942                 * any overflowed level in the mixed signal. 
     1943                 */ 
     1944                for (k=0; k < conf->samples_per_frame; ++k) { 
     1945                    mix_buf[k] += p_in[k]; 
     1946                    /* Check if normalization adjustment needed. */ 
     1947                    if (IS_OVERFLOW(mix_buf[k])) { 
     1948                        /* NORMAL_LEVEL * MAX_LEVEL / mix_buf[k]; */ 
     1949                        int tmp_adj = (MAX_LEVEL<<7) / mix_buf[k]; 
     1950                        if (tmp_adj<0) tmp_adj = -tmp_adj; 
     1951 
     1952                        if (tmp_adj<listener->mix_adj) 
     1953                            listener->mix_adj = tmp_adj; 
     1954 
     1955                    } /* if any overflow in the mixed signals */ 
     1956                } /* loop mixing signals */ 
     1957            } else { 
     1958                /* Only 1 transmitter: 
     1959                 * just copy the samples to the mix buffer 
     1960                 * no mixing and level adjustment needed 
     1961                 */ 
     1962                for (k=0; k<conf->samples_per_frame; ++k) { 
     1963                    mix_buf[k] = p_in[k]; 
     1964                } 
     1965            } 
    19681966        } /* loop the listeners of conf port */ 
    19691967    } /* loop of all conf ports */ 
Note: See TracChangeset for help on using the changeset viewer.