Commit 6491a44f authored by Guillaume Roguez's avatar Guillaume Roguez

daemon: move carryingDTMFdigits API to Call class

Refs #51555

Change-Id: Id993a11abe043c49cdeb4f671b24dd7c15aa93f1
parent 15b3f187
......@@ -283,6 +283,12 @@ class Call : public Recordable {
*/
virtual void peerHungup() = 0;
/**
* Send DTMF
* @param code The char code
*/
virtual void carryingDTMFdigits(char code) = 0;
private:
bool validTransition(CallState newState);
......
......@@ -219,3 +219,10 @@ IAXCall::peerHungup()
link_->removeIaxCall(getCallId());
}
void
IAXCall::carryingDTMFdigits(char code)
{
std::lock_guard<std::mutex> lock(IAXVoIPLink::mutexIAX);
iax_send_dtmf(session, code);
}
......@@ -96,6 +96,8 @@ class IAXCall : public Call {
void peerHungup();
void carryingDTMFdigits(char code);
private:
NON_COPYABLE(IAXCall);
......
......@@ -313,20 +313,6 @@ IAXVoIPLink::newOutgoingCall(const std::string& id, const std::string& toUrl, co
return call;
}
void
IAXVoIPLink::carryingDTMFdigits(const std::string& id, char code)
{
std::lock_guard<std::mutex> lock(iaxCallMapMutex_);
auto call = getIAXCall(id);
if (!call)
return;
{
std::lock_guard<std::mutex> lock(mutexIAX);
iax_send_dtmf(call->session, code);
}
}
#if HAVE_INSTANT_MESSAGING
void
IAXVoIPLink::sendTextMessage(const std::string& callID,
......
......@@ -127,14 +127,6 @@ class IAXVoIPLink : public VoIPLink {
*/
virtual void cancel(const std::string& /*id*/) {}
/**
* Send DTMF
* @param id The ID of the call
* @param code The code of the DTMF
*/
virtual void carryingDTMFdigits(const std::string& id, char code);
#if HAVE_INSTANT_MESSAGING
virtual void sendTextMessage(const std::string& callID, const std::string& message, const std::string& from);
#endif
......
......@@ -1331,8 +1331,8 @@ void ManagerImpl::sendDtmf(const std::string& id, char code)
if (id.empty())
return;
std::string accountid(getAccountFromCall(id));
getAccountLink(accountid)->carryingDTMFdigits(id, code);
if (auto call = getCallFromCallID(id))
call->carryingDTMFdigits(code);
}
//THREAD=Main | VoIPLink
......
......@@ -36,6 +36,7 @@
#include "logger.h" // for _debug
#include "sdp.h"
#include "manager.h"
#include "array_size.h"
#include "audio/audiortp/audio_rtp_factory.h" // for AudioRtpFactoryException
......@@ -89,6 +90,35 @@ stopRtpIfCurrent(SIPCall& call)
}
}
static void
dtmfSend(SIPCall &call, char code, const std::string &dtmf)
{
if (dtmf == SIPAccount::OVERRTP_STR) {
call.getAudioRtp().sendDtmfDigit(code);
return;
} else if (dtmf != SIPAccount::SIPINFO_STR) {
WARN("Unknown DTMF type %s, defaulting to %s instead",
dtmf.c_str(), SIPAccount::SIPINFO_STR);
} // else : dtmf == SIPINFO
int duration = Manager::instance().voipPreferences.getPulseLength();
char dtmf_body[1000];
const char *normal_str= "Signal=%c\r\nDuration=%d\r\n";
const char *flash_str = "Signal=%d\r\nDuration=%d\r\n";
const char *str;
// handle flash code
if (code == '!') {
str = flash_str;
code = 16;
} else {
str = normal_str;
}
snprintf(dtmf_body, sizeof dtmf_body - 1, str, code, duration);
call.sendSIPInfo(dtmf_body, "dtmf-relay");
}
SIPCall::SIPCall(const std::string& id, Call::CallType type,
pj_caching_pool *caching_pool, const std::string &account_id) :
Call(id, type, account_id)
......@@ -147,6 +177,35 @@ VoIPLink*
SIPCall::getVoIPLink() const
{ return &SIPVoIPLink::instance(); }
void
SIPCall::sendSIPInfo(const char *const body, const char *const subtype)
{
pj_str_t methodName = CONST_PJ_STR("INFO");
pjsip_method method;
pjsip_method_init_np(&method, &methodName);
/* Create request message. */
pjsip_tx_data *tdata;
if (pjsip_dlg_create_request(inv->dlg, &method, -1, &tdata) != PJ_SUCCESS) {
ERROR("Could not create dialog");
return;
}
/* Create "application/<subtype>" message body. */
pj_str_t content;
pj_cstr(&content, body);
const pj_str_t type = CONST_PJ_STR("application");
pj_str_t pj_subtype;
pj_cstr(&pj_subtype, subtype);
tdata->msg->body = pjsip_msg_body_create(tdata->pool, &type, &pj_subtype, &content);
if (tdata->msg->body == NULL)
pjsip_tx_data_dec_ref(tdata);
else
pjsip_dlg_send_request(inv->dlg, tdata, SIPVoIPLink::instance().getMod()->id, NULL);
}
void SIPCall::answer()
{
SIPAccount *account = Manager::instance().getSipAccount(getAccountId());
......@@ -578,3 +637,14 @@ SIPCall::peerHungup()
siplink.removeSipCall(getCallId());
}
void
SIPCall::carryingDTMFdigits(char code)
{
const std::string accountID(getAccountId());
SIPAccount *account = Manager::instance().getSipAccount(accountID);
if (!account)
return;
dtmfSend(*this, code, account->getDtmfType());
}
......@@ -112,6 +112,8 @@ class SIPCall : public Call {
VoIPLink* getVoIPLink() const;
void sendSIPInfo(const char *const body, const char *const subtype);
void answer();
void hangup(int reason);
......@@ -128,6 +130,8 @@ class SIPCall : public Call {
void peerHungup();
void carryingDTMFdigits(char code);
private:
// override of Call::createHistoryEntry
......
......@@ -1144,65 +1144,6 @@ SIPVoIPLink::tryGetSIPCall(const std::string& id)
return call;
}
static void
sendSIPInfo(const SIPCall &call, const char *const body, const char *const subtype)
{
pj_str_t methodName = CONST_PJ_STR("INFO");
pjsip_method method;
pjsip_method_init_np(&method, &methodName);
/* Create request message. */
pjsip_tx_data *tdata;
if (pjsip_dlg_create_request(call.inv->dlg, &method, -1, &tdata) != PJ_SUCCESS) {
ERROR("Could not create dialog");
return;
}
/* Create "application/<subtype>" message body. */
pj_str_t content;
pj_cstr(&content, body);
const pj_str_t type = CONST_PJ_STR("application");
pj_str_t pj_subtype;
pj_cstr(&pj_subtype, subtype);
tdata->msg->body = pjsip_msg_body_create(tdata->pool, &type, &pj_subtype, &content);
if (tdata->msg->body == NULL)
pjsip_tx_data_dec_ref(tdata);
else
pjsip_dlg_send_request(call.inv->dlg, tdata, mod_ua_.id, NULL);
}
static void
dtmfSend(SIPCall &call, char code, const std::string &dtmf)
{
if (dtmf == SIPAccount::OVERRTP_STR) {
call.getAudioRtp().sendDtmfDigit(code);
return;
} else if (dtmf != SIPAccount::SIPINFO_STR) {
WARN("Unknown DTMF type %s, defaulting to %s instead",
dtmf.c_str(), SIPAccount::SIPINFO_STR);
} // else : dtmf == SIPINFO
int duration = Manager::instance().voipPreferences.getPulseLength();
char dtmf_body[1000];
const char *normal_str= "Signal=%c\r\nDuration=%d\r\n";
const char *flash_str = "Signal=%d\r\nDuration=%d\r\n";
const char *str;
// handle flash code
if (code == '!') {
str = flash_str;
code = 16;
} else {
str = normal_str;
}
snprintf(dtmf_body, sizeof dtmf_body - 1, str, code, duration);
sendSIPInfo(call, dtmf_body, "dtmf-relay");
}
#ifdef SFL_VIDEO
// Called from a video thread
void
......@@ -1246,27 +1187,10 @@ SIPVoIPLink::requestKeyframe(const std::string &callID)
"</to_encoder></vc_primitive></media_control>";
DEBUG("Sending video keyframe request via SIP INFO");
sendSIPInfo(*call, BODY, "media_control+xml");
call->sendSIPInfo(BODY, "media_control+xml");
}
#endif
void
SIPVoIPLink::carryingDTMFdigits(const std::string& id, char code)
{
auto call = getSipCall(id);
if (!call)
return;
const std::string accountID(call->getAccountId());
SIPAccount *account = Manager::instance().getSipAccount(accountID);
if (!account)
return;
dtmfSend(*call, code, account->getDtmfType());
}
bool
SIPVoIPLink::SIPStartCall(std::shared_ptr<SIPCall>& call)
{
......
......@@ -159,13 +159,6 @@ class SIPVoIPLink : public VoIPLink {
const std::string& toUrl,
const std::string &account_id);
/**
* Send DTMF refering to account configuration
* @param id The call identifier
* @param code The char code
*/
virtual void carryingDTMFdigits(const std::string& id, char code);
/**
* Tell the user that the call was answered
* @param
......
......@@ -93,13 +93,6 @@ class VoIPLink {
*/
virtual std::vector<std::shared_ptr<Call> > getCalls(const std::string &account_id) const = 0;
/**
* Send DTMF
* @param id The call identifier
* @param code The char code
*/
virtual void carryingDTMFdigits(const std::string &id, char code) = 0;
/**
* Send a message to a call identified by its callid
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment