diff options
author | Henri Herscher <henri@oreka.org> | 2006-10-16 15:31:15 +0000 |
---|---|---|
committer | Henri Herscher <henri@oreka.org> | 2006-10-16 15:31:15 +0000 |
commit | 11c5f0f94a71657930d87c067a270991eb875597 (patch) | |
tree | f69a8e9b11ce168e6c16e7798e6a60fe37f0019c /orkaudio/audiocaptureplugins/voip | |
parent | a7f1e318b8cea70aea786580ef9b15e5e3afcd23 (diff) |
Now possible to replay pcap file at normal speed (real-time speed) with <PcapFastReplay> boolean. Also, in fast replay speed, it is now possible to control CPU load with <PcapFastReplaySleepUsPerSec> config parameter.
git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@343 09dcff7a-b715-0410-9601-b79a96267cd0
Diffstat (limited to 'orkaudio/audiocaptureplugins/voip')
-rw-r--r-- | orkaudio/audiocaptureplugins/voip/VoIp.cpp | 56 | ||||
-rw-r--r-- | orkaudio/audiocaptureplugins/voip/VoIpConfig.cpp | 5 | ||||
-rw-r--r-- | orkaudio/audiocaptureplugins/voip/VoIpConfig.h | 2 |
3 files changed, 51 insertions, 12 deletions
diff --git a/orkaudio/audiocaptureplugins/voip/VoIp.cpp b/orkaudio/audiocaptureplugins/voip/VoIp.cpp index 2b9e02a..4ec6d5b 100644 --- a/orkaudio/audiocaptureplugins/voip/VoIp.cpp +++ b/orkaudio/audiocaptureplugins/voip/VoIp.cpp @@ -51,6 +51,8 @@ static LoggerPtr s_skinnyPacketLog; static LoggerPtr s_sipExtractionLog; static LoggerPtr s_voipPluginLog; static time_t s_lastHooveringTime; +static time_t s_lastPause; +static time_t s_lastPacketTimestamp; static ACE_Thread_Mutex s_mutex; static ACE_Thread_Semaphore s_replaySemaphore; int s_replayThreadCounter; @@ -527,20 +529,50 @@ void HandlePacket(u_char *param, const struct pcap_pkthdr *header, const u_char int ipHeaderLength = ipHeader->ip_hl*4; u_char* ipPacketEnd = (u_char*)ipHeader + ntohs(ipHeader->ip_len); + time_t now = time(NULL); + #ifdef WIN32 if(!s_liveCapture) { - // This is a pcap file replay, make sure Orkaudio won't be flooded by too many - // packets at a time by yielding control to other threads. - //ACE_Time_Value yield; - //yield.set(0,1); // 1 us - //ACE_OS::sleep(yield); - - // Use nanosleep instead - struct timespec ts; - ts.tv_sec = 0; - ts.tv_nsec = 1; - ACE_OS::nanosleep (&ts, NULL); + // This is a pcap file replay + if(DLLCONFIG.m_pcapFastReplay) + { + if((now - s_lastPause) > 1) + { + if(DLLCONFIG.m_pcapFastReplaySleepUsPerSec > 0) + { + ACE_Time_Value yield; + yield.set(0,DLLCONFIG.m_pcapFastReplaySleepUsPerSec * 1000); + ACE_OS::sleep(yield); + } + s_lastPause = now; + } + else + { + // Make sure Orkaudio won't be flooded by too many + // packets at a time by yielding control to other threads. + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = 1; + ACE_OS::nanosleep (&ts, NULL); + } + } + else + { + // Simulate normal ("real-time") replay speed: + // Every capture-second, wait for the local clock to elapse a second. + if(header->ts.tv_sec != s_lastPacketTimestamp) + { + while(now == time(NULL)) + { + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = 5000000; // 5 ms + ACE_OS::nanosleep (&ts, NULL); + } + s_lastPacketTimestamp = header->ts.tv_sec; + } + } } #endif @@ -604,7 +636,6 @@ void HandlePacket(u_char *param, const struct pcap_pkthdr *header, const u_char } } - time_t now = time(NULL); if((now - s_lastHooveringTime) > 5) { s_lastHooveringTime = now; @@ -774,6 +805,7 @@ void VoIp::OpenDevices() pcap_if_t* devices = NULL; pcap_if_t* defaultDevice = NULL; s_lastHooveringTime = time(NULL); + s_lastPause = time(NULL); CStdString logMsg; diff --git a/orkaudio/audiocaptureplugins/voip/VoIpConfig.cpp b/orkaudio/audiocaptureplugins/voip/VoIpConfig.cpp index 17e64c0..eeab1b8 100644 --- a/orkaudio/audiocaptureplugins/voip/VoIpConfig.cpp +++ b/orkaudio/audiocaptureplugins/voip/VoIpConfig.cpp @@ -28,6 +28,8 @@ VoIpConfig::VoIpConfig() m_sipDropIndirectInvite = false; m_pcapRepeat = false; m_pcapSocketBufferSize = 0; + m_pcapFastReplay = true; + m_pcapFastReplaySleepUsPerSec = 0; } void VoIpConfig::Define(Serializer* s) @@ -43,8 +45,11 @@ void VoIpConfig::Define(Serializer* s) s->StringValue("PcapFile", m_pcapFile); s->StringValue("PcapDirectory", m_pcapDirectory); s->BoolValue("PcapRepeat", m_pcapRepeat); + s->BoolValue("PcapFastReplay", m_pcapFastReplay); + s->IntValue("PcapFastReplaySleepUsPerSec", m_pcapFastReplaySleepUsPerSec); s->BoolValue("SipDropIndirectInvite", m_sipDropIndirectInvite); s->IntValue("PcapSocketBufferSize", m_pcapSocketBufferSize); + } void VoIpConfig::Validate() diff --git a/orkaudio/audiocaptureplugins/voip/VoIpConfig.h b/orkaudio/audiocaptureplugins/voip/VoIpConfig.h index 33821ac..4ecd2c7 100644 --- a/orkaudio/audiocaptureplugins/voip/VoIpConfig.h +++ b/orkaudio/audiocaptureplugins/voip/VoIpConfig.h @@ -58,6 +58,8 @@ public: bool m_pcapRepeat; bool m_sipDropIndirectInvite; int m_pcapSocketBufferSize; + bool m_pcapFastReplay; + int m_pcapFastReplaySleepUsPerSec; }; //======================================== |