Changeset 633


Ignore:
Timestamp:
Jul 29, 2006 11:14:47 AM (18 years ago)
Author:
bennylp
Message:

Added pjmedia_port_info_init() to fill in pjmedia_port_info structure, avoiding manual initialization and thus improves consistency (and probably reduces size by a tiny bit). This involves modification in quite few places.

Location:
pjproject/trunk/pjmedia
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/include/pjmedia/conference.h

    r622 r633  
    173173 
    174174/** 
    175  * Add stream port to the conference bridge. By default, the new conference 
    176  * port will have both TX and RX enabled, but it is not connected to any 
    177  * other ports. 
    178  * 
    179  * Application SHOULD call #pjmedia_conf_connect_port() to enable audio 
    180  * transmission and receipt to/from this port. 
     175 * Add media port to the conference bridge. 
     176 * 
     177 * By default, the new conference port will have both TX and RX enabled,  
     178 * but it is not connected to any other ports. Application SHOULD call  
     179 * #pjmedia_conf_connect_port() to  enable audio transmission and receipt  
     180 * to/from this port. 
     181 * 
     182 * Once the media port is connected to other port(s) in the bridge, 
     183 * the bridge will continuosly call get_frame() and put_frame() to the 
     184 * port, allowing media to flow to/from the port. 
    181185 * 
    182186 * @param conf          The conference bridge. 
     
    198202 
    199203 
     204/** 
     205 * Create and add a passive media port to the conference bridge. Unlike 
     206 * "normal" media port that is added with #pjmedia_conf_add_port(), media 
     207 * port created with this function will not have its get_frame() and 
     208 * put_frame() called by the bridge; instead, application MUST continuosly 
     209 * call these functions to the port, to allow media to flow from/to the 
     210 * port. 
     211 * 
     212 * Upon return of this function, application will be given two objects: 
     213 * the slot number of the port in the bridge, and pointer to the media 
     214 * port where application MUST start calling get_frame() and put_frame() 
     215 * to the port. 
     216 * 
     217 * @param conf              The conference bridge. 
     218 * @param pool              Pool to allocate buffers etc for this port. 
     219 * @param name              Name to be assigned to the port. 
     220 * @param clock_rate        Clock rate/sampling rate. 
     221 * @param channel_count     Number of channels. 
     222 * @param samples_per_frame Number of samples per frame. 
     223 * @param bits_per_sample   Number of bits per sample. 
     224 * @param options           Options (should be zero at the moment). 
     225 * @param p_slot            Pointer to receive the slot index of the port in 
     226 *                          the conference bridge. 
     227 * @param p_port            Pointer to receive the port instance. 
     228 * 
     229 * @return                  PJ_SUCCESS on success, or the appropriate error  
     230 *                          code. 
     231 */ 
     232PJ_DECL(pj_status_t) pjmedia_conf_add_passive_port( pjmedia_conf *conf, 
     233                                                    pj_pool_t *pool, 
     234                                                    const pj_str_t *name, 
     235                                                    unsigned clock_rate, 
     236                                                    unsigned channel_count, 
     237                                                    unsigned samples_per_frame, 
     238                                                    unsigned bits_per_sample, 
     239                                                    unsigned options, 
     240                                                    unsigned *p_slot, 
     241                                                    pjmedia_port **p_port ); 
     242 
    200243 
    201244/** 
  • pjproject/trunk/pjmedia/include/pjmedia/port.h

    r631 r633  
    292292{ 
    293293    PJMEDIA_FRAME_TYPE_NONE,        /**< No frame.              */ 
    294     PJMEDIA_FRAME_TYPE_CNG,         /**< Silence audio frame.   */ 
    295294    PJMEDIA_FRAME_TYPE_AUDIO        /**< Normal audio frame.    */ 
    296295 
     
    333332{ 
    334333    pjmedia_port_info    info;              /**< Port information.  */ 
    335     void                *user_data;         /**< User data.         */ 
     334 
     335    /** Port data can be used by the port creator to attach arbitrary 
     336     *  value to be associated with the port. 
     337     */ 
     338    struct port_data { 
     339        void            *pdata;             /**< Pointer data.      */ 
     340        long             ldata;             /**< Long data.         */ 
     341    } port_data; 
    336342 
    337343    /** 
  • pjproject/trunk/pjmedia/src/pjmedia/conference.c

    r582 r633  
    3030#include <pj/string.h> 
    3131 
     32 
    3233/* CONF_DEBUG enables detailed operation of the conference bridge. 
    3334 * Beware that it prints large amounts of logs (several lines per frame). 
     
    5859#define BYTES_PER_SAMPLE    2 
    5960 
     61#define SIGNATURE           PJMEDIA_PORT_SIGNATURE('C', 'O', 'N', 'F') 
     62#define SIGNATURE_PORT      PJMEDIA_PORT_SIGNATURE('C', 'O', 'N', 'P') 
    6063#define NORMAL_LEVEL        128 
    6164#define SLOT_TYPE           unsigned 
     
    197200static pj_status_t get_frame(pjmedia_port *this_port,  
    198201                             pjmedia_frame *frame); 
     202static pj_status_t get_frame_pasv(pjmedia_port *this_port,  
     203                                  pjmedia_frame *frame); 
    199204static pj_status_t destroy_port(pjmedia_port *this_port); 
    200205 
     
    329334} 
    330335 
    331 /* 
    332  * Create port zero for the sound device. 
    333  */ 
    334 static pj_status_t create_sound_port( pj_pool_t *pool, 
    335                                       pjmedia_conf *conf ) 
     336 
     337/* 
     338 * Add passive port. 
     339 */ 
     340static pj_status_t create_pasv_port( pjmedia_conf *conf, 
     341                                     pj_pool_t *pool, 
     342                                     const pj_str_t *name, 
     343                                     pjmedia_port *port, 
     344                                     struct conf_port **p_conf_port) 
    336345{ 
    337346    struct conf_port *conf_port; 
    338     pj_str_t name = { "Master/sound", 12 }; 
    339347    unsigned i; 
    340348    pj_status_t status; 
    341349 
    342  
    343  
    344350    /* Create port */ 
    345     status = create_conf_port(pool, conf, NULL, &name, &conf_port); 
     351    status = create_conf_port(pool, conf, port, name, &conf_port); 
    346352    if (status != PJ_SUCCESS) 
    347         goto on_error; 
    348  
    349     /* Sound device has rx buffers. */ 
     353        return status; 
     354 
     355    /* Passive port has rx buffers. */ 
    350356    for (i=0; i<RX_BUF_COUNT; ++i) { 
    351357        conf_port->snd_buf[i] = pj_pool_zalloc(pool, conf->samples_per_frame * 
    352358                                              sizeof(conf_port->snd_buf[0][0])); 
    353359        if (conf_port->snd_buf[i] == NULL) { 
    354             status = PJ_ENOMEM; 
    355             goto on_error; 
     360            return PJ_ENOMEM; 
    356361        } 
    357362    } 
     
    359364    conf_port->snd_read_pos = 0; 
    360365 
    361  
    362      /* Set to port zero */ 
    363     conf->ports[0] = conf_port; 
    364     conf->port_cnt++; 
     366    *p_conf_port = conf_port; 
     367 
     368    return PJ_SUCCESS; 
     369} 
     370 
     371 
     372/* 
     373 * Create port zero for the sound device. 
     374 */ 
     375static pj_status_t create_sound_port( pj_pool_t *pool, 
     376                                      pjmedia_conf *conf ) 
     377{ 
     378    struct conf_port *conf_port; 
     379    pj_str_t name = { "Master/sound", 12 }; 
     380    pj_status_t status; 
     381 
     382 
     383    status = create_pasv_port(conf, pool, &name, NULL, &conf_port); 
     384    if (status != PJ_SUCCESS) 
     385        return status; 
    365386 
    366387 
     
    395416 
    396417 
     418     /* Add the port to the bridge */ 
     419    conf->ports[0] = conf_port; 
     420    conf->port_cnt++; 
     421 
     422 
    397423    PJ_LOG(5,(THIS_FILE, "Sound device successfully created for port 0")); 
    398424    return PJ_SUCCESS; 
    399  
    400 on_error: 
    401     return status; 
    402  
    403425} 
    404426 
     
    416438{ 
    417439    pjmedia_conf *conf; 
     440    const pj_str_t name = { "Conf", 4 }; 
    418441    pj_status_t status; 
    419442 
     
    443466    PJ_ASSERT_RETURN(conf->master_port, PJ_ENOMEM); 
    444467     
    445     conf->master_port->info.bits_per_sample = bits_per_sample; 
    446     conf->master_port->info.bytes_per_frame = samples_per_frame * 
    447                                               bits_per_sample / 8; 
    448     conf->master_port->info.channel_count = channel_count; 
    449     conf->master_port->info.encoding_name = pj_str("pcm"); 
    450     conf->master_port->info.has_info = 1; 
    451     conf->master_port->info.name = pj_str("sound-dev"); 
    452     conf->master_port->info.need_info = 0; 
    453     conf->master_port->info.pt = 0xFF; 
    454     conf->master_port->info.clock_rate = clock_rate; 
    455     conf->master_port->info.samples_per_frame = samples_per_frame; 
    456     conf->master_port->info.signature = 0; 
    457     conf->master_port->info.type = PJMEDIA_TYPE_AUDIO; 
     468    pjmedia_port_info_init(&conf->master_port->info, &name, SIGNATURE, 
     469                           clock_rate, channel_count, bits_per_sample, 
     470                           samples_per_frame); 
     471 
     472    conf->master_port->port_data.pdata = conf; 
     473    conf->master_port->port_data.ldata = 0; 
    458474 
    459475    conf->master_port->get_frame = &get_frame; 
    460476    conf->master_port->put_frame = &put_frame; 
    461477    conf->master_port->on_destroy = &destroy_port; 
    462  
    463     conf->master_port->user_data = conf; 
    464478 
    465479 
     
    545559static pj_status_t destroy_port(pjmedia_port *this_port) 
    546560{ 
    547     pjmedia_conf *conf = this_port->user_data; 
     561    pjmedia_conf *conf = this_port->port_data.pdata; 
    548562    return pjmedia_conf_destroy(conf); 
    549563} 
     
    630644    return PJ_SUCCESS; 
    631645} 
     646 
     647 
     648/* 
     649 * Add passive port. 
     650 */ 
     651PJ_DEF(pj_status_t) pjmedia_conf_add_passive_port( pjmedia_conf *conf, 
     652                                                   pj_pool_t *pool, 
     653                                                   const pj_str_t *name, 
     654                                                   unsigned clock_rate, 
     655                                                   unsigned channel_count, 
     656                                                   unsigned samples_per_frame, 
     657                                                   unsigned bits_per_sample, 
     658                                                   unsigned options, 
     659                                                   unsigned *p_slot, 
     660                                                   pjmedia_port **p_port ) 
     661{ 
     662    struct conf_port *conf_port; 
     663    pjmedia_port *port; 
     664    unsigned index; 
     665    pj_str_t tmp; 
     666    pj_status_t status; 
     667 
     668    PJ_ASSERT_RETURN(conf && pool, PJ_EINVAL); 
     669 
     670    /* For this version of PJMEDIA, port MUST have the same number of 
     671     * PCM channels. 
     672     */ 
     673    if (channel_count != conf->channel_count) { 
     674        pj_assert(!"Number of channels mismatch"); 
     675        return PJMEDIA_ENCCHANNEL; 
     676    } 
     677 
     678    /* For this version, options must be zero */ 
     679    PJ_ASSERT_RETURN(options == 0, PJ_EINVAL); 
     680    PJ_UNUSED_ARG(options); 
     681 
     682    pj_mutex_lock(conf->mutex); 
     683 
     684    if (conf->port_cnt >= conf->max_ports) { 
     685        pj_assert(!"Too many ports"); 
     686        pj_mutex_unlock(conf->mutex); 
     687        return PJ_ETOOMANY; 
     688    } 
     689 
     690    /* Find empty port in the conference bridge. */ 
     691    for (index=0; index < conf->max_ports; ++index) { 
     692        if (conf->ports[index] == NULL) 
     693            break; 
     694    } 
     695 
     696    pj_assert(index != conf->max_ports); 
     697 
     698    if (name == NULL) { 
     699        name = &tmp; 
     700 
     701        tmp.ptr = pj_pool_alloc(pool, 20); 
     702        tmp.slen = pj_ansi_sprintf(tmp.ptr, "ConfPort#%d", index); 
     703    } 
     704 
     705    /* Create and initialize the media port structure. */ 
     706    port = pj_pool_zalloc(pool, sizeof(pjmedia_port)); 
     707    PJ_ASSERT_RETURN(port, PJ_ENOMEM); 
     708     
     709    pjmedia_port_info_init(&port->info, name, SIGNATURE_PORT, 
     710                           clock_rate, channel_count, bits_per_sample, 
     711                           samples_per_frame); 
     712 
     713    port->port_data.pdata = conf; 
     714    port->port_data.ldata = index; 
     715 
     716    port->get_frame = &get_frame_pasv; 
     717    port->put_frame = &put_frame; 
     718    port->on_destroy = NULL; 
     719 
     720     
     721    /* Create conf port structure. */ 
     722    status = create_pasv_port(conf, pool, name, port, &conf_port); 
     723    if (status != PJ_SUCCESS) { 
     724        pj_mutex_unlock(conf->mutex); 
     725        return status; 
     726    } 
     727 
     728 
     729    /* Put the port. */ 
     730    conf->ports[index] = conf_port; 
     731    conf->port_cnt++; 
     732 
     733    /* Done. */ 
     734    if (p_slot) 
     735        *p_slot = index; 
     736    if (p_port) 
     737        *p_port = port; 
     738 
     739    pj_mutex_unlock(conf->mutex); 
     740 
     741    return PJ_SUCCESS; 
     742} 
     743 
    632744 
    633745 
     
    13631475                             pjmedia_frame *frame) 
    13641476{ 
    1365     pjmedia_conf *conf = this_port->user_data; 
     1477    pjmedia_conf *conf = this_port->port_data.pdata; 
    13661478    unsigned ci, cj, i, j; 
    13671479     
     
    14191531 
    14201532        /* Get frame from this port.  
    1421          * For port zero (sound port), get the frame  from the rx_buffer 
    1422          * instead. 
     1533         * For port zero (sound port) and passive ports, get the frame  from  
     1534         * the rx_buffer instead. 
    14231535         */ 
    1424         if (i==0) { 
     1536        if (conf_port->port == NULL) { 
    14251537            pj_int16_t *snd_buf; 
    14261538 
     
    16161728 
    16171729/* 
     1730 * get_frame() for passive port 
     1731 */ 
     1732static pj_status_t get_frame_pasv(pjmedia_port *this_port,  
     1733                                  pjmedia_frame *frame) 
     1734{ 
     1735    pj_assert(0); 
     1736    return -1; 
     1737} 
     1738 
     1739 
     1740/* 
    16181741 * Recorder callback. 
    16191742 */ 
     
    16211744                             const pjmedia_frame *frame) 
    16221745{ 
    1623     pjmedia_conf *conf = this_port->user_data; 
    1624     struct conf_port *snd_port = conf->ports[0]; 
     1746    pjmedia_conf *conf = this_port->port_data.pdata; 
     1747    struct conf_port *port = conf->ports[this_port->port_data.ldata]; 
    16251748    const pj_int16_t *input = frame->buf; 
    16261749    pj_int16_t *target_snd_buf; 
     
    16321755 
    16331756    /* Skip if this port is muted/disabled. */ 
    1634     if (snd_port->rx_setting != PJMEDIA_PORT_ENABLE) { 
     1757    if (port->rx_setting != PJMEDIA_PORT_ENABLE) { 
    16351758        return PJ_SUCCESS; 
    16361759    } 
    16371760 
    16381761    /* Skip if no port is listening to the microphone */ 
    1639     if (snd_port->listener_cnt == 0) { 
     1762    if (port->listener_cnt == 0) { 
    16401763        return PJ_SUCCESS; 
    16411764    } 
     
    16431766 
    16441767    /* Determine which rx_buffer to fill in */ 
    1645     target_snd_buf = snd_port->snd_buf[snd_port->snd_write_pos]; 
     1768    target_snd_buf = port->snd_buf[port->snd_write_pos]; 
    16461769     
    16471770    /* Copy samples from audio device to target rx_buffer */ 
     
    16491772 
    16501773    /* Switch buffer */ 
    1651     snd_port->snd_write_pos = (snd_port->snd_write_pos+1)%RX_BUF_COUNT; 
    1652  
    1653  
    1654     return PJ_SUCCESS; 
    1655 } 
    1656  
     1774    port->snd_write_pos = (port->snd_write_pos+1)%RX_BUF_COUNT; 
     1775 
     1776 
     1777    return PJ_SUCCESS; 
     1778} 
     1779 
  • pjproject/trunk/pjmedia/src/pjmedia/mem_capture.c

    r532 r633  
    5858{ 
    5959    struct mem_rec *rec; 
     60    const pj_str_t name = { "memrec", 6 }; 
    6061 
    6162    /* Sanity check */ 
     
    7273 
    7374    /* Create the rec */ 
    74     rec->base.info.name = pj_str("memrec"); 
    75     rec->base.info.signature = SIGNATURE; 
    76     rec->base.info.type = PJMEDIA_TYPE_AUDIO; 
    77     rec->base.info.has_info = PJ_TRUE; 
    78     rec->base.info.need_info = PJ_FALSE; 
    79     rec->base.info.pt = 0xFF; 
    80     rec->base.info.encoding_name = pj_str("pcm"); 
     75    pjmedia_port_info_init(&rec->base.info, &name, SIGNATURE, 
     76                           clock_rate, channel_count, bits_per_sample,  
     77                           samples_per_frame); 
     78 
    8179 
    8280    rec->base.put_frame = &rec_put_frame; 
     
    8482    rec->base.on_destroy = &rec_on_destroy; 
    8583 
    86     rec->base.info.clock_rate = clock_rate; 
    87     rec->base.info.channel_count = channel_count; 
    88     rec->base.info.bits_per_sample = bits_per_sample; 
    89     rec->base.info.samples_per_frame = samples_per_frame; 
    90     rec->base.info.bytes_per_frame = samples_per_frame * bits_per_sample / 2; 
    9184 
    9285    /* Save the buffer */ 
  • pjproject/trunk/pjmedia/src/pjmedia/mem_player.c

    r532 r633  
    5959{ 
    6060    struct mem_player *port; 
     61    pj_str_t name = pj_str("memplayer"); 
    6162 
    6263    /* Sanity check */ 
     
    7374 
    7475    /* Create the port */ 
    75     port->base.info.name = pj_str("memplayer"); 
    76     port->base.info.signature = SIGNATURE; 
    77     port->base.info.type = PJMEDIA_TYPE_AUDIO; 
    78     port->base.info.has_info = PJ_TRUE; 
    79     port->base.info.need_info = PJ_FALSE; 
    80     port->base.info.pt = 0xFF; 
    81     port->base.info.encoding_name = pj_str("pcm"); 
     76    pjmedia_port_info_init(&port->base.info, &name, SIGNATURE, clock_rate, 
     77                           channel_count, bits_per_sample, samples_per_frame); 
    8278 
    8379    port->base.put_frame = &mem_put_frame; 
     
    8581    port->base.on_destroy = &mem_on_destroy; 
    8682 
    87     port->base.info.clock_rate = clock_rate; 
    88     port->base.info.channel_count = channel_count; 
    89     port->base.info.bits_per_sample = bits_per_sample; 
    90     port->base.info.samples_per_frame = samples_per_frame; 
    91     port->base.info.bytes_per_frame = samples_per_frame * bits_per_sample / 2; 
    9283 
    9384    /* Save the buffer */ 
  • pjproject/trunk/pjmedia/src/pjmedia/null_port.c

    r506 r633  
    2424 
    2525 
     26#define SIGNATURE   PJMEDIA_PORT_SIGNATURE('N', 'U', 'L', 'L') 
     27 
    2628static pj_status_t null_get_frame(pjmedia_port *this_port,  
    2729                                  pjmedia_frame *frame); 
     
    3941{ 
    4042    pjmedia_port *port; 
     43    const pj_str_t name = pj_str("null-port"); 
    4144 
    4245    PJ_ASSERT_RETURN(pool && p_port, PJ_EINVAL); 
     
    4548    PJ_ASSERT_RETURN(pool != NULL, PJ_ENOMEM); 
    4649 
    47     port->info.bits_per_sample = bits_per_sample; 
    48     port->info.bytes_per_frame = samples_per_frame * bits_per_sample / 8; 
    49     port->info.encoding_name = pj_str("pcm"); 
    50     port->info.has_info = 1; 
    51     port->info.name = pj_str("null-port"); 
    52     port->info.need_info = 0; 
    53     port->info.pt = 0xFF; 
    54     port->info.clock_rate = sampling_rate; 
    55     port->info.samples_per_frame = samples_per_frame; 
    56     port->info.channel_count = channel_count; 
    57     port->info.signature = 0x2411; 
    58     port->info.type = PJMEDIA_TYPE_AUDIO; 
     50    pjmedia_port_info_init(&port->info, &name, SIGNATURE, sampling_rate, 
     51                           channel_count, bits_per_sample, samples_per_frame); 
    5952 
    6053    port->get_frame = &null_get_frame; 
  • pjproject/trunk/pjmedia/src/pjmedia/resample_port.c

    r582 r633  
    2525 
    2626#define BYTES_PER_SAMPLE        2 
     27#define SIGNATURE               PJMEDIA_PORT_SIGNATURE('R','S','M','P') 
     28 
    2729 
    2830struct resample_port 
     
    5355                                                  pjmedia_port **p_port  ) 
    5456{ 
     57    const pj_str_t name = pj_str("resample"); 
    5558    struct resample_port *rport; 
    5659    unsigned ptime; 
     
    7073    PJ_ASSERT_RETURN(rport != NULL, PJ_ENOMEM); 
    7174 
    72     rport->base.info.clock_rate = clock_rate; 
    73     rport->base.info.samples_per_frame = clock_rate * ptime / 1000; 
    74     rport->base.info.bytes_per_frame = rport->base.info.samples_per_frame * 
    75                                        BYTES_PER_SAMPLE; 
    76     rport->base.info.bits_per_sample = BYTES_PER_SAMPLE * 8; 
    77     rport->base.info.channel_count = dn_port->info.channel_count; 
    78     rport->base.info.encoding_name = pj_str("pcm"); 
    79     rport->base.info.has_info = 1; 
    80     rport->base.info.name = pj_str("resample"); 
    81     rport->base.info.need_info = 0; 
    82     rport->base.info.pt = 0xFF; 
    83     rport->base.info.signature = PJMEDIA_PORT_SIGNATURE('R','S','M','P'); 
    84     rport->base.info.type = PJMEDIA_TYPE_AUDIO; 
     75    pjmedia_port_info_init(&rport->base.info, &name, SIGNATURE, clock_rate, 
     76                           dn_port->info.channel_count, BYTES_PER_SAMPLE * 8,  
     77                           clock_rate * ptime / 1000); 
    8578 
    8679    rport->dn_port = dn_port; 
  • pjproject/trunk/pjmedia/src/pjmedia/splitcomb.c

    r631 r633  
    2525 
    2626#define SIGNATURE           PJMEDIA_PORT_SIGNATURE('S', 'p', 'C', 'b') 
     27#define SIGNATURE_PORT      PJMEDIA_PORT_SIGNATURE('S', 'p', 'C', 'P') 
    2728#define THIS_FILE           "splitcomb.c" 
    2829#define TMP_SAMP_TYPE       pj_int16_t 
     
    129130                                              pjmedia_port **p_splitcomb) 
    130131{ 
     132    const pj_str_t name = pj_str("splitcomb"); 
    131133    struct splitcomb *sc; 
    132134 
     
    161163 
    162164    /* Initialize port */ 
    163     sc->base.info.name = pj_str("splitcomb"); 
    164     sc->base.info.signature = SIGNATURE; 
    165     sc->base.info.type = PJMEDIA_TYPE_AUDIO; 
    166     sc->base.info.has_info = PJ_TRUE; 
    167     sc->base.info.need_info = PJ_FALSE; 
    168     sc->base.info.pt = 0xFF; 
    169     sc->base.info.encoding_name = pj_str("pcm"); 
    170     sc->base.info.clock_rate = clock_rate; 
    171     sc->base.info.channel_count = channel_count; 
    172     sc->base.info.bits_per_sample = bits_per_sample; 
    173     sc->base.info.samples_per_frame = samples_per_frame; 
    174     sc->base.info.bytes_per_frame = samples_per_frame * bits_per_sample / 8; 
     165    pjmedia_port_info_init(&sc->base.info, &name, SIGNATURE, clock_rate, 
     166                           channel_count, bits_per_sample, samples_per_frame); 
    175167 
    176168    sc->base.put_frame = &put_frame; 
     
    227219                                      pjmedia_port **p_chport) 
    228220{ 
     221    const pj_str_t name = pj_str("splitcomb-ch"); 
    229222    struct splitcomb *sc = (struct splitcomb*) splitcomb; 
    230223    struct reverse_port *rport; 
     
    251244    /* Initialize port info... */ 
    252245    port = &rport->base; 
    253     port->info.name = pj_str("splitcomb-ch"); 
    254     port->info.signature = 0; 
    255     port->info.type = PJMEDIA_TYPE_AUDIO; 
    256     port->info.has_info = PJ_TRUE; 
    257     port->info.need_info = PJ_FALSE; 
    258     port->info.pt = 0xFF; 
    259     port->info.encoding_name = pj_str("pcm"); 
    260     port->info.clock_rate = splitcomb->info.clock_rate; 
    261     port->info.channel_count = 1; 
    262     port->info.bits_per_sample = splitcomb->info.bits_per_sample; 
    263     port->info.samples_per_frame = splitcomb->info.samples_per_frame / 
    264                                    splitcomb->info.channel_count; 
    265     port->info.bytes_per_frame = port->info.samples_per_frame *  
    266                                  port->info.bits_per_sample / 8; 
     246    pjmedia_port_info_init(&port->info, &name, SIGNATURE_PORT,  
     247                           splitcomb->info.clock_rate, 1,  
     248                           splitcomb->info.bits_per_sample,  
     249                           splitcomb->info.samples_per_frame /  
     250                                   splitcomb->info.channel_count); 
    267251 
    268252    /* ... and the callbacks */ 
  • pjproject/trunk/pjmedia/src/pjmedia/stream.c

    r569 r633  
    144144static pj_status_t get_frame( pjmedia_port *port, pjmedia_frame *frame) 
    145145{ 
    146     pjmedia_stream *stream = port->user_data; 
     146    pjmedia_stream *stream = port->port_data.pdata; 
    147147    pjmedia_channel *channel = stream->dec; 
    148148    unsigned samples_count, samples_per_frame, samples_required; 
     
    439439                              const pjmedia_frame *frame ) 
    440440{ 
    441     pjmedia_stream *stream = port->user_data; 
     441    pjmedia_stream *stream = port->port_data.pdata; 
    442442    pjmedia_channel *channel = stream->enc; 
    443443    pj_status_t status = 0; 
     
    914914{ 
    915915    pjmedia_stream *stream; 
     916    pj_str_t name; 
    916917    unsigned jb_init, jb_max, jb_min_pre, jb_max_pre; 
    917918    pj_status_t status; 
     
    926927 
    927928    /* Init stream/port name */ 
    928     stream->port.info.name.ptr = pj_pool_alloc(pool, 24); 
    929     pj_ansi_sprintf(stream->port.info.name.ptr, 
    930                     "strm%p", stream); 
    931     stream->port.info.name.slen = pj_ansi_strlen(stream->port.info.name.ptr); 
     929    name.ptr = pj_pool_alloc(pool, 24); 
     930    name.slen = pj_ansi_snprintf(name.ptr, 24, "strm%p", stream); 
     931 
     932 
     933    /* Init some port-info. Some parts of the info will be set later 
     934     * once we have more info about the codec. 
     935     */ 
     936    pjmedia_port_info_init(&stream->port.info, &name, 
     937                           PJMEDIA_PORT_SIGNATURE('S', 'T', 'R', 'M'), 
     938                           info->fmt.clock_rate, info->fmt.channel_cnt, 
     939                           16, 80); 
    932940 
    933941    /* Init port. */ 
    934     stream->port.info.signature = ('S'<<3 | 'T'<<2 | 'R'<<1 | 'M'); 
    935     stream->port.info.type = PJMEDIA_TYPE_AUDIO; 
    936     stream->port.info.has_info = 1; 
    937     stream->port.info.need_info = 0; 
    938     stream->port.info.pt = info->fmt.pt; 
     942 
    939943    pj_strdup(pool, &stream->port.info.encoding_name, &info->fmt.encoding_name); 
    940944    stream->port.info.clock_rate = info->fmt.clock_rate; 
    941945    stream->port.info.channel_count = info->fmt.channel_cnt; 
    942     stream->port.user_data = stream; 
     946    stream->port.port_data.pdata = stream; 
    943947    stream->port.put_frame = &put_frame; 
    944948    stream->port.get_frame = &get_frame; 
  • pjproject/trunk/pjmedia/src/pjmedia/wav_player.c

    r582 r633  
    7878static struct file_port *create_file_port(pj_pool_t *pool) 
    7979{ 
     80    const pj_str_t name = pj_str("file"); 
    8081    struct file_port *port; 
    8182 
     
    8485        return NULL; 
    8586 
    86     port->base.info.name = pj_str("file"); 
    87     port->base.info.signature = SIGNATURE; 
    88     port->base.info.type = PJMEDIA_TYPE_AUDIO; 
    89     port->base.info.has_info = PJ_TRUE; 
    90     port->base.info.need_info = PJ_FALSE; 
    91     port->base.info.pt = 0xFF; 
    92     port->base.info.encoding_name = pj_str("pcm"); 
     87    /* Put in default values. 
     88     * These will be overriden once the file is read. 
     89     */ 
     90    pjmedia_port_info_init(&port->base.info, &name, SIGNATURE,  
     91                           8000, 1, 16, 80); 
    9392 
    9493    port->base.put_frame = &file_put_frame; 
     
    9695    port->base.on_destroy = &file_on_destroy; 
    9796 
    98  
    99     /* Put in default values. 
    100      * These will be overriden once the file is read. 
    101      */ 
    102     port->base.info.clock_rate = 8000; 
    103     port->base.info.bits_per_sample = 16; 
    104     port->base.info.samples_per_frame = 160; 
    105     port->base.info.bytes_per_frame = 320; 
    10697 
    10798    return port; 
     
    151142 
    152143                fport->eof = PJ_TRUE; 
    153                 status = (*fport->cb)(&fport->base, fport->base.user_data); 
     144                status=(*fport->cb)(&fport->base,fport->base.port_data.pdata); 
    154145                if (status != PJ_SUCCESS) { 
    155146                    /* This will crash if file port is destroyed in the  
     
    425416    fport = (struct file_port*) port; 
    426417 
    427     fport->base.user_data = user_data; 
     418    fport->base.port_data.pdata = user_data; 
    428419    fport->cb = cb; 
    429420 
  • pjproject/trunk/pjmedia/src/pjmedia/wav_writer.c

    r582 r633  
    7070    pjmedia_wave_hdr wave_hdr; 
    7171    pj_ssize_t size; 
     72    pj_str_t name; 
    7273    pj_status_t status; 
    7374 
     
    8788 
    8889    /* Initialize port info. */ 
    89     fport->base.info.bits_per_sample = bits_per_sample; 
    90     fport->base.info.bytes_per_frame = samples_per_frame * bits_per_sample * 
    91                                        channel_count / 8; 
    92     fport->base.info.channel_count = channel_count; 
    93     fport->base.info.encoding_name = pj_str("pom"); 
    94     fport->base.info.has_info = 1; 
    95     pj_strdup2(pool, &fport->base.info.name, filename); 
    96     fport->base.info.need_info = 0; 
    97     fport->base.info.pt = 0xFF; 
    98     fport->base.info.clock_rate = sampling_rate; 
    99     fport->base.info.samples_per_frame = samples_per_frame; 
    100     fport->base.info.signature = SIGNATURE; 
    101     fport->base.info.type = PJMEDIA_TYPE_AUDIO; 
    102      
     90    pj_strdup2(pool, &name, filename); 
     91    pjmedia_port_info_init(&fport->base.info, &name, SIGNATURE, 
     92                           sampling_rate, channel_count, bits_per_sample, 
     93                           samples_per_frame); 
     94 
    10395    fport->base.get_frame = &file_get_frame; 
    10496    fport->base.put_frame = &file_put_frame; 
     
    221213 
    222214    fport->cb_size = pos; 
    223     fport->base.user_data = user_data; 
     215    fport->base.port_data.pdata = user_data; 
    224216    fport->cb = cb; 
    225217 
     
    294286        fport->cb = NULL; 
    295287 
    296         status = (*cb)(this_port, this_port->user_data); 
     288        status = (*cb)(this_port, this_port->port_data.pdata); 
    297289        return status; 
    298290    } 
Note: See TracChangeset for help on using the changeset viewer.