Skip to content

Commit

Permalink
Merge pull request #13 from voiceip/new
Browse files Browse the repository at this point in the history
Merge upstream changes
  • Loading branch information
kingster authored Dec 3, 2019
2 parents 01191c0 + f3dc447 commit 0302d8b
Show file tree
Hide file tree
Showing 47 changed files with 761 additions and 348 deletions.
5 changes: 5 additions & 0 deletions orkaudio/audiocaptureplugins/common/AcpConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ void AcpConfig::Reset() {
m_rtpS1S2MappingDeterministicS1IsLocal = true;

m_asciiMediaGateways.clear();
m_ctiDrivenEnable = false;
m_ctiDrivenMatchingTimeoutSec = 30;
}

void AcpConfig::Define(Serializer* s) {
Expand All @@ -33,6 +35,9 @@ void AcpConfig::Define(Serializer* s) {
s->BoolValue("RtpS1S2MappingDeterministicS1IsLocal", m_rtpS1S2MappingDeterministicS1IsLocal);

s->CsvValue("MediaGateways", m_asciiMediaGateways);
s->BoolValue("CtiDrivenEnable", m_ctiDrivenEnable);
s->IntValue("CtiDrivenMatchingTimeoutSec",m_ctiDrivenMatchingTimeoutSec);
s->CsvValue("CtiDrivenMatchingCriteria", m_ctiDrivenMatchingCriteria);
}

void AcpConfig::Validate() {
Expand Down
3 changes: 3 additions & 0 deletions orkaudio/audiocaptureplugins/common/AcpConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class AcpConfig : public Object

bool IsMediaGateway(struct in_addr);
std::list<unsigned int> m_mediaGateways;
bool m_ctiDrivenEnable;
int m_ctiDrivenMatchingTimeoutSec;
std::list<CStdString> m_ctiDrivenMatchingCriteria;
};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ DLL_EXPORT void __CDECL__ PauseCapture(CStdString& party, CStdString& orkuid, C
DLL_EXPORT void __CDECL__ SetOnHold(CStdString& port, CStdString& orkuid);
DLL_EXPORT void __CDECL__ SetOffHold(CStdString& port, CStdString& orkuid);
DLL_EXPORT void __CDECL__ GetConnectionStatus(CStdString& msg);
DLL_EXPORT void __CDECL__ ProcessMetadataMsg(SyncMessage* msg);
}

#endif
19 changes: 12 additions & 7 deletions orkaudio/audiocaptureplugins/common/DtmfHandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,6 @@ void ReportDtmfDigit(OrkSession* ss, int channel, CStdString digitValue, unsign

CStdString ods = ss->m_config->m_onDemandViaDtmfDigitsString;

if(ss->m_keepRtp == false && ods.length() > 0 && ss->m_dtmfDigitString.find(ods) != std::string::npos) {
LOG4CXX_INFO(getLog(), "[" + ss->m_trackingId + "] Trigger OnDemand via DTMF");
ss->TriggerOnDemandViaDtmf();
ss->m_dtmfDigitString.clear();
}

if(ss->m_keepRtp == true && ss->m_config->m_onDemandPauseViaDtmfDigitsString.length() > 0)
{
if(ss->m_dtmfDigitString.find(ss->m_config->m_onDemandPauseViaDtmfDigitsString) != std::string::npos)
Expand All @@ -152,6 +146,12 @@ void ReportDtmfDigit(OrkSession* ss, int channel, CStdString digitValue, unsign
}
}

if(ss->m_onDemand == false && ods.length() > 0 && ss->m_dtmfDigitString.find(ods) != std::string::npos) {
LOG4CXX_INFO(getLog(), "[" + ss->m_trackingId + "] Trigger OnDemand via DTMF");
ss->TriggerOnDemandViaDtmf();
ss->m_dtmfDigitString.clear();
}


int rtpEvent = DtmfDigitToEnum(digitValue);
CStdString dtmfEventString, dtmfEventKey;
Expand Down Expand Up @@ -184,10 +184,15 @@ void ReportDtmfDigit(OrkSession* ss, int channel, CStdString digitValue, unsign
g_captureEventCallBack(event, ss->m_capturePort);
}

CStdString dtmfDigitEventValue = digitValue;
if(CONFIG.m_dtmfReportingDetailed == true) {
dtmfDigitEventValue.Format("%s_%d_%d",digitValue,digitVolume,digitDuration);
}

event.reset(new CaptureEvent());
event->m_type = CaptureEvent::EtKeyValue;
event->m_key = "dtmfdigit";
event->m_value = digitValue;
event->m_value = dtmfDigitEventValue;
event->m_offsetMs = msDiff;
g_captureEventCallBack(event, ss->m_capturePort);
}
Expand Down
87 changes: 87 additions & 0 deletions orkaudio/audiocaptureplugins/common/OrkSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
//#include "winsock2.h"
#endif
#include "OrkSession.h"
#include "LogManager.h"
#include "ConfigManager.h"


static LoggerPtr getLog() {
static LoggerPtr s_log = Logger::getLogger("orksession");
return s_log;
}


bool OrkSession::ShouldSwapChannels()
{
Expand Down Expand Up @@ -42,3 +51,81 @@ bool OrkSession::ShouldSwapChannels()

return false;
}

void OrkSession::Start() {
}

void OrkSession::ReportMetadata() {
}

// ==========================================================================
//
// DetectChannel (RtpPacketInfoRef& rtpPacket)
//
// Detects and returns the correct channel number for the rtp packet
// it starts the session if session is set to start with the first s2.
//
// =========================================================================

int OrkSession::DetectChannel(RtpPacketInfoRef& rtpPacket, bool* pIsFirstPacket)
{
CStdString logMsg;

if (pIsFirstPacket)
{
*pIsFirstPacket = false;
}

if(m_lastRtpPacketSide1.get() == NULL)
{
// First RTP packet for side 1
m_lastRtpPacketSide1 = rtpPacket;

if(getLog()->isInfoEnabled())
{
rtpPacket->ToString(logMsg);
logMsg = "[" + m_trackingId + "] 1st packet s1: " + logMsg;
LOG4CXX_INFO(getLog(), logMsg);
}
if (pIsFirstPacket)
{
*pIsFirstPacket = true;
}
return 1;
}
else if( rtpPacket->m_ssrc == m_lastRtpPacketSide1->m_ssrc && m_lastRtpPacketSide1->m_destIp.s_addr == rtpPacket->m_destIp.s_addr ) {
return 1;
}

if(m_lastRtpPacketSide2.get() == NULL)
{
// First RTP packet for side 2
m_lastRtpPacketSide2 = rtpPacket;

if(getLog()->isInfoEnabled())
{
rtpPacket->ToString(logMsg);
logMsg = "[" + m_trackingId + "] 1st packet s2: " + logMsg;
LOG4CXX_INFO(getLog(), logMsg);
}
if (CONFIG.m_discardUnidirectionalCalls && m_startWhenReceiveS2)
{
Start();
ReportMetadata();
if (CONFIG.m_lookBackRecording == false)
{
m_nonLookBackSessionStarted = true;
}
}
if (pIsFirstPacket)
{
*pIsFirstPacket = true;
}
return 2;
}
else if(rtpPacket->m_ssrc == m_lastRtpPacketSide2->m_ssrc && m_lastRtpPacketSide2->m_destIp.s_addr == rtpPacket->m_destIp.s_addr) {
return 2;
}

return 0;
}
26 changes: 25 additions & 1 deletion orkaudio/audiocaptureplugins/common/OrkSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,58 @@ class OrkSession {
m_config(config),

m_keepRtp(true),
m_onDemand(false),
m_startWhenReceiveS2(false),
m_nonLookBackSessionStarted(false),

// DTMF related
m_dtmfDigitString(""),
m_currentRtpEventTs(0),
m_telephoneEventPayloadType(config->m_rtpEventPayloadTypeDefaultValue)
{}
{
for (int i = 0; i < 32; i++) m_orekaRtpPayloadTypeMap[i] = i+96;
}

CStdString m_capturePort;
CStdString m_trackingId;
time_t m_beginDate; // When the session has seen a few RTP packets

int DetectChannel(RtpPacketInfoRef& rtpPacket, bool* pIsFirstPacket=NULL ) ;

CStdString m_dtmfDigitString;
unsigned int m_currentRtpEventTs;
int m_telephoneEventPayloadType;

virtual void TriggerOnDemandViaDtmf()=0;
virtual void Start();
virtual void ReportMetadata();

AcpConfig * m_config;

bool m_keepRtp;
bool m_onDemand;
CStdString m_logMsg;
bool m_startWhenReceiveS2;
bool m_nonLookBackSessionStarted;

RtpPacketInfoRef m_lastRtpPacketSide1;
RtpPacketInfoRef m_lastRtpPacketSide2;
bool ShouldSwapChannels();
struct in_addr m_localIp;
bool m_mappedS1S2;
unsigned char m_orekaRtpPayloadTypeMap[32];

void UpdateRtpPayloadMap(unsigned char *map)
{
for (int i = 0; i < 32; i++)
{
// The map we're passed is an array of 32 payload types.
// each entry is 0 if it hasn't been seen in the SDP, and
// will otherwise be the internal Oreka RTP payload type
// as used in BatchProcessing
if (map[i]) m_orekaRtpPayloadTypeMap[i] = map[i];
}
}
};
typedef oreka::shared_ptr<OrkSession> OrkSessionRef;

Expand Down
32 changes: 32 additions & 0 deletions orkaudio/audiocaptureplugins/voip/ParsingUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,35 @@ void GrabLineSkipLeadingWhitespace(char* start, char* limit, CStdString& out)

GrabLine(c, limit, out);
}

