diff options
author | Henri Herscher <henri@oreka.org> | 2005-12-14 16:38:53 +0000 |
---|---|---|
committer | Henri Herscher <henri@oreka.org> | 2005-12-14 16:38:53 +0000 |
commit | 3cdcd8d2e5bb825d774b461c650cf4af966e06a9 (patch) | |
tree | db180f6abebc55898b996c409ed0c4c7d18e07a8 | |
parent | 7e49c9f57ce23cefe98f0655c502277e12e2a8b8 (diff) |
Added tracking ID to RTP sessions
git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@108 09dcff7a-b715-0410-9601-b79a96267cd0
-rw-r--r-- | orkaudio/audiocaptureplugins/voip/RtpSession.cpp | 33 | ||||
-rw-r--r-- | orkaudio/audiocaptureplugins/voip/RtpSession.h | 5 | ||||
-rw-r--r-- | orkbasecxx/Utils.h | 44 |
3 files changed, 64 insertions, 18 deletions
diff --git a/orkaudio/audiocaptureplugins/voip/RtpSession.cpp b/orkaudio/audiocaptureplugins/voip/RtpSession.cpp index e7e9d4c..0273d88 100644 --- a/orkaudio/audiocaptureplugins/voip/RtpSession.cpp +++ b/orkaudio/audiocaptureplugins/voip/RtpSession.cpp @@ -28,8 +28,9 @@ extern VoIpConfigTopObjectRef g_VoIpConfigTopObjectRef; #define DLLCONFIG g_VoIpConfigTopObjectRef.get()->m_config -RtpSession::RtpSession() +RtpSession::RtpSession(CStdString& trackingId) { + m_trackingId = trackingId; m_lastUpdated = time(NULL); m_log = Logger::getLogger("rtpsession"); m_invitorIp.s_addr = 0; @@ -47,7 +48,7 @@ void RtpSession::Stop() { if(m_started) { - LOG4CXX_INFO(m_log, m_capturePort + " Session stop"); + LOG4CXX_INFO(m_log, m_trackingId + ": " + m_capturePort + " Session stop"); CaptureEventRef stopEvent(new CaptureEvent); stopEvent->m_type = CaptureEvent::EtStop; stopEvent->m_timestamp = time(NULL); @@ -58,7 +59,7 @@ void RtpSession::Stop() void RtpSession::Start() { m_started = true; - LOG4CXX_INFO(m_log, m_capturePort + " " + ProtocolToString(m_protocol) + " Session start"); + LOG4CXX_INFO(m_log, m_trackingId + ": " + m_capturePort + " " + ProtocolToString(m_protocol) + " Session start"); m_rtpRingBuffer.SetCapturePort(m_capturePort); CaptureEventRef startEvent(new CaptureEvent); startEvent->m_type = CaptureEvent::EtStart; @@ -157,7 +158,7 @@ void RtpSession::ProcessMetadataSip(RtpPacketInfoRef& rtpPacket) } else { - LOG4CXX_DEBUG(m_log, m_ipAndPort + " alien RTP packet"); + LOG4CXX_ERROR(m_log, m_trackingId + ": " + m_ipAndPort + " alien RTP packet"); } // work out capture port and direction @@ -264,7 +265,7 @@ void RtpSession::AddRtpPacket(RtpPacketInfoRef& rtpPacket) if(m_log->isInfoEnabled()) { rtpPacket->ToString(logMsg); - logMsg = "1st packet s1: " + logMsg; + logMsg = m_trackingId + ": " + "1st packet s1: " + logMsg; LOG4CXX_INFO(m_log, logMsg); } } @@ -282,7 +283,7 @@ void RtpSession::AddRtpPacket(RtpPacketInfoRef& rtpPacket) if(m_log->isInfoEnabled()) { rtpPacket->ToString(logMsg); - logMsg = "1st packet s2: " + logMsg; + logMsg = m_trackingId + ": " + "1st packet s2: " + logMsg; LOG4CXX_INFO(m_log, logMsg); } } @@ -302,7 +303,7 @@ void RtpSession::AddRtpPacket(RtpPacketInfoRef& rtpPacket) if(m_log->isDebugEnabled()) { CStdString timestampOffsetString = IntToString(timestampOffset); - LOG4CXX_DEBUG(m_log, m_capturePort + ": " + "Applying timestamp corrective offset:" + timestampOffsetString); + LOG4CXX_DEBUG(m_log, m_trackingId + ": " + m_capturePort + ": " + "Applying timestamp corrective offset:" + timestampOffsetString); } } } @@ -316,7 +317,7 @@ void RtpSession::AddRtpPacket(RtpPacketInfoRef& rtpPacket) if(m_log->isDebugEnabled()) { CStdString debug; - debug.Format("%s: Add RTP packet ts:%u arrival:%u", m_capturePort, rtpPacket->m_timestamp, rtpPacket->m_arrivalTimestamp); + debug.Format("%s: %s: Add RTP packet ts:%u arrival:%u", m_trackingId, m_capturePort, rtpPacket->m_timestamp, rtpPacket->m_arrivalTimestamp); LOG4CXX_DEBUG(m_log, debug); } @@ -413,7 +414,7 @@ void RtpSessions::ReportSipInvite(SipInviteInfoRef& invite) } // create new session and insert into both maps - RtpSessionRef session(new RtpSession()); + RtpSessionRef session(new RtpSession(alphaCounter.GetNext())); session->m_ipAndPort = ipAndPort; session->m_callId = invite->m_callId; session->m_protocol = RtpSession::ProtSip; @@ -448,7 +449,7 @@ void RtpSessions::ReportSkinnyCallInfo(SkCallInfoStruct* callInfo) } // create new session and insert into the callid map - RtpSessionRef session(new RtpSession()); + RtpSessionRef session(new RtpSession(alphaCounter.GetNext())); session->m_callId = callId; session->m_protocol = RtpSession::ProtSkinny; switch(callInfo->callType) @@ -604,9 +605,9 @@ void RtpSessions::ReportRtpPacket(RtpPacketInfoRef& rtpPacket) if(m_log->isInfoEnabled()) { CStdString debug; - debug.Format("Merging session % with callid:%s into session %s with callid:%s", - mergeeSession->m_ipAndPort, mergeeSession->m_callId, - mergerSession->m_ipAndPort, mergerSession->m_callId); + debug.Format("Merging session %s %s with callid:%s into session %s %s with callid:%s", + mergeeSession->m_trackingId, mergeeSession->m_ipAndPort, mergeeSession->m_callId, + mergerSession->m_trackingId, mergerSession->m_ipAndPort, mergerSession->m_callId); LOG4CXX_INFO(m_log, debug); } Stop(mergeeSession); @@ -615,7 +616,7 @@ void RtpSessions::ReportRtpPacket(RtpPacketInfoRef& rtpPacket) if(numSessionsFound == 0) { // create new Raw RTP session and insert into IP+Port map - RtpSessionRef session(new RtpSession()); + RtpSessionRef session(new RtpSession(alphaCounter.GetNext())); session->m_protocol = RtpSession::ProtRawRtp; session->m_ipAndPort = ipAndPort; m_byIpAndPort.insert(std::make_pair(ipAndPort, session)); @@ -644,7 +645,7 @@ void RtpSessions::Hoover(time_t now) for (std::list<RtpSessionRef>::iterator it = toDismiss.begin(); it != toDismiss.end() ; it++) { RtpSessionRef session = *it; - LOG4CXX_DEBUG(m_log, session->m_ipAndPort + " Expired"); + LOG4CXX_DEBUG(m_log, session->m_trackingId + ": " + session->m_ipAndPort + " Expired"); Stop(session); } @@ -663,7 +664,7 @@ void RtpSessions::Hoover(time_t now) for (std::list<RtpSessionRef>::iterator it2 = toDismiss.begin(); it2 != toDismiss.end() ; it2++) { RtpSessionRef session = *it2; - LOG4CXX_DEBUG(m_log, session->m_ipAndPort + " Expired"); + LOG4CXX_DEBUG(m_log, session->m_trackingId + ": " + session->m_ipAndPort + " Expired"); Stop(session); } } diff --git a/orkaudio/audiocaptureplugins/voip/RtpSession.h b/orkaudio/audiocaptureplugins/voip/RtpSession.h index 8ea84b7..41a25bd 100644 --- a/orkaudio/audiocaptureplugins/voip/RtpSession.h +++ b/orkaudio/audiocaptureplugins/voip/RtpSession.h @@ -74,12 +74,13 @@ public: static int ProtocolToEnum(CStdString& protocol); static CStdString ProtocolToString(int protocolEnum); - RtpSession(); + RtpSession(CStdString& trackingId); void Stop(); void Start(); void AddRtpPacket(RtpPacketInfoRef& rtpPacket); void ReportSipInvite(SipInviteInfoRef& invite); + CStdString m_trackingId; CStdString m_ipAndPort; // IP address and TCP port of one side of the session, serves as a key for session storage and retrieval. Not necessarily the same as the capturePort (capturePort is usually the client (phone) IP+port) CStdString m_callId; SipInviteInfoRef m_invite; @@ -117,7 +118,6 @@ class RtpSessions { public: RtpSessions(); - void Create(CStdString& ipAndPort); void Stop(RtpSessionRef& session); void ReportSipInvite(SipInviteInfoRef& invite); void ReportSipBye(SipByeInfo bye); @@ -130,6 +130,7 @@ private: std::map<CStdString, RtpSessionRef> m_byIpAndPort; std::map<CStdString, RtpSessionRef> m_byCallId; LoggerPtr m_log; + AlphaCounter alphaCounter; }; typedef ACE_Singleton<RtpSessions, ACE_Thread_Mutex> RtpSessionsSingleton; diff --git a/orkbasecxx/Utils.h b/orkbasecxx/Utils.h index b50872a..dcd22f2 100644 --- a/orkbasecxx/Utils.h +++ b/orkbasecxx/Utils.h @@ -19,6 +19,8 @@ // error C2039: 'TryEnterCriticalSection' : is not a member of '`global namespace'' // If seeing this error somewhere, the remedy is to #include "Utils.h" first #include "ace/Thread_Mutex.h" +#include "ace/OS_NS_stdlib.h" +#include "ace/OS_NS_time.h" #include "StdString.h" #include "OrkBase.h" @@ -93,5 +95,47 @@ inline CStdString StripFileExtension(CStdString& filename) typedef ACE_Guard<ACE_Thread_Mutex> MutexSentinel; +/** A counter that generates a "counting" 3 character strings, i.e. aaa, aab, ..., zzz + that represents a number between 0 and 26^3-1 (wrapping counter) + and starts at a random location in this range. + useful for generating debugging IDs +*/ +class AlphaCounter +{ +public: + inline AlphaCounter::AlphaCounter() + { + // Generate pseudo-random number from high resolution time least significant two bytes + ACE_hrtime_t hrtime = ACE_OS::gethrtime(); + unsigned short srandom = (short)hrtime; + double drandom = (double)srandom/65536.0; // 0 <= random < 1 + + m_counter = (unsigned int)(drandom*(26*26*26)); + } + + inline CStdString AlphaCounter::GetNext() + { + m_counter++; + if(m_counter >= (26*26*26) ) + { + m_counter = 0; + } + unsigned int char1val = m_counter/(26*26); + unsigned int remains = m_counter%(26*26); + unsigned int char2val = remains/26; + unsigned int char3val = remains%26; + + char1val += 65; + char2val += 65; + char3val += 65; + + CStdString string; + string.Format("%c%c%c", char1val, char2val, char3val); + return string; + } +private: + unsigned int m_counter; +}; + #endif |