Ignore:
Timestamp:
Mar 23, 2006 1:15:59 PM (18 years ago)
Author:
bennylp
Message:

Changed sound device framework to allow opening bidirectional streams from one device

File:
1 edited

Legend:

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

    r321 r352  
    2424struct pjmedia_snd_port 
    2525{ 
    26     int                  snd_index; 
     26    int                  rec_id; 
     27    int                  play_id; 
    2728    pjmedia_snd_stream  *snd_stream; 
    2829    pjmedia_dir          dir; 
     
    124125 
    125126    /* Open sound stream. */ 
    126     if (snd_port->dir == PJMEDIA_DIR_ENCODING) { 
    127         status = pjmedia_snd_open_recorder( snd_port->snd_index,  
    128                                             snd_port->clock_rate, 
    129                                             snd_port->channel_count, 
    130                                             snd_port->samples_per_frame, 
    131                                             snd_port->bits_per_sample, 
    132                                             &rec_cb, 
    133                                             snd_port, 
    134                                             &snd_port->snd_stream); 
    135     } else { 
    136         status = pjmedia_snd_open_player( snd_port->snd_index,  
     127    if (snd_port->dir == PJMEDIA_DIR_CAPTURE) { 
     128        status = pjmedia_snd_open_rec( snd_port->rec_id,  
     129                                       snd_port->clock_rate, 
     130                                       snd_port->channel_count, 
     131                                       snd_port->samples_per_frame, 
     132                                       snd_port->bits_per_sample, 
     133                                       &rec_cb, 
     134                                       snd_port, 
     135                                       &snd_port->snd_stream); 
     136 
     137    } else if (snd_port->dir == PJMEDIA_DIR_PLAYBACK) { 
     138        status = pjmedia_snd_open_player( snd_port->play_id,  
    137139                                          snd_port->clock_rate, 
    138140                                          snd_port->channel_count, 
     
    142144                                          snd_port, 
    143145                                          &snd_port->snd_stream); 
     146 
     147    } else if (snd_port->dir == PJMEDIA_DIR_CAPTURE_PLAYBACK) { 
     148        status = pjmedia_snd_open( snd_port->rec_id,  
     149                                   snd_port->play_id, 
     150                                   snd_port->clock_rate, 
     151                                   snd_port->channel_count, 
     152                                   snd_port->samples_per_frame, 
     153                                   snd_port->bits_per_sample, 
     154                                   &rec_cb, 
     155                                   &play_cb, 
     156                                   snd_port, 
     157                                   &snd_port->snd_stream); 
     158    } else { 
     159        pj_assert(!"Invalid dir"); 
     160        status = PJ_EBUG; 
    144161    } 
    145162 
     
    177194 
    178195/* 
     196 * Create bidirectional port. 
     197 */ 
     198PJ_DEF(pj_status_t) pjmedia_snd_port_create( pj_pool_t *pool, 
     199                                             int rec_id, 
     200                                             int play_id, 
     201                                             unsigned clock_rate, 
     202                                             unsigned channel_count, 
     203                                             unsigned samples_per_frame, 
     204                                             unsigned bits_per_sample, 
     205                                             unsigned options, 
     206                                             pjmedia_snd_port **p_port) 
     207{ 
     208    pjmedia_snd_port *snd_port; 
     209 
     210    PJ_ASSERT_RETURN(pool && p_port, PJ_EINVAL); 
     211    PJ_ASSERT_RETURN(options == 0, PJ_EINVAL); 
     212 
     213    snd_port = pj_pool_zalloc(pool, sizeof(pjmedia_snd_port)); 
     214    PJ_ASSERT_RETURN(snd_port, PJ_ENOMEM); 
     215 
     216    snd_port->rec_id = rec_id; 
     217    snd_port->play_id = play_id; 
     218    snd_port->dir = PJMEDIA_DIR_CAPTURE_PLAYBACK; 
     219    snd_port->clock_rate = clock_rate; 
     220    snd_port->channel_count = channel_count; 
     221    snd_port->samples_per_frame = samples_per_frame; 
     222    snd_port->bits_per_sample = bits_per_sample; 
     223 
     224    *p_port = snd_port; 
     225 
     226    /* Start sound device immediately. 
     227     * If there's no port connected, the sound callback will return 
     228     * empty signal. 
     229     */ 
     230    return start_sound_device( snd_port ); 
     231 
     232} 
     233 
     234/* 
    179235 * Create sound recorder port. 
    180236 */ 
    181237PJ_DEF(pj_status_t) pjmedia_snd_port_create_rec( pj_pool_t *pool, 
    182                                                  int index, 
     238                                                 int dev_id, 
    183239                                                 unsigned clock_rate, 
    184240                                                 unsigned channel_count, 
     
    196252    PJ_ASSERT_RETURN(snd_port, PJ_ENOMEM); 
    197253 
    198     snd_port->snd_index = index; 
    199     snd_port->dir = PJMEDIA_DIR_ENCODING; 
     254    snd_port->rec_id = dev_id; 
     255    snd_port->dir = PJMEDIA_DIR_CAPTURE; 
    200256    snd_port->clock_rate = clock_rate; 
    201257    snd_port->channel_count = channel_count; 
     
    217273 */ 
    218274PJ_DEF(pj_status_t) pjmedia_snd_port_create_player( pj_pool_t *pool, 
    219                                                     int index, 
     275                                                    int dev_id, 
    220276                                                    unsigned clock_rate, 
    221277                                                    unsigned channel_count, 
     
    233289    PJ_ASSERT_RETURN(snd_port, PJ_ENOMEM); 
    234290 
    235     snd_port->snd_index = index; 
    236     snd_port->dir = PJMEDIA_DIR_DECODING; 
     291    snd_port->play_id = dev_id; 
     292    snd_port->dir = PJMEDIA_DIR_PLAYBACK; 
    237293    snd_port->clock_rate = clock_rate; 
    238294    snd_port->channel_count = channel_count; 
     
    262318 
    263319/* 
     320 * Retrieve the sound stream associated by this sound device port. 
     321 */ 
     322PJ_DEF(pjmedia_snd_stream*) pjmedia_snd_port_get_snd_stream( 
     323                                                pjmedia_snd_port *snd_port) 
     324{ 
     325    PJ_ASSERT_RETURN(snd_port, NULL); 
     326    return snd_port->snd_stream; 
     327} 
     328 
     329 
     330/* 
    264331 * Connect a port. 
    265332 */ 
Note: See TracChangeset for help on using the changeset viewer.