void GetDynamicPayloadMapping(char* start, char* stop, unsigned char* map)
{
CStdString rtpmap = "a=rtpmap:";
char* rtpmapPos;
rtpmapPos = memFindStr(rtpmap, start, stop);
while(rtpmapPos != NULL)
{
CStdString fullLine, plStr;
int plType = -1;
GrabTokenAcceptSpace(rtpmapPos, stop, fullLine);
GrabToken(rtpmapPos + rtpmap.length(), stop, plStr);
if(plStr.length() > 0)
{
plType = StringToInt(plStr);
}
if(plType > 95 && plType < 127)
{
int orekaPayloadType = GetOrekaRtpPayloadTypeForSdpRtpMap(fullLine);
if(orekaPayloadType && orekaPayloadType != map[plType-96])
{
map[plType-96] = orekaPayloadType; //remaps payload type to internal value
}
}

rtpmapPos = memFindStr(rtpmap, rtpmapPos + fullLine.length(), stop);
}

}



1 change: 1 addition & 0 deletions orkaudio/audiocaptureplugins/voip/ParsingUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ void GrabSipUriUser(char* in, char* limit, CStdString& out);
void GrabString(char* start, char* stop, CStdString& out);
char* GrabLine(char* start, char* limit, CStdString& out);
void GrabLineSkipLeadingWhitespace(char* start, char* limit, CStdString& out);
void GetDynamicPayloadMapping(char* start, char* stop, unsigned char* map);

