Changeset 863


Ignore:
Timestamp:
Dec 26, 2006 12:11:48 AM (17 years ago)
Author:
bennylp
Message:

Added DTMF callback support all the way to PJSUA API (ticket #48)

Location:
pjproject/trunk
Files:
9 edited

Legend:

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

    r518 r863  
    322322 
    323323/** 
     324 * Set callback to be called upon receiving DTMF digits. If callback is 
     325 * registered, the stream will not buffer incoming DTMF but rather call 
     326 * the callback as soon as DTMF digit is received completely. 
     327 * 
     328 * @param session       The media session. 
     329 * @param index         The stream index. 
     330 * @param cb            Callback to be called upon receiving DTMF digits. 
     331 *                      The DTMF digits will be given to the callback as 
     332 *                      ASCII digits. 
     333 * @param user_data     User data to be returned back when the callback 
     334 *                      is called. 
     335 * 
     336 * @return              PJ_SUCCESS on success. 
     337 */ 
     338PJ_DECL(pj_status_t) 
     339pjmedia_session_set_dtmf_callback(pjmedia_session *session, 
     340                                  unsigned index, 
     341                                  void (*cb)(pjmedia_stream*,  
     342                                             void *user_data,  
     343                                             int digit),  
     344                                  void *user_data); 
     345 
     346/** 
    324347 * Destroy media session. 
    325348 * 
  • pjproject/trunk/pjmedia/include/pjmedia/stream.h

    r568 r863  
    278278 
    279279/** 
     280 * Set callback to be called upon receiving DTMF digits. If callback is 
     281 * registered, the stream will not buffer incoming DTMF but rather call 
     282 * the callback as soon as DTMF digit is received completely. 
     283 * 
     284 * @param stream        The media stream. 
     285 * @param cb            Callback to be called upon receiving DTMF digits. 
     286 *                      The DTMF digits will be given to the callback as 
     287 *                      ASCII digits. 
     288 * @param user_data     User data to be returned back when the callback 
     289 *                      is called. 
     290 * 
     291 * @return              PJ_SUCCESS on success. 
     292 */ 
     293PJ_DECL(pj_status_t) 
     294pjmedia_stream_set_dtmf_callback(pjmedia_stream *stream, 
     295                                 void (*cb)(pjmedia_stream*,  
     296                                            void *user_data,  
     297                                            int digit),  
     298                                 void *user_data); 
     299 
     300/** 
    280301 * @} 
    281302 */ 
  • pjproject/trunk/pjmedia/src/pjmedia/session.c

    r637 r863  
    734734                                   size); 
    735735} 
     736 
     737/* 
     738 * Install DTMF callback. 
     739 */ 
     740PJ_DEF(pj_status_t) 
     741pjmedia_session_set_dtmf_callback(pjmedia_session *session, 
     742                                  unsigned index, 
     743                                  void (*cb)(pjmedia_stream*,  
     744                                             void *user_data,  
     745                                             int digit),  
     746                                  void *user_data) 
     747{ 
     748    PJ_ASSERT_RETURN(session && index < session->stream_cnt, PJ_EINVAL); 
     749    return pjmedia_stream_set_dtmf_callback(session->stream[index], cb, 
     750                                            user_data); 
     751} 
     752 
  • pjproject/trunk/pjmedia/src/pjmedia/stream.c

    r846 r863  
    114114    unsigned                 rx_dtmf_count; /**< # of digits in dtmf rx buf.*/ 
    115115    char                     rx_dtmf_buf[32];/**< Incoming DTMF buffer.     */ 
     116 
     117    /* DTMF callback */ 
     118    void                    (*dtmf_cb)(pjmedia_stream*, void*, int); 
     119    void                     *dtmf_cb_user_data; 
    116120}; 
    117121 
     
    380384        pj_mutex_unlock(stream->jb_mutex); 
    381385 
    382         if (stream->tx_dtmf_count) 
     386        if (stream->tx_dtmf_count) { 
    383387            PJ_LOG(5,(stream->port.info.name.ptr, 
    384388                      "Sending DTMF digit id %c",  
    385389                      digitmap[stream->tx_dtmf_buf[0].event])); 
     390        } 
    386391 
    387392    } else if (duration == 0) { 
     
    664669    stream->last_dtmf_dur = pj_ntohs(event->duration); 
    665670 
    666     /* By convention, we use jitter buffer's mutex to access shared 
    667      * DTMF variables. 
     671    /* If DTMF callback is installed, call the callback, otherwise keep 
     672     * the DTMF digits in the buffer. 
    668673     */ 
    669     pj_mutex_lock(stream->jb_mutex); 
    670     if (stream->rx_dtmf_count >= PJ_ARRAY_SIZE(stream->rx_dtmf_buf)) { 
    671         /* DTMF digits overflow.  Discard the oldest digit. */ 
    672         pj_array_erase(stream->rx_dtmf_buf, sizeof(stream->rx_dtmf_buf[0]), 
    673                        stream->rx_dtmf_count, 0); 
    674         --stream->rx_dtmf_count; 
    675     } 
    676     stream->rx_dtmf_buf[stream->rx_dtmf_count++] = digitmap[event->event]; 
    677     pj_mutex_unlock(stream->jb_mutex); 
     674    if (stream->dtmf_cb) { 
     675 
     676        stream->dtmf_cb(stream, stream->dtmf_cb_user_data,  
     677                        digitmap[event->event]); 
     678 
     679    } else { 
     680        /* By convention, we use jitter buffer's mutex to access shared 
     681         * DTMF variables. 
     682         */ 
     683        pj_mutex_lock(stream->jb_mutex); 
     684        if (stream->rx_dtmf_count >= PJ_ARRAY_SIZE(stream->rx_dtmf_buf)) { 
     685            /* DTMF digits overflow.  Discard the oldest digit. */ 
     686            pj_array_erase(stream->rx_dtmf_buf,  
     687                           sizeof(stream->rx_dtmf_buf[0]), 
     688                           stream->rx_dtmf_count, 0); 
     689            --stream->rx_dtmf_count; 
     690        } 
     691        stream->rx_dtmf_buf[stream->rx_dtmf_count++] = digitmap[event->event]; 
     692        pj_mutex_unlock(stream->jb_mutex); 
     693    } 
    678694} 
    679695 
     
    13691385    return PJ_SUCCESS; 
    13701386} 
     1387 
     1388 
     1389/* 
     1390 * Set callback to be called upon receiving DTMF digits. 
     1391 */ 
     1392PJ_DEF(pj_status_t) 
     1393pjmedia_stream_set_dtmf_callback(pjmedia_stream *stream, 
     1394                                 void (*cb)(pjmedia_stream*,  
     1395                                            void *user_data,  
     1396                                            int digit),  
     1397                                 void *user_data) 
     1398{ 
     1399    PJ_ASSERT_RETURN(stream, PJ_EINVAL); 
     1400 
     1401    /* By convention, we use jitter buffer's mutex to access DTMF 
     1402     * digits resources. 
     1403     */ 
     1404    pj_mutex_lock(stream->jb_mutex); 
     1405 
     1406    stream->dtmf_cb = cb; 
     1407    stream->dtmf_cb_user_data = user_data; 
     1408 
     1409    pj_mutex_unlock(stream->jb_mutex); 
     1410 
     1411    return PJ_SUCCESS; 
     1412} 
     1413 
  • pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c

    r861 r863  
    16231623} 
    16241624 
     1625/* 
     1626 * DTMF callback. 
     1627 */ 
     1628static void call_on_dtmf_callback(pjsua_call_id call_id, int dtmf) 
     1629{ 
     1630    PJ_LOG(3,(THIS_FILE, "Incoming DTMF on call %d: %c", call_id, dtmf)); 
     1631} 
    16251632 
    16261633/* 
     
    28192826    app_config.cfg.cb.on_call_media_state = &on_call_media_state; 
    28202827    app_config.cfg.cb.on_incoming_call = &on_incoming_call; 
     2828    app_config.cfg.cb.on_dtmf_digit = &call_on_dtmf_callback; 
    28212829    app_config.cfg.cb.on_reg_state = &on_reg_state; 
    28222830    app_config.cfg.cb.on_buddy_state = &on_buddy_state; 
  • pjproject/trunk/pjsip/include/pjsip.h

    r849 r863  
    4141#include <pjsip/sip_transport_loop.h> 
    4242#include <pjsip/sip_transport_tcp.h> 
    43 #if defined(PJSIP_HAS_TLS_TRANSPORT) && PJSIP_HAS_TLS_TRANSPORT!=0 
    44 #   include <pjsip/sip_transport_tls.h> 
    45 #endif 
     43#include <pjsip/sip_transport_tls.h> 
    4644#include <pjsip/sip_resolve.h> 
    4745 
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h

    r861 r863  
    287287     * Application may then query the call info to get the 
    288288     * detail call states. 
     289     * 
     290     * @param call_id   The call index. 
     291     * @param e         Event which causes the call state to change. 
    289292     */ 
    290293    void (*on_call_state)(pjsua_call_id call_id, pjsip_event *e); 
     
    292295    /** 
    293296     * Notify application on incoming call. 
     297     * 
     298     * @param acc_id    The account which match the incoming call. 
     299     * @param call_id   The call id that has just been created for 
     300     *                  the call. 
     301     * @param rdata     The incoming INVITE request. 
    294302     */ 
    295303    void (*on_incoming_call)(pjsua_acc_id acc_id, pjsua_call_id call_id, 
     
    300308     * Normal application would need to implement this callback, e.g. 
    301309     * to connect the call's media to sound device. 
     310     * 
     311     * @param call_id   The call index. 
    302312     */ 
    303313    void (*on_call_media_state)(pjsua_call_id call_id); 
     314 
     315    /** 
     316     * Notify application upon incoming DTMF digits. 
     317     * 
     318     * @param call_id   The call index. 
     319     * @param digit     DTMF ASCII digit. 
     320     */ 
     321    void (*on_dtmf_digit)(pjsua_call_id call_id, int digit); 
    304322 
    305323    /** 
     
    309327     * is not defined, the default behavior is to accept the 
    310328     * transfer. 
     329     * 
     330     * @param call_id   The call index. 
     331     * @param dst       The destination where the call will be  
     332     *                  transfered to. 
     333     * @param code      Status code to be returned for the call transfer 
     334     *                  request. On input, it contains status code 200. 
    311335     */ 
    312336    void (*on_call_transfer_request)(pjsua_call_id call_id, 
     
    373397     * Application may then query the account info to get the 
    374398     * registration details. 
     399     * 
     400     * @param acc_id        Account ID. 
    375401     */ 
    376402    void (*on_reg_state)(pjsua_acc_id acc_id); 
     
    379405     * Notify application when the buddy state has changed. 
    380406     * Application may then query the buddy into to get the details. 
     407     * 
     408     * @param buddy_id      The buddy id. 
    381409     */ 
    382410    void (*on_buddy_state)(pjsua_buddy_id buddy_id); 
     
    386414     * Argument call_id will be -1 if MESSAGE request is not related to an 
    387415     * existing call. 
     416     * 
     417     * @param call_id       Containts the ID of the call where the IM was 
     418     *                      sent, or PJSUA_INVALID_ID if the IM was sent 
     419     *                      outside call context. 
     420     * @param from          URI of the sender. 
     421     * @param to            URI of the destination message. 
     422     * @param contact       The Contact URI of the sender, if present. 
     423     * @param mime_type     MIME type of the message. 
     424     * @param body          The message content. 
    388425     */ 
    389426    void (*on_pager)(pjsua_call_id call_id, const pj_str_t *from, 
     
    414451    /** 
    415452     * Notify application about typing indication. 
     453     * 
     454     * @param call_id       Containts the ID of the call where the IM was 
     455     *                      sent, or PJSUA_INVALID_ID if the IM was sent 
     456     *                      outside call context. 
     457     * @param from          URI of the sender. 
     458     * @param to            URI of the destination message. 
     459     * @param contact       The Contact URI of the sender, if present. 
     460     * @param is_typing     Non-zero if peer is typing, or zero if peer 
     461     *                      has stopped typing a message. 
    416462     */ 
    417463    void (*on_typing)(pjsua_call_id call_id, const pj_str_t *from, 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c

    r847 r863  
    20512051 
    20522052/* 
     2053 * DTMF callback from the stream. 
     2054 */ 
     2055static void dtmf_callback(pjmedia_stream *strm, void *user_data, 
     2056                          int digit) 
     2057{ 
     2058    PJ_UNUSED_ARG(strm); 
     2059 
     2060    if (pjsua_var.ua_cfg.cb.on_dtmf_digit) { 
     2061        pjsua_call_id call_id; 
     2062 
     2063        call_id = (pjsua_call_id)user_data; 
     2064        pjsua_var.ua_cfg.cb.on_dtmf_digit(call_id, digit); 
     2065    } 
     2066} 
     2067 
     2068/* 
    20532069 * Callback to be called when SDP offer/answer negotiation has just completed 
    20542070 * in the session. This function will start/update media if negotiation 
     
    21892205        } 
    21902206 
     2207        /* If DTMF callback is installed by application, install our 
     2208         * callback to the session. 
     2209         */ 
     2210        if (pjsua_var.ua_cfg.cb.on_dtmf_digit) { 
     2211            pjmedia_session_set_dtmf_callback(call->session, 0,  
     2212                                              &dtmf_callback,  
     2213                                              (void*)(call->index)); 
     2214        } 
    21912215 
    21922216        /* Get the port interface of the first stream in the session. 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c

    r833 r863  
    443443 
    444444    /* Close media transports */ 
    445     for (i=0; i<(int)pjsua_var.ua_cfg.max_calls; ++i) { 
     445    for (i=0; i<pjsua_var.ua_cfg.max_calls; ++i) { 
    446446        if (pjsua_var.calls[i].med_tp) { 
    447447            (*pjsua_var.calls[i].med_tp->op->destroy)(pjsua_var.calls[i].med_tp); 
Note: See TracChangeset for help on using the changeset viewer.