PJ_DECL(pj_status_t) vid_set_android_renderer(pjsua_call_id call_id, jobject window) { pj_status_t status = PJ_ENOTFOUND; pjsua_call *call; int i; if( !(call_id>=0 && call_id<(int)pjsua_var.ua_cfg.max_calls) ){ return PJ_ENOTFOUND; } PJ_LOG(4, (THIS_FILE, "Setup android renderer for call %d", call_id)); PJSUA_LOCK(); // Retrieve the stream if (pjsua_call_has_media(call_id)) { call = &pjsua_var.calls[call_id]; for (i = 0; i < call->med_cnt; ++i) { pjsua_call_media *call_med = &call->media[i]; vid_set_stream_window(call_med, PJMEDIA_DIR_RENDER, window); status = PJ_SUCCESS; } } PJSUA_UNLOCK(); return status; }
PJ_DECL(pj_status_t) vid_set_android_capturer(jobject window) { unsigned ci, i, count; pj_status_t status = PJ_ENOTFOUND; pjsua_call *call; pjsua_call_id calls_id[PJSUA_MAX_ACC]; count = PJ_ARRAY_SIZE(calls_id); status = pjsua_enum_calls(calls_id, &count); if(status != PJ_SUCCESS){ return status; } PJ_LOG(4, (THIS_FILE, "Setup android capturer for all calls")); PJSUA_LOCK(); for(ci = 0; ci < count; ++ci){ pjsua_call_id call_id = calls_id[ci]; if(pjsua_call_is_active(call_id) && pjsua_call_has_media(call_id)){ call = &pjsua_var.calls[call_id]; for (i = 0; i < call->med_cnt; ++i) { pjsua_call_media *call_med = &call->media[i]; vid_set_stream_window(call_med, PJMEDIA_DIR_CAPTURE, window); status = PJ_SUCCESS; } } } PJSUA_UNLOCK(); return status; }
static void ui_send_dtmf_2833() { if (current_call == -1) { PJ_LOG(3,(THIS_FILE, "No current call")); } else if (!pjsua_call_has_media(current_call)) { PJ_LOG(3,(THIS_FILE, "Media is not established yet!")); } else { pj_str_t digits; int call = current_call; pj_status_t status; char buf[128]; if (!simple_input("DTMF strings to send (0-9*R#A-B)", buf, sizeof(buf))) { return; } if (call != current_call) { puts("Call has been disconnected"); return; } digits = pj_str(buf); status = pjsua_call_dial_dtmf(current_call, &digits); if (status != PJ_SUCCESS) { pjsua_perror(THIS_FILE, "Unable to send DTMF", status); } else { puts("DTMF digits enqueued for transmission"); } } }
struct jzrtp_allContext jzrtp_getContext(pjsua_call_id call_id) { pjsua_call *call; pj_status_t status; unsigned i; pjmedia_transport_info tp_info; struct jzrtp_allContext result; result.cbUserData = NULL; result.zrtpContext = NULL; PJ_ASSERT_RETURN(call_id>=0 && call_id<(int)pjsua_var.ua_cfg.max_calls, NULL); if (pjsua_call_has_media(call_id)) { call = &pjsua_var.calls[call_id]; for (i = 0; i < call->med_cnt; ++i) { pjsua_call_media *call_med = &call->media[i]; if (call_med->tp && call_med->type == PJMEDIA_TYPE_AUDIO) { pjmedia_transport_info tp_info; pjmedia_transport_info_init(&tp_info); pjmedia_transport_get_info(call_med->tp, &tp_info); if (tp_info.specific_info_cnt > 0) { unsigned j; for (j = 0; j < tp_info.specific_info_cnt; ++j) { if (tp_info.spc_info[j].type == PJMEDIA_TRANSPORT_TYPE_ZRTP) { result.zrtpContext = pjmedia_transport_zrtp_getZrtpContext(call_med->tp); result.cbUserData = (zrtp_cb_user_data*) pjmedia_transport_zrtp_getUserData(call_med->tp); } } } } } } return result; }
static void _ics_conference_call(ics_t *data, int call_id) { int i, max; PJ_UNUSED_ARG(data); max = pjsua_call_get_count(); SHOW_LOG(3, "Let's conference call!\n"); pjsua_call_info ci; #if 1 if ( (call_id != current_call) && pjsua_call_is_active(call_id) ) { pjsua_call_reinvite(call_id, PJ_TRUE, NULL); for (i = 0; i < max; i++) { if (pjsua_call_has_media(i) != 0) { pjsua_conf_connect(pjsua_call_get_conf_port(call_id), pjsua_call_get_conf_port(i)); pjsua_conf_connect(pjsua_call_get_conf_port(i), pjsua_call_get_conf_port(call_id)); } } } else SHOW_LOG(3, "Cannot transfer call!\n"); #endif //For test only: #if 1 for (i = 0; i < max; i++){ if (pjsua_call_is_active(i) && (i != current_call)) { pjsua_call_reinvite(i, PJ_TRUE, NULL); pjsua_call_get_info(i, &ci); pjsua_conf_connect(pjsua_call_get_conf_port(ci.id), pjsua_call_get_conf_port(current_call)); pjsua_conf_connect(pjsua_call_get_conf_port(current_call), pjsua_call_get_conf_port(ci.id)); } break; } #endif }
/** * Is call using a secure RTP method (SRTP/ZRTP) */ PJ_DECL(pj_str_t) call_secure_info(pjsua_call_id call_id) { pjsua_call *call; pj_status_t status; unsigned i; pjmedia_transport_info tp_info; pj_str_t result = pj_str(""); PJ_ASSERT_RETURN(call_id>=0 && call_id<(int)pjsua_var.ua_cfg.max_calls, result); PJSUA_LOCK(); if (pjsua_call_has_media(call_id)) { call = &pjsua_var.calls[call_id]; for (i = 0; i < call->med_cnt; ++i) { pjsua_call_media *call_med = &call->media[i]; PJ_LOG(4, (THIS_FILE, "Get secure for media type %d", call_med->type)); if (call_med->tp && call_med->type == PJMEDIA_TYPE_AUDIO) { pjmedia_transport_info tp_info; pjmedia_transport_info_init(&tp_info); pjmedia_transport_get_info(call_med->tp, &tp_info); if (tp_info.specific_info_cnt > 0) { unsigned j; for (j = 0; j < tp_info.specific_info_cnt; ++j) { if (tp_info.spc_info[j].type == PJMEDIA_TRANSPORT_TYPE_SRTP) { pjmedia_srtp_info *srtp_info = (pjmedia_srtp_info*) tp_info.spc_info[j].buffer; if (srtp_info->active) { result = pj_str("SRTP"); break; } } #if defined(PJMEDIA_HAS_ZRTP) && PJMEDIA_HAS_ZRTP!=0 else if (tp_info.spc_info[j].type == PJMEDIA_TRANSPORT_TYPE_ZRTP) { zrtp_state_info info = jzrtp_getInfoFromTransport(call_med->tp); if(info.secure){ char msg[512]; PJ_LOG(4, (THIS_FILE, "ZRTP :: V %d", info.sas_verified)); PJ_LOG(4, (THIS_FILE, "ZRTP :: S L %d", info.sas.slen)); PJ_LOG(4, (THIS_FILE, "ZRTP :: C L %d", info.cipher.slen)); pj_ansi_snprintf(msg, sizeof(msg), "ZRTP - %s\n%.*s\n%.*s", info.sas_verified ? "Verified": "Not verified", info.sas.slen, info.sas.ptr, info.cipher.slen, info.cipher.ptr); pj_strdup2_with_null(css_var.pool, &result, msg); break; } } #endif } } } } } PJSUA_UNLOCK(); return result; }
/** * Is call using a secure RTP method (SRTP/ZRTP) */ PJ_DECL(pj_str_t) call_secure_info(pjsua_call_id call_id) { pjsua_call *call; pjsip_dialog *dlg; pj_status_t status; unsigned i; pjmedia_transport_info tp_info; pj_str_t result = pj_str(""); PJ_LOG(3, (THIS_FILE, "Get call secure info...")); PJ_ASSERT_RETURN(call_id>=0 && call_id<(int)pjsua_var.ua_cfg.max_calls, result); /* Use PJSUA_LOCK() instead of acquire_call(): * https://trac.pjsip.org/repos/ticket/1371 */ PJSUA_LOCK(); if (pjsua_call_has_media(call_id)) { call = &pjsua_var.calls[call_id]; for (i = 0; i < call->med_cnt; ++i) { pjsua_call_media *call_med = &call->media[i]; PJ_LOG(4, (THIS_FILE, "Get secure for media type %d", call_med->type)); /* Get and ICE SRTP status */ if (call_med->tp && call_med->type == PJMEDIA_TYPE_AUDIO) { pjmedia_transport_info tp_info; pjmedia_transport_info_init(&tp_info); pjmedia_transport_get_info(call_med->tp, &tp_info); if (tp_info.specific_info_cnt > 0) { unsigned j; for (j = 0; j < tp_info.specific_info_cnt; ++j) { if (tp_info.spc_info[j].type == PJMEDIA_TRANSPORT_TYPE_SRTP) { pjmedia_srtp_info *srtp_info = (pjmedia_srtp_info*) tp_info.spc_info[j].buffer; if (srtp_info->active) { result = pj_str("SRTP"); break; } } #if defined(PJMEDIA_HAS_ZRTP) && PJMEDIA_HAS_ZRTP!=0 else if (tp_info.spc_info[j].type == PJMEDIA_TRANSPORT_TYPE_ZRTP) { pjmedia_zrtp_info *zrtp_info = (pjmedia_zrtp_info*) tp_info.spc_info[j].buffer; // if(zrtp_info->active){ result = jzrtp_getInfo(call_med->tp); break; // } } #endif } } } } } PJSUA_UNLOCK(); return result; }
/* * Callback on media state changed event. * The action may connect the call to sound device, to file, or * to loop the call. */ static void on_call_media_state(pjsua_call_id call_id) { pjsua_call_info call_info; pjsua_call_get_info(call_id, &call_info); /* Connect ports appropriately when media status is ACTIVE or REMOTE HOLD, * otherwise we should NOT connect the ports. */ if (call_info.media_status == PJSUA_CALL_MEDIA_ACTIVE || call_info.media_status == PJSUA_CALL_MEDIA_REMOTE_HOLD) { pj_bool_t connect_sound = PJ_TRUE; /* Loopback sound, if desired */ if (app_config.auto_loop) { pjsua_conf_connect(call_info.conf_slot, call_info.conf_slot); connect_sound = PJ_FALSE; } /* Automatically record conversation, if desired */ if (app_config.auto_rec && app_config.rec_port != PJSUA_INVALID_ID) { pjsua_conf_connect(call_info.conf_slot, app_config.rec_port); } /* Stream a file, if desired */ if ((app_config.auto_play || app_config.auto_play_hangup) && app_config.wav_port != PJSUA_INVALID_ID) { pjsua_conf_connect(app_config.wav_port, call_info.conf_slot); connect_sound = PJ_FALSE; } /* Put call in conference with other calls, if desired */ if (app_config.auto_conf) { pjsua_call_id call_ids[PJSUA_MAX_CALLS]; unsigned call_cnt=PJ_ARRAY_SIZE(call_ids); unsigned i; /* Get all calls, and establish media connection between * this call and other calls. */ pjsua_enum_calls(call_ids, &call_cnt); for (i=0; i<call_cnt; ++i) { if (call_ids[i] == call_id) continue; if (!pjsua_call_has_media(call_ids[i])) continue; pjsua_conf_connect(call_info.conf_slot, pjsua_call_get_conf_port(call_ids[i])); pjsua_conf_connect(pjsua_call_get_conf_port(call_ids[i]), call_info.conf_slot); /* Automatically record conversation, if desired */ if (app_config.auto_rec && app_config.rec_port != PJSUA_INVALID_ID) { pjsua_conf_connect(pjsua_call_get_conf_port(call_ids[i]), app_config.rec_port); } } /* Also connect call to local sound device */ connect_sound = PJ_TRUE; } /* Otherwise connect to sound device */ if (connect_sound) { pjsua_conf_connect(call_info.conf_slot, 0); pjsua_conf_connect(0, call_info.conf_slot); /* Automatically record conversation, if desired */ if (app_config.auto_rec && app_config.rec_port != PJSUA_INVALID_ID) { pjsua_conf_connect(call_info.conf_slot, app_config.rec_port); pjsua_conf_connect(0, app_config.rec_port); } } } PJ_LOG(3,(THIS_FILE, "Media for call %d is active", call_id)); /* Handle media status */ switch (call_info.media_status) { case PJSUA_CALL_MEDIA_ACTIVE: PJ_LOG(3,(THIS_FILE, "Media for call %d is active", call_id)); break; case PJSUA_CALL_MEDIA_LOCAL_HOLD: PJ_LOG(3,(THIS_FILE, "Media for call %d is suspended (hold) by local", call_id)); // call on call hold handler cb_callholdconf(call_id); break; case PJSUA_CALL_MEDIA_REMOTE_HOLD: PJ_LOG(3,(THIS_FILE, "Media for call %d is suspended (hold) by remote", call_id)); break; case PJSUA_CALL_MEDIA_ERROR: PJ_LOG(3,(THIS_FILE, "Media has reported error, disconnecting call")); { pj_str_t reason = pj_str("ICE negotiation failed"); pjsua_call_hangup(call_id, 500, &reason, NULL); } break; case PJSUA_CALL_MEDIA_NONE: PJ_LOG(3,(THIS_FILE, "Media for call %d is inactive", call_id)); break; default: pj_assert(!"Unhandled media status"); break; } }