#endif
2 changes: 1 addition & 1 deletion orkaudio/audiocaptureplugins/voip/SipHeaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SipInviteInfo::SipInviteInfo() : m_telephoneEventPayloadType(0)
m_validated = false;
m_attrSendonly = false;
m_SipGroupPickUpPatternDetected = false;
m_orekaRtpPayloadType = 0;
memset(m_orekaRtpPayloadTypeMap, 0, sizeof(m_orekaRtpPayloadTypeMap));
}

void SipInviteInfo::ToString(CStdString& string)
Expand Down
7 changes: 6 additions & 1 deletion orkaudio/audiocaptureplugins/voip/SipHeaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ class SipInviteInfo
CStdString m_contactName;
CStdString m_contactDomain;
bool m_SipGroupPickUpPatternDetected;
int m_orekaRtpPayloadType;
//
// track dynamic RTP payload types present in SDP
// we need 32 bytes to track payload types 96-127.
// value is 0 if payload type is not in the SDP.
// otherwise it will be set to our internal RTP payload type
unsigned char m_orekaRtpPayloadTypeMap[32];

time_t m_recvTime;
};
Expand Down
20 changes: 13 additions & 7 deletions orkaudio/audiocaptureplugins/voip/SipParsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1535,15 +1535,21 @@ bool TrySipInvite(EthernetHeaderStruct* ethernetHeader, IpHeaderStruct* ipHeader
}
}

//Determine the being used codec: should be the first rtpmap
if(sipMethod == SIP_METHOD_200_OK || sipMethod == SIP_RESPONSE_SESSION_PROGRESS)
rtpmapAttribute = memFindAfter("\na=rtpmap:", (char*)audioSdpStart, audioSdpEnd);
if(rtpmapAttribute)
{
rtpmapAttribute = memFindAfter("\na=rtpmap:", (char*)audioSdpStart, audioSdpEnd);
if(rtpmapAttribute)
GetDynamicPayloadMapping(audioSdpStart,audioSdpEnd, info->m_orekaRtpPayloadTypeMap);
if(s_sipExtractionLog->isDebugEnabled())
{
CStdString line;
GrabLineSkipLeadingWhitespace(rtpmapAttribute, sipEnd, line);
info->m_orekaRtpPayloadType = GetOrekaRtpPayloadTypeForSdpRtpMap(line);
logMsg.Format("%s: [%s]: Re-mapped codecs", sipMethod, info->m_callId);
for (int i = 0; i < 32; i++)
{
if (info->m_orekaRtpPayloadTypeMap[i])
{
logMsg.AppendFormat(" %d->%d", i+96, info->m_orekaRtpPayloadTypeMap[i]);
}
}
LOG4CXX_DEBUG(s_sipExtractionLog, logMsg);
}
}

