Ignore:
Timestamp:
Oct 5, 2007 9:12:26 AM (17 years ago)
Author:
bennylp
Message:

Ticket #391: Added framework to send and receive arbitrary requests within call in PJSUA-LIB, with samples to send/receive DTMF with INFO in pjsua application

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c

    r1471 r1477  
    15971597 
    15981598/* 
     1599 * Handler when a transaction within a call has changed state. 
     1600 */ 
     1601static void on_call_tsx_state(pjsua_call_id call_id, 
     1602                              pjsip_transaction *tsx, 
     1603                              pjsip_event *e) 
     1604{ 
     1605    const pjsip_method info_method =  
     1606    { 
     1607        PJSIP_OTHER_METHOD, 
     1608        { "INFO", 4 } 
     1609    }; 
     1610 
     1611    if (pjsip_method_cmp(&tsx->method, &info_method)==0) { 
     1612        /* 
     1613         * Handle INFO method. 
     1614         */ 
     1615        if (tsx->role == PJSIP_ROLE_UAC &&  
     1616            (tsx->state == PJSIP_TSX_STATE_COMPLETED || 
     1617               tsx->state == PJSIP_TSX_STATE_TERMINATED && 
     1618               e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED))  
     1619        { 
     1620            /* Status of outgoing INFO request */ 
     1621            if (tsx->status_code >= 200 && tsx->status_code < 300) { 
     1622                PJ_LOG(4,(THIS_FILE,  
     1623                          "Call %d: DTMF sent successfully with INFO", 
     1624                          call_id)); 
     1625            } else if (tsx->status_code >= 300) { 
     1626                PJ_LOG(4,(THIS_FILE,  
     1627                          "Call %d: Failed to send DTMF with INFO: %d/%.*s", 
     1628                          call_id, 
     1629                          tsx->status_code, 
     1630                          (int)tsx->status_text.slen, 
     1631                          tsx->status_text.ptr)); 
     1632            } 
     1633        } else if (tsx->role == PJSIP_ROLE_UAS && 
     1634                   tsx->state == PJSIP_TSX_STATE_TRYING) 
     1635        { 
     1636            /* Answer incoming INFO with 200/OK */ 
     1637            pjsip_rx_data *rdata; 
     1638            pjsip_tx_data *tdata; 
     1639            pj_status_t status; 
     1640 
     1641            rdata = e->body.tsx_state.src.rdata; 
     1642 
     1643            if (rdata->msg_info.msg->body) { 
     1644                status = pjsip_endpt_create_response(tsx->endpt, rdata, 
     1645                                                     200, NULL, &tdata); 
     1646                if (status == PJ_SUCCESS) 
     1647                    status = pjsip_tsx_send_msg(tsx, tdata); 
     1648 
     1649                PJ_LOG(3,(THIS_FILE, "Call %d: incoming INFO:\n%.*s",  
     1650                          call_id, 
     1651                          (int)rdata->msg_info.msg->body->len, 
     1652                          rdata->msg_info.msg->body->data)); 
     1653            } else { 
     1654                status = pjsip_endpt_create_response(tsx->endpt, rdata, 
     1655                                                     400, NULL, &tdata); 
     1656                if (status == PJ_SUCCESS) 
     1657                    status = pjsip_tsx_send_msg(tsx, tdata); 
     1658            } 
     1659        } 
     1660    } 
     1661} 
     1662 
     1663 
     1664/* 
    15991665 * Callback on media state changed event. 
    16001666 * The action may connect the call to sound device, to file, or 
     
    28632929            break; 
    28642930 
     2931        case '*': 
     2932            /* Send DTMF with INFO */ 
     2933            if (current_call == -1) { 
     2934                 
     2935                PJ_LOG(3,(THIS_FILE, "No current call")); 
     2936 
     2937            } else { 
     2938                const pj_str_t SIP_INFO = pj_str("INFO"); 
     2939                pj_str_t digits; 
     2940                int call = current_call; 
     2941                int i; 
     2942                pj_status_t status; 
     2943 
     2944                if (!simple_input("DTMF strings to send (0-9*#A-B)", buf,  
     2945                                  sizeof(buf))) 
     2946                { 
     2947                        break; 
     2948                } 
     2949 
     2950                if (call != current_call) { 
     2951                    puts("Call has been disconnected"); 
     2952                    continue; 
     2953                } 
     2954 
     2955                digits = pj_str(buf); 
     2956                for (i=0; i<digits.slen; ++i) { 
     2957                    pjsua_msg_data msg_data; 
     2958                    char body[80]; 
     2959 
     2960                    pjsua_msg_data_init(&msg_data); 
     2961                    msg_data.content_type = pj_str("application/dtmf-relay"); 
     2962                     
     2963                    pj_ansi_snprintf(body, sizeof(body), 
     2964                                     "Signal=%c\r\n" 
     2965                                     "Duration=160", 
     2966                                     buf[i]); 
     2967                    msg_data.msg_body = pj_str(body); 
     2968 
     2969                    status = pjsua_call_send_request(current_call, &SIP_INFO,  
     2970                                                     &msg_data); 
     2971                    if (status != PJ_SUCCESS) { 
     2972                        break; 
     2973                    } 
     2974                } 
     2975            } 
     2976            break; 
     2977 
    28652978        case 'S': 
    28662979            /* 
     
    31513264    app_config.cfg.cb.on_call_media_state = &on_call_media_state; 
    31523265    app_config.cfg.cb.on_incoming_call = &on_incoming_call; 
     3266    app_config.cfg.cb.on_call_tsx_state = &on_call_tsx_state; 
    31533267    app_config.cfg.cb.on_dtmf_digit = &call_on_dtmf_callback; 
    31543268    app_config.cfg.cb.on_reg_state = &on_reg_state; 
Note: See TracChangeset for help on using the changeset viewer.