Ignore:
Timestamp:
Mar 14, 2014 4:09:50 AM (11 years ago)
Author:
bennylp
Message:

Closed #1748: enhancements to WAV player API

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsua2/media.cpp

    r4776 r4793  
    263263                                           &playerId) ); 
    264264 
     265    /* Register EOF callback */ 
     266    pjmedia_port *port; 
     267    pj_status_t status; 
     268 
     269    status = pjsua_player_get_port(playerId, &port); 
     270    if (status != PJ_SUCCESS) { 
     271        pjsua_player_destroy(playerId); 
     272        PJSUA2_RAISE_ERROR2(status, "AudioMediaPlayer::createPlayer()"); 
     273    } 
     274    status = pjmedia_wav_player_set_eof_cb(port, this, &eof_cb); 
     275    if (status != PJ_SUCCESS) { 
     276        pjsua_player_destroy(playerId); 
     277        PJSUA2_RAISE_ERROR2(status, "AudioMediaPlayer::createPlayer()"); 
     278    } 
     279 
    265280    /* Get media port id. */ 
    266281    id = pjsua_player_get_conf_port(playerId); 
     
    281296    unsigned i, count = 0; 
    282297    pj_str_t pj_lbl = str2Pj(label); 
     298    pj_status_t status; 
    283299 
    284300    count = PJ_ARRAY_SIZE(pj_files); 
     
    297313                                             &playerId) ); 
    298314 
     315    /* Register EOF callback */ 
     316    pjmedia_port *port; 
     317    status = pjsua_player_get_port(playerId, &port); 
     318    if (status != PJ_SUCCESS) { 
     319        pjsua_player_destroy(playerId); 
     320        PJSUA2_RAISE_ERROR2(status, "AudioMediaPlayer::createPlaylist()"); 
     321    } 
     322    status = pjmedia_wav_playlist_set_eof_cb(port, this, &eof_cb); 
     323    if (status != PJ_SUCCESS) { 
     324        pjsua_player_destroy(playerId); 
     325        PJSUA2_RAISE_ERROR2(status, "AudioMediaPlayer::createPlaylist()"); 
     326    } 
     327 
    299328    /* Get media port id. */ 
    300329    id = pjsua_player_get_conf_port(playerId); 
     
    303332} 
    304333 
     334AudioMediaPlayerInfo AudioMediaPlayer::getInfo() const throw(Error) 
     335{ 
     336    AudioMediaPlayerInfo info; 
     337    pjmedia_wav_player_info pj_info; 
     338 
     339    PJSUA2_CHECK_EXPR( pjsua_player_get_info(playerId, &pj_info) ); 
     340 
     341    pj_bzero(&info, sizeof(info)); 
     342    info.formatId               = pj_info.fmt_id; 
     343    info.payloadBitsPerSample   = pj_info.payload_bits_per_sample; 
     344    info.sizeBytes              = pj_info.size_bytes; 
     345    info.sizeSamples            = pj_info.size_samples; 
     346 
     347    return info; 
     348} 
     349 
     350pj_uint32_t AudioMediaPlayer::getPos() const throw(Error) 
     351{ 
     352    pj_ssize_t pos = pjsua_player_get_pos(playerId); 
     353    if (pos < 0) { 
     354        PJSUA2_RAISE_ERROR2(-pos, "AudioMediaPlayer::getPos()"); 
     355    } 
     356    return (pj_uint32_t)pos; 
     357} 
     358 
    305359void AudioMediaPlayer::setPos(pj_uint32_t samples) throw(Error) 
    306360{ 
     
    312366{ 
    313367    return static_cast<AudioMediaPlayer*>(media); 
     368} 
     369 
     370pj_status_t AudioMediaPlayer::eof_cb(pjmedia_port *port, 
     371                                     void *usr_data) 
     372{ 
     373    AudioMediaPlayer *player = (AudioMediaPlayer*)usr_data; 
     374    return player->onEof() ? PJ_SUCCESS : PJ_EEOF; 
    314375} 
    315376 
Note: See TracChangeset for help on using the changeset viewer.