Expand Down
24 changes: 12 additions & 12 deletions orkaudio/audiocaptureplugins/voip/VoIp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class VoIp : public OrkSingleton<VoIp>
void ProcessSkinnyGlobalNumbers(char *line, int ln);
void LoadSkinnyGlobalNumbers();
void GetConnectionStatus(CStdString& msg);
void ProcessMetadataMsg(SyncMessage* msg);

private:
pcap_t* OpenPcapDeviceLive(CStdString name);
Expand Down Expand Up @@ -1020,7 +1021,7 @@ void UdpListenerThread()
CStdString logMsg;

char frameBuffer[65000];
apr_int32_t bufSize = 8388608;
apr_int32_t bufSize = DLLCONFIG.m_udpListenerSocketBufferSize;
apr_status_t ret;
apr_sockaddr_t* sa;
apr_socket_t* socket;
Expand All @@ -1041,17 +1042,7 @@ void UdpListenerThread()
{
LOG4CXX_ERROR(s_packetLog, "UdpListenerThread failed to set timeout");
}
apr_socket_opt_set(socket, APR_SO_RCVBUF, bufSize);
if(ret == APR_SUCCESS)
{
logMsg.Format("Setting UDP listener socket buffer size:%d successful", bufSize);
LOG4CXX_INFO(s_packetLog, logMsg);
}
else
{
logMsg.Format("Setting UDP listener socket buffer size:%d failed", bufSize);
LOG4CXX_ERROR(s_packetLog, logMsg);
}
set_socket_buffer_size(s_packetLog, "UdpListenerThread", socket, bufSize);

struct pcap_pkthdr pcap_headerPtr ;
u_char param;
Expand Down Expand Up @@ -2023,6 +2014,11 @@ void VoIp::GetConnectionStatus(CStdString& msg)
{
msg = "unknown";
}

void VoIp::ProcessMetadataMsg(SyncMessage* msg)
{
;
}
//================================================================================
#ifndef WIN32
void HandleTcpConnection(int clientSock)
Expand Down Expand Up @@ -2285,3 +2281,7 @@ void __CDECL__ GetConnectionStatus(CStdString& msg)
VoIpSingleton::instance()->GetConnectionStatus(msg);
}

void __CDECL__ ProcessMetadataMsg(SyncMessage* msg)
{
VoIpSingleton::instance()->ProcessMetadataMsg(msg);
}
2 changes: 1 addition & 1 deletion orkaudio/audiocaptureplugins/voip/VoIp.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<InlineFunctionExpansion>Default</InlineFunctionExpansion>
<AdditionalIncludeDirectories>C:\DevExtVC12\winpcap\WpdPack\Include;../..;../../../OrkBaseCxx;C:\DevExtVC12\boost\boost_1_32_0;C:\DevExtVC12\ACE_wrappers;C:\DevExtVC12\xerces\src;../Common;C:\DevExtVC12\Log4cxx\log4cxx-0.10.0\src\main\include;C:\DevExtVC12\apr-1.6.3\apr\include;C:\DevExtVC12\apr-1.6.3\apr-util\include;C:\DevExtVC12\openssl\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>C:\DevExtVC12\winpcap\WpdPack\Include;../..;../../../OrkBaseCxx;C:\DevExtVC12\boost\boost_1_32_0;C:\DevExtVC12\xerces\src;../Common;C:\DevExtVC12\Log4cxx\log4cxx-0.10.0\src\main\include;C:\DevExtVC12\apr-1.6.3\apr\include;C:\DevExtVC12\apr-1.6.3\apr-util\include;C:\DevExtVC12\openssl\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>SUPPORTS_CPP11;WIN32;NDEBUG;_WINDOWS;_USRDLL;VoIp_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
Expand Down
Loading

0 comments on commit 0302d8b

Please sign in to comment.