Changeset 513


Ignore:
Timestamp:
Jun 16, 2006 3:54:43 PM (16 years ago)
Author:
bennylp
Message:

Optimizations mostly in the conference bridge (gained more than 3x faster)

Location:
pjproject/trunk
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/include/pj/doxygen.h

    r66 r513  
    3535 * @section intro_sec What is PJLIB 
    3636 * 
    37  * PJLIB is a small foundation library written in C for making scalable  
    38  * applications. Because of its small footprint, it can be used in embedded  
    39  * applications (we hope so!), but yet the library is also aimed for  
    40  * facilitating high performance protocol stacks. 
    41  * 
    42  * PJLIB is released under LGPL terms. 
     37 * PJLIB is an Open Source, small footprint framework library written in C for  
     38 * making scalable applications. Because of its small footprint, it can be used 
     39 * in embedded applications (we hope so!), but yet the library is also aimed for 
     40 * facilitating the creation of high performance protocol stacks. 
     41 * 
     42 * PJLIB is released under GPL terms. 
    4343 * 
    4444 * @section download_sec Download 
     
    5656 * @subsection doc_ver_subsec Version 
    5757 * 
    58  * This document corresponds to PJLIB version 0.3-pre2. 
     58 * This document corresponds to PJLIB version 0.5.6. 
    5959 * 
    6060 * 
     
    115115 * @subsection open_source_feat It's Open Source! 
    116116 * 
    117  * PJLIB is currently released on LGPL license. We may release PJLIB under 
    118  * additional schemes in the future (such as GPL or MPL) to incorporate 
    119  * linking with specific application, however, one thing for sure is 
    120  * we will NEVER be able to make PJLIB a proprietary software. 
     117 * PJLIB is currently released on GPL license, but other arrangements 
     118 * can be made with the author. 
    121119 * 
    122120 * @subsection extreme_portable_feat Extreme Portability 
     
    128126 * It can even run in environment where no ANSI LIBC is available.  
    129127 * 
    130  * Currently PJLIB is being ported to: 
    131  *  - x86, Win32 (Win95/98/ME, NT/2000/XP/2003, mingw). 
    132  *  - x86, Linux (user mode and as <b>kernel module</b>(!)). 
    133  *  - alpha, Linux 
    134  * And coming up: 
    135  *  - x86, eCos 
    136  *  - ultra-II, Solaris. 
    137  *  - powerpc, MacOS 
    138  *  - m68k, PalmOS. 
    139  *  - arm, PocketPC 
    140  * 
    141  * No other library is known to have this extreme portability! 
     128 * Currently PJLIB is known to run on these platforms: 
     129 *  - Win32/x86 (Win95/98/ME, NT/2000/XP/2003, mingw). 
     130 *  - arm, WinCE and Windows Mobile. 
     131 *  - Linux/x86, (user mode and as <b>kernel module</b>(!)). 
     132 *  - Linux/alpha 
     133 *  - Solaris/ultra. 
     134 *  - MacOS X/powerpc 
     135 *  - RTEMS (x86 and powerpc). 
     136 * 
     137 * And efforts is under way to port PJLIB on: 
     138 *  - Symbian OS 
     139 * 
    142140 * 
    143141 * @subsection small_size_feat Small in Size 
     
    152150 * For more info, please see @ref pj_config. 
    153151 * 
     152 * 
     153 * @subsection big_perform_feat Big in Performance 
     154 * 
     155 * Almost everything in PJLIB is designed to achieve the highest possible 
     156 * performance out of the target platform.  
     157 * 
     158 * 
    154159 * @subsection no_dyn_mem No Dynamic Memory Allocations 
    155160 * 
     
    165170 *    destroyed. 
    166171 * 
    167  * The performance gained on some systems can be as high as 10x speed up 
    168  * against \a malloc() and \a free(). 
     172 * The performance gained on some systems can be as high as 30x speed up 
     173 * against \a malloc() and \a free() on certain configurations, but of 
     174 * course your mileage may vary.  
    169175 * 
    170176 * For more information, see \ref PJ_POOL_GROUP 
     
    384390 * 
    385391 * You MUST NOT use \a malloc() or any other memory allocation functions. 
    386  * Use PJLIB pool instead! It's faster and most portable. 
     392 * Use PJLIB @ref PJ_POOL_GROUP instead! It's faster and most portable. 
    387393 * 
    388394 * @subsection logging_subsubsec Use Logging for Text Display 
    389395 * 
    390  * DO NOT use <stdio.h> for text output. Use PJLIB logging instead. 
     396 * DO NOT use <stdio.h> for text output. Use PJLIB @ref PJ_LOG instead. 
    391397 * 
    392398 * 
  • pjproject/trunk/pjmedia/include/pjmedia/conference.h

    r492 r513  
    4545    pjmedia_port_op     tx_setting;         /**< Transmit settings.         */ 
    4646    pjmedia_port_op     rx_setting;         /**< Receive settings.          */ 
    47     pj_bool_t          *listener;           /**< Array of listeners.        */ 
     47    unsigned            listener_cnt;       /**< Number of listeners.       */ 
     48    unsigned           *listener_slots;     /**< Array of listeners.        */ 
    4849    unsigned            clock_rate;         /**< Clock rate of the port.    */ 
    4950    unsigned            channel_count;      /**< Number of channels.        */ 
  • pjproject/trunk/pjmedia/include/pjmedia/types.h

    r506 r513  
    2121 
    2222#include <pjmedia/config.h> 
    23 #include <pj/sock.h> 
     23#include <pj/sock.h>        /* pjmedia_sock_info        */ 
     24#include <pj/string.h>      /* pj_memcpy(), pj_memset() */ 
     25 
    2426 
    2527/**  
     
    125127PJ_INLINE(void) pjmedia_zero_samples(pj_int16_t *samples, unsigned count) 
    126128{ 
     129#if 1 
     130    pj_memset(samples, 0, count*sizeof(pj_int16_t)); 
     131#elif 0 
    127132    unsigned i; 
    128     for (i=0; i<count; ++i) 
    129         samples[i] = 0; 
     133    for (i=0; i<count; ++i) samples[i] = 0; 
     134#else 
     135    unsigned i; 
     136    count >>= 1; 
     137    for (i=0; i<count; ++i) ((pj_int32_t*)samples)[i] = (pj_int32_t)0; 
     138#endif 
    130139} 
    131140 
     
    140149                                     unsigned count) 
    141150{ 
     151#if 1 
     152    pj_memcpy(dst, src, count*sizeof(pj_int16_t)); 
     153#elif 0 
    142154    unsigned i; 
    143     for (i=0; i<count; ++i) 
    144         dst[i] = src[i]; 
     155    for (i=0; i<count; ++i) dst[i] = src[i]; 
     156#else 
     157    unsigned i; 
     158    count >>= 1; 
     159    for (i=0; i<count; ++i)  
     160        ((pj_int32_t*)dst)[i] = ((pj_int32_t*)src)[i]; 
     161#endif 
    145162} 
    146163 
  • pjproject/trunk/pjmedia/src/pjmedia/conference.c

    r506 r513  
    2424#include <pjmedia/sound_port.h> 
    2525#include <pjmedia/stream.h> 
     26#include <pj/array.h> 
    2627#include <pj/assert.h> 
    2728#include <pj/log.h> 
     
    5859 
    5960#define NORMAL_LEVEL        128 
     61#define SLOT_TYPE           unsigned 
     62#define INVALID_SLOT        ((SLOT_TYPE)-1) 
    6063 
    6164 
     
    7982    pjmedia_port_op      rx_setting;    /**< Can we receive from this port  */ 
    8083    pjmedia_port_op      tx_setting;    /**< Can we transmit to this port   */ 
    81     int                  listener_cnt;  /**< Number of listeners.           */ 
    82     pj_bool_t           *listeners;     /**< Array of listeners.            */ 
     84    unsigned             listener_cnt;  /**< Number of listeners.           */ 
     85    SLOT_TYPE           *listener_slots;/**< Array of listeners.            */ 
     86    unsigned             transmitter_cnt;/**<Number of transmitters.        */ 
    8387    pjmedia_silence_det *vad;           /**< VAD for this port.             */ 
    8488 
     
    8892 
    8993    /* Calculated signal levels: */ 
    90     pj_bool_t            need_tx_level; /**< Need to calculate tx level?    */ 
    9194    unsigned             tx_level;      /**< Last tx level to this port.    */ 
    9295    unsigned             rx_level;      /**< Last rx level from this port.  */ 
     
    122125     * received by this port from all other ports. Samples from all ports 
    123126     * that are transmitting to this port will be accumulated here, then 
    124      * they will be divided by the sources count before the samples are put 
     127     * they will be divided by the source level before the samples are put 
    125128     * to the TX buffer of this port. 
    126129     * 
     
    130133     * Note that the samples here are unsigned 32bit. 
    131134     */ 
    132     unsigned             sources;       /**< Number of sources.             */ 
     135    unsigned             src_level;     /**< Sum of input levels            */ 
     136    unsigned             src_cnt;       /**< Number of sources.             */ 
    133137    pj_uint32_t         *mix_buf;       /**< Total sum of signal.           */ 
    134138 
     
    224228 
    225229    /* Create transmit flag array */ 
    226     conf_port->listeners = pj_pool_zalloc(pool,  
    227                                           conf->max_ports*sizeof(pj_bool_t)); 
    228     PJ_ASSERT_RETURN(conf_port->listeners, PJ_ENOMEM); 
    229  
     230    conf_port->listener_slots = pj_pool_zalloc(pool,  
     231                                          conf->max_ports * sizeof(SLOT_TYPE)); 
     232    PJ_ASSERT_RETURN(conf_port->listener_slots, PJ_ENOMEM); 
    230233 
    231234    /* Save some port's infos, for convenience. */ 
     
    667670    struct conf_port *src_port, *dst_port; 
    668671    pj_bool_t start_sound = PJ_FALSE; 
     672    unsigned i; 
    669673 
    670674    /* Check arguments */ 
     
    684688    dst_port = conf->ports[sink_slot]; 
    685689 
    686     if (src_port->listeners[sink_slot] == 0) { 
    687         src_port->listeners[sink_slot] = 1; 
     690    /* Check if connection has been made */ 
     691    for (i=0; i<src_port->listener_cnt; ++i) { 
     692        if (src_port->listener_slots[i] == sink_slot) 
     693            break; 
     694    } 
     695 
     696    if (i == src_port->listener_cnt) { 
     697        src_port->listener_slots[src_port->listener_cnt] = sink_slot; 
    688698        ++conf->connect_cnt; 
    689699        ++src_port->listener_cnt; 
     700        ++dst_port->transmitter_cnt; 
    690701 
    691702        if (conf->connect_cnt == 1) 
    692703            start_sound = 1; 
    693704 
    694         PJ_LOG(4,(THIS_FILE,"Port %.*s transmitting to port %.*s", 
     705        PJ_LOG(4,(THIS_FILE,"Port %d (%.*s) transmitting to port %d (%.*s)", 
     706                  src_slot, 
    695707                  (int)src_port->name.slen, 
    696708                  src_port->name.ptr, 
     709                  sink_slot, 
    697710                  (int)dst_port->name.slen, 
    698711                  dst_port->name.ptr)); 
     
    719732{ 
    720733    struct conf_port *src_port, *dst_port; 
     734    unsigned i; 
    721735 
    722736    /* Check arguments */ 
     
    733747    dst_port = conf->ports[sink_slot]; 
    734748 
    735     if (src_port->listeners[sink_slot] != 0) { 
    736         src_port->listeners[sink_slot] = 0; 
     749    /* Check if connection has been made */ 
     750    for (i=0; i<src_port->listener_cnt; ++i) { 
     751        if (src_port->listener_slots[i] == sink_slot) 
     752            break; 
     753    } 
     754 
     755    if (i != src_port->listener_cnt) { 
     756        pj_assert(src_port->listener_cnt > 0 &&  
     757                  src_port->listener_cnt < conf->max_ports); 
     758        pj_assert(dst_port->transmitter_cnt > 0 &&  
     759                  dst_port->transmitter_cnt < conf->max_ports); 
     760        pj_array_erase(src_port->listener_slots, sizeof(SLOT_TYPE),  
     761                       src_port->listener_cnt, i); 
    737762        --conf->connect_cnt; 
    738763        --src_port->listener_cnt; 
    739  
    740         PJ_LOG(4,(THIS_FILE,"Port %.*s stop transmitting to port %.*s", 
     764        --dst_port->transmitter_cnt; 
     765 
     766        PJ_LOG(4,(THIS_FILE, 
     767                  "Port %d (%.*s) stop transmitting to port %d (%.*s)", 
     768                  src_slot, 
    741769                  (int)src_port->name.slen, 
    742770                  src_port->name.ptr, 
     771                  sink_slot, 
    743772                  (int)dst_port->name.slen, 
    744773                  dst_port->name.ptr)); 
     
    785814    /* Remove this port from transmit array of other ports. */ 
    786815    for (i=0; i<conf->max_ports; ++i) { 
     816        unsigned j; 
     817 
    787818        conf_port = conf->ports[i]; 
    788819 
     
    790821            continue; 
    791822 
    792         if (conf_port->listeners[port] != 0) { 
    793             --conf->connect_cnt; 
    794             --conf_port->listener_cnt; 
    795             conf_port->listeners[port] = 0; 
     823        if (conf_port->listener_cnt == 0) 
     824            continue; 
     825 
     826        for (j=0; j<conf_port->listener_cnt; ++j) { 
     827            if (conf_port->listener_slots[j] == port) { 
     828                pj_array_erase(conf_port->listener_slots, sizeof(SLOT_TYPE), 
     829                               conf_port->listener_cnt, j); 
     830                --conf->connect_cnt; 
     831                --conf_port->listener_cnt; 
     832                break; 
     833            } 
    796834        } 
    797835    } 
    798836 
    799     /* Remove all ports listening from this port. */ 
     837    /* Update conf's connection count. */ 
    800838    conf_port = conf->ports[port]; 
    801     for (i=0; i<conf->max_ports; ++i) { 
    802         if (conf_port->listeners[i]) { 
    803             --conf->connect_cnt; 
    804             --conf_port->listener_cnt; 
    805         } 
    806     } 
     839    conf->connect_cnt -= conf_port->listener_cnt; 
    807840 
    808841    /* Remove the port. */ 
     
    865898    info->tx_setting = conf_port->tx_setting; 
    866899    info->rx_setting = conf_port->rx_setting; 
    867     info->listener = conf_port->listeners; 
     900    info->listener_cnt = conf_port->listener_cnt; 
     901    info->listener_slots = conf_port->listener_slots; 
    868902    info->clock_rate = conf_port->clock_rate; 
    869903    info->channel_count = conf->channel_count; 
     
    917951 
    918952    if (tx_level != NULL) { 
    919         conf_port->need_tx_level = 1; 
    920953        *tx_level = conf_port->tx_level; 
    921954    } 
     
    11211154     */ 
    11221155    /* note: 
    1123      *  the "cport->sources==0" checking will cause discontinuous 
     1156     *  the "cport->src_level==0" checking will cause discontinuous 
    11241157     *  transmission for RTP stream. 
    11251158     */ 
    1126     if (cport->tx_setting == PJMEDIA_PORT_MUTE || cport->sources==0) { 
     1159    if (cport->tx_setting == PJMEDIA_PORT_MUTE || cport->src_level==0) { 
    11271160 
    11281161        pjmedia_frame frame; 
     
    11441177    } 
    11451178 
     1179    buf = (pj_int16_t*)cport->mix_buf; 
     1180 
     1181    /* This is the convention set in get_frame(). For optimization purpose, 
     1182     * if we only have one transmitter transmitting to this port, then 
     1183     * the transmitter will directly copy the original 16bit frame to 
     1184     * mix_buf. 
     1185     */ 
     1186    if (cport->transmitter_cnt==1 && cport->src_cnt == 1) { 
     1187 
     1188        /* But still see if we need to adjust the level */ 
     1189        if (cport->tx_adj_level != NORMAL_LEVEL) { 
     1190            pj_int16_t *input = buf; 
     1191            pj_int32_t adj = cport->tx_adj_level; 
     1192 
     1193            for (j=0; j<conf->samples_per_frame; ++j) { 
     1194                pj_int32_t itemp; 
     1195 
     1196                /* For the level adjustment, we need to store the sample to 
     1197                 * a temporary 32bit integer value to avoid overflowing the 
     1198                 * 16bit sample storage. 
     1199                 */ 
     1200                itemp = input[j]; 
     1201                itemp = itemp * adj / NORMAL_LEVEL; 
     1202 
     1203                /* Clip the signal if it's too loud */ 
     1204                if (itemp > 32767) itemp = 32767; 
     1205                else if (itemp < -32768) itemp = -32768; 
     1206 
     1207                input[j] = (pj_int16_t) itemp; 
     1208            } 
     1209        } 
     1210 
     1211    }  
    11461212    /* If there are sources in the mix buffer, convert the mixed samples 
    11471213     * to the mixed samples itself. This is possible because mixed sample 
     
    11511217     * TX signal, we adjust is here too. 
    11521218     */ 
    1153     buf = (pj_int16_t*)cport->mix_buf; 
    1154  
    1155     if (cport->tx_adj_level != NORMAL_LEVEL && cport->sources) { 
     1219    else if (cport->tx_adj_level != NORMAL_LEVEL && cport->src_level) { 
    11561220 
    11571221        unsigned adj_level = cport->tx_adj_level; 
     
    11641228             * 16bit signed integer. 
    11651229             */ 
    1166             itemp = unsigned2pcm(cport->mix_buf[j] / cport->sources); 
     1230            itemp = unsigned2pcm(cport->mix_buf[j] / cport->src_level); 
    11671231 
    11681232            /* Adjust the level */ 
     
    11771241        } 
    11781242 
    1179     } else if (cport->sources) { 
     1243    } else if (cport->src_level) { 
    11801244        /* No need to adjust signal level. */ 
    11811245        for (j=0; j<conf->samples_per_frame; ++j) { 
    1182             buf[j] = unsigned2pcm(cport->mix_buf[j] / cport->sources); 
     1246            buf[j] = unsigned2pcm(cport->mix_buf[j] / cport->src_level); 
    11831247        } 
    11841248    } else { 
    11851249        // Not necessarry. Buffer has been zeroed before. 
    11861250        // pjmedia_zero_samples(buf, conf->samples_per_frame); 
    1187         pj_assert(buf[0] == 0); 
     1251        //pj_assert(buf[0] == 0); 
     1252 
     1253        // This shouldn't happen. Function should've already bailed out when 
     1254        // cport->src_level == 0. 
     1255        pj_assert(0); 
    11881256    } 
    11891257 
     
    11971265     * indication of the signal level of the port. 
    11981266     */ 
    1199     if (cport->need_tx_level && cport->sources) { 
    1200         pj_uint32_t level; 
    1201  
    1202         /* Get the signal level. */ 
    1203         level = pjmedia_calc_avg_signal(buf, conf->samples_per_frame); 
    1204  
    1205         /* Convert level to 8bit complement ulaw */ 
    1206         cport->tx_level = linear2ulaw(level) ^ 0xff; 
    1207  
     1267    if (cport->src_cnt) { 
     1268        cport->tx_level = cport->src_level / cport->src_cnt; 
    12081269    } else { 
    12091270        cport->tx_level = 0; 
     
    13111372                             conf->bits_per_sample / 8); 
    13121373 
    1313     /* Must lock mutex (must we??) */ 
     1374    /* Must lock mutex */ 
    13141375    pj_mutex_lock(conf->mutex); 
    13151376 
    1316     /* Zero all port's temporary buffers. */ 
     1377    /* Reset port source count. We will only reset port's mix 
     1378     * buffer when we have someone transmitting to it. 
     1379     */ 
    13171380    for (i=0, ci=0; i<conf->max_ports && ci < conf->port_cnt; ++i) { 
    13181381        struct conf_port *conf_port = conf->ports[i]; 
    1319         pj_uint32_t *mix_buf; 
    13201382 
    13211383        /* Skip empty slot. */ 
     
    13251387        ++ci; 
    13261388 
    1327         conf_port->sources = 0; 
    1328         mix_buf = conf_port->mix_buf; 
    1329  
    1330         pj_memset(mix_buf, 0, conf->samples_per_frame*sizeof(mix_buf[0])); 
     1389        /* Reset sources */ 
     1390        conf_port->src_level = 0; 
     1391        conf_port->src_cnt = 0; 
    13311392    } 
    13321393 
     
    14421503        conf_port->rx_level = level; 
    14431504 
     1505        /* Skip processing frame if level is zero */ 
     1506        if (level == 0) 
     1507            continue; 
     1508 
    14441509        /* Convert the buffer to unsigned 16bit value */ 
    14451510        for (j=0; j<conf->samples_per_frame; ++j) 
     
    14471512 
    14481513        /* Add the signal to all listeners. */ 
    1449         for (j=0, cj=0;  
    1450              j<conf->max_ports && cj<(unsigned)conf_port->listener_cnt; 
    1451              ++j)  
     1514        for (cj=0; cj < conf_port->listener_cnt; ++cj)  
    14521515        { 
    1453             struct conf_port *listener = conf->ports[j]; 
     1516            struct conf_port *listener; 
    14541517            pj_uint32_t *mix_buf; 
    14551518            unsigned k; 
    14561519 
    1457             if (listener == 0) 
    1458                 continue; 
    1459  
    1460             /* Skip if this is not the listener. */ 
    1461             if (!conf_port->listeners[j]) 
    1462                 continue; 
    1463  
    1464             /* Var "cj" is the number of listeners we have visited so far */ 
    1465             ++cj; 
     1520            listener = conf->ports[conf_port->listener_slots[cj]]; 
    14661521 
    14671522            /* Skip if this listener doesn't want to receive audio */ 
     
    14691524                continue; 
    14701525 
    1471             /* Mix the buffer */ 
     1526            /* Mix the buffer. If this is the first source for target port, 
     1527             * zero the mix buffer of target port first. 
     1528             */ 
    14721529            mix_buf = listener->mix_buf; 
    1473             for (k=0; k<conf->samples_per_frame; ++k) 
    1474                 mix_buf[k] += (conf->uns_buf[k] * level); 
    1475  
    1476             listener->sources += level; 
     1530            if (listener->src_level == 0) { 
     1531                pj_memset(mix_buf, 0,  
     1532                          conf->samples_per_frame*sizeof(mix_buf[0])); 
     1533            } 
     1534 
     1535            /* A little bit of optimization: 
     1536             *  When "conf_port" is the only transmitter to "listener", 
     1537             *  just add copy the frame directly from the original 
     1538             *  16bit frame (avoiding unsigned2pcm() conversion). 
     1539             *  But write_port() needs to be aware of this trick! 
     1540             */ 
     1541            if (listener->transmitter_cnt == 1) { 
     1542                pjmedia_copy_samples((pj_int16_t*)mix_buf,  
     1543                                     frame->buf, conf->samples_per_frame); 
     1544                listener->src_level = level; 
     1545            } else { 
     1546                for (k=0; k<conf->samples_per_frame; ++k) 
     1547                    mix_buf[k] += (conf->uns_buf[k] * level); 
     1548 
     1549                listener->src_level += level; 
     1550            } 
     1551            listener->src_cnt++; 
    14771552        } 
    14781553    } 
     
    15111586 
    15121587    /* Return sound playback frame. */ 
    1513     if (conf->ports[0]->sources) { 
     1588    if (conf->ports[0]->src_level) { 
    15141589        TRACE_((THIS_FILE, "write to audio, count=%d",  
    15151590                           conf->samples_per_frame)); 
  • pjproject/trunk/pjmedia/src/pjmedia/dsound.c

    r470 r513  
    369369    if SUCCEEDED(hr) {  
    370370        // Read from pointers.  
    371         CopyMemory(lpbSoundData, lpvPtr1, dwBytes1);  
     371        pj_memcpy(lpbSoundData, lpvPtr1, dwBytes1);  
    372372        if (lpvPtr2 != NULL) 
    373             CopyMemory(lpbSoundData+dwBytes1, lpvPtr2, dwBytes2);  
     373            pj_memcpy(lpbSoundData+dwBytes1, lpvPtr2, dwBytes2);  
    374374         
    375375        // Release the data back to DirectSound.  
     
    408408    }  
    409409    if SUCCEEDED(hr) {  
    410         CopyMemory(lpvPtr1, lpbSoundData, dwBytes1);  
     410        pj_memcpy(lpvPtr1, lpbSoundData, dwBytes1);  
    411411        if (NULL != lpvPtr2)  
    412             CopyMemory(lpvPtr2, lpbSoundData+dwBytes1, dwBytes2);  
     412            pj_memcpy(lpvPtr2, lpbSoundData+dwBytes1, dwBytes2);  
    413413         
    414414        hr = IDirectSoundBuffer_Unlock(lpDsb, lpvPtr1, dwBytes1, lpvPtr2, dwBytes2);  
  • pjproject/trunk/pjmedia/src/pjmedia/resample.c

    r495 r513  
    5959 *  - move stddefs.h and resample.h to this file. 
    6060 *  - const correctness. 
    61  *  - fixed SrcLinear() may write pass output buffer. 
    62  *  - assume the same for SrcUp() and SrcUD(), so put the same 
    63  *    protection. 
    6461 */ 
    6562#include <pjmedia/resample.h> 
     
    261258    Yend = Ystart + (unsigned)(nx * pFactor); 
    262259    endTime = time + (1<<Np)*(WORD)nx; 
    263     while (time < endTime && Y < Yend)  /* bennylp fix: added Y < Yend */ 
     260    while (time < endTime) 
    264261    { 
    265262        iconst = (time) & Pmask; 
     
    400397    Yend = Ystart + (unsigned)(nx * pFactor); 
    401398    endTime = time + (1<<Np)*(WORD)nx; 
    402     while (time < endTime && Y < Yend)  /* bennylp fix: protect Y */ 
     399    while (time < endTime) 
    403400    { 
    404401        xp = &X[time>>Np];      /* Ptr to current input sample */ 
     
    444441    Yend = Ystart + (unsigned)(nx * pFactor); 
    445442    endTime = time + (1<<Np)*(WORD)nx; 
    446     while (time < endTime && Y < Yend) /* bennylp fix: protect Y */ 
     443    while (time < endTime) 
    447444    { 
    448445        xp = &X[time>>Np];      /* Ptr to current input sample */ 
     
    496493    /* 
    497494     * If we're downsampling, always use the fast algorithm since it seems 
    498      * to yield the same performance. 
     495     * to yield the same quality. 
    499496     */ 
    500497    if (rate_out < rate_in) { 
     498        //no this is not a good idea. It sounds pretty good with speech, 
     499        //but very poor with background noise etc. 
    501500        //high_quality = 0; 
    502501    } 
     
    534533    if (high_quality) { 
    535534        unsigned size; 
    536         unsigned i; 
    537535 
    538536        /* This is a bug in xoff calculation, thanks Stephane Lussier 
     
    552550        PJ_ASSERT_RETURN(resample->buffer, PJ_ENOMEM); 
    553551 
    554         for (i=0; i<resample->xoff*2; ++i) { 
    555             resample->buffer[i] = 0; 
    556         } 
     552        pjmedia_zero_samples(resample->buffer, resample->xoff*2); 
    557553 
    558554 
     
    562558 
    563559    *p_resample = resample; 
     560 
     561    PJ_LOG(5,(THIS_FILE, "resample created: %s qualiy, %s filter, in/out " 
     562                          "rate=%d/%d",  
     563                          (high_quality?"high":"low"), 
     564                          (large_filter?"large":"small"), 
     565                          rate_in, rate_out)); 
    564566    return PJ_SUCCESS; 
    565567} 
     
    574576 
    575577    if (resample->high_quality) { 
    576         unsigned i; 
    577578        pj_int16_t *dst_buf; 
    578579        const pj_int16_t *src_buf; 
     
    645646         */ 
    646647        dst_buf = resample->buffer + resample->xoff*2; 
    647         for (i=0; i<resample->frame_size; ++i) dst_buf[i] = input[i]; 
     648        pjmedia_copy_samples(dst_buf, input, resample->frame_size); 
    648649             
    649650        if (resample->factor >= 1) { 
     
    689690        dst_buf = resample->buffer; 
    690691        src_buf = input + resample->frame_size - resample->xoff*2; 
    691         for (i=0; i<resample->xoff * 2; ++i) { 
    692             dst_buf[i] = src_buf[i]; 
    693         } 
     692        pjmedia_copy_samples(dst_buf, src_buf, resample->xoff * 2); 
    694693 
    695694    } else { 
  • pjproject/trunk/pjsip-apps/build/Samples-vc.mak

    r464 r513  
    3737 
    3838SAMPLES = $(BINDIR)\confsample.exe \ 
     39          $(BINDIR)\confbench.exe \ 
    3940          $(BINDIR)\level.exe \ 
    4041          $(BINDIR)\playfile.exe \ 
  • pjproject/trunk/pjsip-apps/build/samples.dsp

    r464 r513  
    8787# Begin Source File 
    8888 
     89SOURCE=..\src\samples\confbench.c 
     90# End Source File 
     91# Begin Source File 
     92 
    8993SOURCE=..\src\samples\confsample.c 
    9094# End Source File 
  • pjproject/trunk/pjsip-apps/src/samples/confsample.c

    r412 r513  
    476476         
    477477        txlist[0] = '\0'; 
    478         for (j=0; j<count; ++j) { 
     478        for (j=0; j<port_info->listener_cnt; ++j) { 
    479479            char s[10]; 
    480             if (port_info->listener[j]) { 
    481                 pj_ansi_sprintf(s, "#%d ", j); 
    482                 pj_ansi_strcat(txlist, s); 
    483             } 
     480            pj_ansi_sprintf(s, "#%d ", port_info->listener_slots[j]); 
     481            pj_ansi_strcat(txlist, s); 
     482 
    484483        } 
    485484 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c

    r507 r513  
    549549 
    550550    /* Build array of listeners */ 
    551     count = pjsua_var.media_cfg.max_media_ports; 
    552     for (i=0; i<count; ++i) { 
    553         if (cinfo.listener[i]) { 
    554             info->listeners[info->listener_cnt++] = i; 
    555         } 
     551    info->listener_cnt = cinfo.listener_cnt; 
     552    for (i=0; i<cinfo.listener_cnt; ++i) { 
     553        info->listeners[i] = cinfo.listener_slots[i]; 
    556554    } 
    557555 
Note: See TracChangeset for help on using the changeset viewer.