From 0a51c441700be676a20353a72f019d13673ab0fb Mon Sep 17 00:00:00 2001 From: Henri Herscher Date: Tue, 20 Jun 2006 20:21:27 +0000 Subject: Changed the Filter interface so that filters can also receive capture events, not just audio chunks. git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@267 09dcff7a-b715-0410-9601-b79a96267cd0 --- orkaudio/audiocaptureplugins/voip/VoIp.cpp | 18 ++++++++++++++---- orkaudio/filters/rtpmixer/RtpMixer.cpp | 28 ++++++++++++++++++---------- orkbasecxx/Filter.cpp | 19 +++++++++++++++++++ orkbasecxx/Filter.h | 6 ++++++ 4 files changed, 57 insertions(+), 14 deletions(-) diff --git a/orkaudio/audiocaptureplugins/voip/VoIp.cpp b/orkaudio/audiocaptureplugins/voip/VoIp.cpp index f925a21..9df7a8b 100644 --- a/orkaudio/audiocaptureplugins/voip/VoIp.cpp +++ b/orkaudio/audiocaptureplugins/voip/VoIp.cpp @@ -453,12 +453,22 @@ void HandlePacket(u_char *param, const struct pcap_pkthdr *header, const u_char IpHeaderStruct* ipHeader = (IpHeaderStruct*)((char*)ethernetHeader + sizeof(EthernetHeaderStruct)); if(ipHeader->ip_v != 4) // sanity check, is it an IP packet v4 { - // If not, the IP packet might be wrapped into a 802.1Q VLAN or MPLS header (add 4 bytes) - ipHeader = (IpHeaderStruct*)((u_char*)ipHeader+4); + // If not, the IP packet might have been captured using the tcpdump -i switch + ipHeader = (IpHeaderStruct*)((u_char*)ipHeader+2); if(ipHeader->ip_v != 4) { - // Still not an IP packet V4, drop it - return; + // If not, the IP packet might be wrapped into a 802.1Q VLAN or MPLS header (add 4 bytes, ie 2 bytes on top of previous 2) + ipHeader = (IpHeaderStruct*)((u_char*)ipHeader+2); + if(ipHeader->ip_v != 4) + { + // If not, the IP packet might be tcpdump -i as well as VLAN, add another 2 bytes + ipHeader = (IpHeaderStruct*)((u_char*)ipHeader+2); + if(ipHeader->ip_v != 4) + { + // Still not an IP packet V4, drop it + return; + } + } } } int ipHeaderLength = ipHeader->ip_hl*4; diff --git a/orkaudio/filters/rtpmixer/RtpMixer.cpp b/orkaudio/filters/rtpmixer/RtpMixer.cpp index f1e1f79..0c1f756 100644 --- a/orkaudio/filters/rtpmixer/RtpMixer.cpp +++ b/orkaudio/filters/rtpmixer/RtpMixer.cpp @@ -32,9 +32,9 @@ extern "C" #include "g711.h" } -#define NUM_SAMPLES_CIRCULAR_BUFFER 8000 -#define NUM_SAMPLES_TRIGGER 4000 // when we have this number of available samples make a shipment -#define NUM_SAMPLES_SHIPMENT_HOLDOFF 2000 // when shipping, ship everything but this number of samples +#define NUM_SAMPLES_CIRCULAR_BUFFER 16000 +#define NUM_SAMPLES_TRIGGER 12000 // when we have this number of available samples make a shipment +#define NUM_SAMPLES_SHIPMENT_HOLDOFF 11000 // when shipping, ship everything but this number of samples class RtpMixer : public Filter @@ -49,6 +49,8 @@ public: AudioEncodingEnum __CDECL__ GetOutputAudioEncoding(); CStdString __CDECL__ GetName(); int __CDECL__ GetInputRtpPayloadType(); + inline void __CDECL__ CaptureEventIn(CaptureEventRef& event) {;} + inline void __CDECL__ CaptureEventOut(CaptureEventRef& event) {;} private: //AudioChunkRef m_outputAudioChunk; @@ -110,12 +112,18 @@ void RtpMixer::AudioChunkIn(AudioChunkRef& chunk) throw (CStdString("RtpMixer input audio must be PCM !")); } + if(m_log->isDebugEnabled()) + { + logMsg.Format("New chunk, timestamp:%d", details->m_timestamp); + LOG4CXX_DEBUG(m_log, logMsg); + } + unsigned int rtpEndTimestamp = details->m_timestamp + chunk->GetNumSamples(); if(m_writeTimestamp == 0) { // First RTP packet of the session - //LOG4CXX_DEBUG(m_log, m_capturePort + " first packet"); + LOG4CXX_DEBUG(m_log, "first chunk"); m_writeTimestamp = details->m_timestamp; m_readTimestamp = m_writeTimestamp; StoreRtpPacket(chunk); @@ -156,7 +164,7 @@ void RtpMixer::AudioChunkIn(AudioChunkRef& chunk) } else { - //LOG4CXX_DEBUG(m_log, m_capturePort + " packet too old, dropped"); + LOG4CXX_DEBUG(m_log, " chunk too old, dropped"); } if(m_log->isDebugEnabled()) { @@ -221,7 +229,7 @@ void RtpMixer::StoreRtpPacket(AudioChunkRef& audioChunk) int silenceSize = endRtpTimestamp - m_writeTimestamp; m_writeTimestamp = endRtpTimestamp; debug.Format("Zeroed %d samples, wr:%x wrts:%u", silenceSize, m_writePtr, m_writeTimestamp); - //LOG4CXX_DEBUG(m_log, debug); + LOG4CXX_DEBUG(m_log, debug); } // 2. Mix in the latest samples from this RTP packet @@ -249,7 +257,7 @@ void RtpMixer::StoreRtpPacket(AudioChunkRef& audioChunk) } } debug.Format("Copied %d samples, tmpwr:%x", audioChunk->GetNumSamples(), tempWritePtr); - //LOG4CXX_DEBUG(m_log, debug); + LOG4CXX_DEBUG(m_log, debug); } short* RtpMixer::CircularPointerAddOffset(short *ptr, size_t offset) @@ -311,7 +319,7 @@ void RtpMixer::CreateShipment(size_t silenceSize) CStdString debug; debug.Format("Ship %d samples, rd:%x rdts:%u", shortSize, m_readPtr, m_readTimestamp); - //LOG4CXX_DEBUG(m_log, debug); + LOG4CXX_DEBUG(m_log, debug); // 2. ship from beginning of buffer until stop ptr @@ -328,7 +336,7 @@ void RtpMixer::CreateShipment(size_t silenceSize) m_readPtr = CircularPointerAddOffset(m_readPtr ,shortSize); m_readTimestamp += shortSize; debug.Format("Ship wrapped %d samples, rd:%x rdts:%u", shortSize, m_readPtr, m_readTimestamp); - //LOG4CXX_DEBUG(m_log, debug); + LOG4CXX_DEBUG(m_log, debug); } // 3. ship silence @@ -348,7 +356,7 @@ void RtpMixer::CreateShipment(size_t silenceSize) m_readTimestamp += silenceSize; } debug.Format("Ship %d silence samples, rd:%x rdts:%u", silenceSize, m_readPtr, m_readTimestamp); - //LOG4CXX_DEBUG(m_log, debug); + LOG4CXX_DEBUG(m_log, debug); } } diff --git a/orkbasecxx/Filter.cpp b/orkbasecxx/Filter.cpp index ae0c2c9..f154148 100644 --- a/orkbasecxx/Filter.cpp +++ b/orkbasecxx/Filter.cpp @@ -156,6 +156,15 @@ int AlawToPcmFilter::GetInputRtpPayloadType() return 0x8; } +void AlawToPcmFilter::CaptureEventIn(CaptureEventRef& event) +{ + ; +} + +void AlawToPcmFilter::CaptureEventOut(CaptureEventRef& event) +{ + ; +} //==================================================================== @@ -225,3 +234,13 @@ int UlawToPcmFilter::GetInputRtpPayloadType() { return 0x0; } + +void UlawToPcmFilter::CaptureEventIn(CaptureEventRef& event) +{ + ; +} + +void UlawToPcmFilter::CaptureEventOut(CaptureEventRef& event) +{ + ; +} \ No newline at end of file diff --git a/orkbasecxx/Filter.h b/orkbasecxx/Filter.h index 3002e7f..557184c 100644 --- a/orkbasecxx/Filter.h +++ b/orkbasecxx/Filter.h @@ -43,6 +43,8 @@ public: /** Input RTP payload time - this is overridden if the filter is a codec that accepts a certain RTP payload type such as GSM. if not, returns -1 by default */ virtual int __CDECL__ GetInputRtpPayloadType(); + virtual void __CDECL__ CaptureEventIn(CaptureEventRef& event) = 0; + virtual void __CDECL__ CaptureEventOut(CaptureEventRef& event) = 0; }; //=================================================================== @@ -56,6 +58,8 @@ public: AudioEncodingEnum __CDECL__ GetOutputAudioEncoding(); CStdString __CDECL__ GetName(); int __CDECL__ GetInputRtpPayloadType(); + void __CDECL__ CaptureEventIn(CaptureEventRef& event); + void __CDECL__ CaptureEventOut(CaptureEventRef& event); private: AudioChunkRef m_outputAudioChunk; @@ -73,6 +77,8 @@ public: AudioEncodingEnum __CDECL__ GetOutputAudioEncoding(); CStdString __CDECL__ GetName(); int __CDECL__ GetInputRtpPayloadType(); + void __CDECL__ CaptureEventIn(CaptureEventRef& event); + void __CDECL__ CaptureEventOut(CaptureEventRef& event); private: AudioChunkRef m_outputAudioChunk; -- cgit v1.2.3