Changeset 4982


Ignore:
Timestamp:
Feb 11, 2015 5:15:29 AM (10 years ago)
Author:
nanang
Message:

Close #1814: Add audio frame preview callbacks.

Location:
pjproject/trunk
Files:
4 edited

Legend:

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

    r4082 r4982  
    9696     */ 
    9797    unsigned ec_options; 
     98 
     99    /** 
     100     * Arbitrary user data for playback and record preview callbacks below. 
     101     */ 
     102    void *user_data; 
     103 
     104    /** 
     105     * Optional callback for audio frame preview right before queued to 
     106     * the speaker. 
     107     * Notes: 
     108     * - application MUST NOT block or perform long operation in the callback 
     109     *   as the callback may be executed in sound device thread 
     110     * - when using software echo cancellation, application MUST NOT modify 
     111     *   the audio data from within the callback, otherwise the echo canceller 
     112     *   will not work properly. 
     113     * - the return value of the callback will be ignored 
     114     */ 
     115    pjmedia_aud_play_cb on_play_frame; 
     116 
     117    /** 
     118     * Optional callback for audio frame preview recorded from the microphone 
     119     * before being processed by any media component such as software echo 
     120     * canceller. 
     121     * Notes: 
     122     * - application MUST NOT block or perform long operation in the callback 
     123     *   as the callback may be executed in sound device thread 
     124     * - when using software echo cancellation, application MUST NOT modify 
     125     *   the audio data from within the callback, otherwise the echo canceller 
     126     *   will not work properly. 
     127     * - the return value of the callback will be ignored 
     128     */ 
     129    pjmedia_aud_rec_cb on_rec_frame; 
    98130 
    99131} pjmedia_snd_port_param; 
  • pjproject/trunk/pjmedia/src/pjmedia/sound_port.c

    r4537 r4982  
    6262    unsigned             ec_suspend_count; 
    6363    unsigned             ec_suspend_limit; 
     64 
     65    /* audio frame preview callbacks */ 
     66    void                *user_data; 
     67    pjmedia_aud_play_cb  on_play_frame; 
     68    pjmedia_aud_rec_cb   on_rec_frame; 
    6469}; 
    6570 
     
    101106    } 
    102107 
     108    /* Invoke preview callback */ 
     109    if (snd_port->on_play_frame) 
     110        (*snd_port->on_play_frame)(snd_port->user_data, frame); 
    103111 
    104112    return PJ_SUCCESS; 
     
    121129    } 
    122130 
     131    /* Invoke preview callback */ 
     132    if (snd_port->on_play_frame) 
     133        (*snd_port->on_play_frame)(snd_port->user_data, frame); 
     134 
    123135    return PJ_SUCCESS; 
    124136} 
     
    135147 
    136148    pjmedia_clock_src_update(&snd_port->cap_clocksrc, &frame->timestamp); 
     149 
     150    /* Invoke preview callback */ 
     151    if (snd_port->on_rec_frame) 
     152        (*snd_port->on_rec_frame)(snd_port->user_data, frame); 
    137153 
    138154    port = snd_port->port; 
     
    167183    pjmedia_port_get_frame(port, frame); 
    168184 
     185    /* Invoke preview callback */ 
     186    if (snd_port->on_play_frame) 
     187        (*snd_port->on_play_frame)(snd_port->user_data, frame); 
     188 
    169189    return PJ_SUCCESS; 
    170190} 
     
    179199    pjmedia_snd_port *snd_port = (pjmedia_snd_port*) user_data; 
    180200    pjmedia_port *port; 
     201 
     202    /* Invoke preview callback */ 
     203    if (snd_port->on_rec_frame) 
     204        (*snd_port->on_rec_frame)(snd_port->user_data, frame); 
    181205 
    182206    port = snd_port->port; 
     
    465489    snd_port->options = prm->options; 
    466490    snd_port->prm_ec_options = prm->ec_options; 
     491    snd_port->user_data = prm->user_data; 
     492    snd_port->on_play_frame = prm->on_play_frame; 
     493    snd_port->on_rec_frame = prm->on_rec_frame; 
    467494 
    468495    ptime_usec = prm->base.samples_per_frame * 1000 / prm->base.channel_count / 
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h

    r4957 r4982  
    58125812     */ 
    58135813    pj_bool_t no_rtcp_sdes_bye; 
     5814 
     5815    /** 
     5816     * Optional callback for audio frame preview right before queued to 
     5817     * the speaker. 
     5818     * Notes: 
     5819     * - application MUST NOT block or perform long operation in the callback 
     5820     *   as the callback may be executed in sound device thread 
     5821     * - when using software echo cancellation, application MUST NOT modify 
     5822     *   the audio data from within the callback, otherwise the echo canceller 
     5823     *   will not work properly. 
     5824     */ 
     5825    void (*on_aud_prev_play_frame)(pjmedia_frame *frame); 
     5826 
     5827    /** 
     5828     * Optional callback for audio frame preview recorded from the microphone 
     5829     * before being processed by any media component such as software echo 
     5830     * canceller. 
     5831     * Notes: 
     5832     * - application MUST NOT block or perform long operation in the callback 
     5833     *   as the callback may be executed in sound device thread 
     5834     * - when using software echo cancellation, application MUST NOT modify 
     5835     *   the audio data from within the callback, otherwise the echo canceller 
     5836     *   will not work properly. 
     5837     */ 
     5838    void (*on_aud_prev_rec_frame)(pjmedia_frame *frame); 
    58145839}; 
    58155840 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_aud.c

    r4857 r4982  
    16781678} 
    16791679 
     1680static pj_status_t on_aud_prev_play_frame(void *user_data, pjmedia_frame *frame) 
     1681{ 
     1682    PJ_UNUSED_ARG(user_data); 
     1683    (*pjsua_var.media_cfg.on_aud_prev_play_frame)(frame); 
     1684    return PJ_SUCCESS; 
     1685} 
     1686 
     1687static pj_status_t on_aud_prev_rec_frame(void *user_data, pjmedia_frame *frame) 
     1688{ 
     1689    PJ_UNUSED_ARG(user_data); 
     1690    (*pjsua_var.media_cfg.on_aud_prev_rec_frame)(frame); 
     1691    return PJ_SUCCESS; 
     1692} 
     1693 
    16801694/* Open sound device with the setting. */ 
    16811695static pj_status_t open_snd_dev(pjmedia_snd_port_param *param) 
     
    17051719    PJ_ASSERT_RETURN(pjsua_var.snd_pool, PJ_ENOMEM); 
    17061720 
     1721    /* Setup preview callbacks, if configured */ 
     1722    if (pjsua_var.media_cfg.on_aud_prev_play_frame) 
     1723        param->on_play_frame = &on_aud_prev_play_frame; 
     1724    if (pjsua_var.media_cfg.on_aud_prev_rec_frame) 
     1725        param->on_rec_frame = &on_aud_prev_rec_frame; 
    17071726 
    17081727    PJ_LOG(4,(THIS_FILE, "Opening sound device %s@%d/%d/%dms", 
Note: See TracChangeset for help on using the changeset viewer.