//Ended by us void BlabbleCall::LocalEnd() { pjsua_call_id old_id = INTERLOCKED_EXCHANGE((volatile long *)&call_id_, (long)INVALID_CALL); if (old_id == INVALID_CALL || old_id < 0 || old_id >= (long)pjsua_call_get_max_count()) { return; } StopRinging(); pjsua_call_info info; if (pjsua_call_get_info(old_id, &info) == PJ_SUCCESS && info.conf_slot > 0) { //Kill the audio pjsua_conf_disconnect(info.conf_slot, 0); pjsua_conf_disconnect(0, info.conf_slot); } pjsua_call_hangup(old_id, 0, NULL, NULL); if (on_call_end_) { BlabbleCallPtr call = get_shared(); on_call_end_->getHost()->ScheduleOnMainThread(call, boost::bind(&BlabbleCall::CallOnCallEnd, call)); } BlabbleAccountPtr p = parent_.lock(); if (p) p->OnCallEnd(get_shared()); }
/** * \fn find_call() * \brief Xac dinh call id cua cuoc goi gan nhat * \return PJ_SUCCESS */ static pj_bool_t find_call(void) { int i, max; max = pjsua_call_get_max_count(); for (i = max-1; i >= 0; --i) { if (pjsua_call_is_active(i)) { current_call = i; return PJ_TRUE; } } current_call = PJSUA_INVALID_ID; return PJ_FALSE; }
//Ended by remote, could be becuase of an error void BlabbleCall::RemoteEnd(const pjsua_call_info &info) { pjsua_call_id old_id = INTERLOCKED_EXCHANGE((volatile long *)&call_id_, (long)INVALID_CALL); if (old_id == INVALID_CALL || old_id < 0 || old_id >= (long)pjsua_call_get_max_count()) { return; } StopRinging(); //Kill the audio if (info.conf_slot > 0) { pjsua_conf_disconnect(info.conf_slot, 0); pjsua_conf_disconnect(0, info.conf_slot); } pjsua_call_hangup(old_id, 0, NULL, NULL); if (info.last_status > 400) { std::string callerId; if (info.remote_contact.ptr == NULL) { callerId =std::string(info.remote_info.ptr, info.remote_info.slen); } else { callerId = std::string(info.remote_contact.ptr, info.remote_contact.slen); } if (on_call_end_) { BlabbleCallPtr call = get_shared(); on_call_end_->getHost()->ScheduleOnMainThread(call, boost::bind(&BlabbleCall::CallOnCallEnd, call, info.last_status)); } } else { if (on_call_end_) { BlabbleCallPtr call = get_shared(); on_call_end_->getHost()->ScheduleOnMainThread(call, boost::bind(&BlabbleCall::CallOnCallEnd, call)); } } BlabbleAccountPtr p = parent_.lock(); if (p) p->OnCallEnd(get_shared()); }
bool BlabbleCall::RegisterIncomingCall(pjsua_call_id call_id) { BlabbleAccountPtr p = parent_.lock(); if (!p) return false; if (call_id_ == INVALID_CALL && call_id != INVALID_CALL && call_id >= 0 && call_id < (long)pjsua_call_get_max_count()) { call_id_ = call_id; pjsua_call_set_user_data(call_id, &id_); /* Automatically answer incoming calls with 180/RINGING */ pjsua_call_answer(call_id, 180, NULL, NULL); StartInRinging(); return true; } return false; }
/* * Find next call when current call is disconnected or when user * press ']' */ pj_bool_t find_next_call() { int i, max; max = pjsua_call_get_max_count(); for (i=current_call+1; i<max; ++i) { if (pjsua_call_is_active(i)) { current_call = i; return PJ_TRUE; } } for (i=0; i<current_call; ++i) { if (pjsua_call_is_active(i)) { current_call = i; return PJ_TRUE; } } current_call = PJSUA_INVALID_ID; return PJ_FALSE; }