From 8278fd69bdca293e4e8a094dcdb7d985c97f3b7d Mon Sep 17 00:00:00 2001 From: Gerald Begumisa Date: Tue, 11 Nov 2008 17:40:24 +0000 Subject: Enhanced the audio segmentation feature such that it may be used on other feeds apart from continuous streams. This means it now works correctly with VoIP or TDM feeds git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@569 09dcff7a-b715-0410-9601-b79a96267cd0 --- orkbasecxx/CapturePluginProxy.cpp | 26 ++++++++++++++++++++++- orkbasecxx/CapturePort.cpp | 43 +++++++++++++++++++++++++++++++++++++++ orkbasecxx/CapturePort.h | 5 +++++ 3 files changed, 73 insertions(+), 1 deletion(-) (limited to 'orkbasecxx') diff --git a/orkbasecxx/CapturePluginProxy.cpp b/orkbasecxx/CapturePluginProxy.cpp index fbfc3da..925c14a 100644 --- a/orkbasecxx/CapturePluginProxy.cpp +++ b/orkbasecxx/CapturePluginProxy.cpp @@ -217,7 +217,31 @@ void __CDECL__ CapturePluginProxy::CaptureEventCallBack(CaptureEventRef eventRef { if (eventRef->m_type == CaptureEvent::EtStart || eventRef->m_type == CaptureEvent::EtStop) { - LOG4CXX_ERROR(LOG.portLog, "#" + capturePort + ": received start or stop while in VAD or audio segmentation mode"); + if(CONFIG.m_audioSegmentation == true) + { + // find the right port and give it the event + // If this is EtStop, we clear the event cache + CapturePortRef portRef = CapturePortsSingleton::instance()->AddAndReturnPort(capturePort); + if(eventRef->m_type == CaptureEvent::EtStop) + { + portRef->ClearEventQueue(); + } + portRef->AddCaptureEvent(eventRef); + } + else + { + LOG4CXX_ERROR(LOG.portLog, "#" + capturePort + ": received start or stop while in VAD mode"); + } + } + else + { + if(CONFIG.m_audioSegmentation == true) + { + // find the right port and give it the event + CapturePortRef portRef = CapturePortsSingleton::instance()->AddAndReturnPort(capturePort); + portRef->QueueCaptureEvent(eventRef); + portRef->AddCaptureEvent(eventRef); + } } } else diff --git a/orkbasecxx/CapturePort.cpp b/orkbasecxx/CapturePort.cpp index b07a6c2..24b2ce4 100644 --- a/orkbasecxx/CapturePort.cpp +++ b/orkbasecxx/CapturePort.cpp @@ -31,6 +31,7 @@ CapturePort::CapturePort(CStdString& id) m_capturing = false; m_lastUpdated = 0; m_needSendStop = false; + m_segmentNumber = 0; LoadFilters(); } @@ -89,6 +90,44 @@ void CapturePort::FilterCaptureEvent(CaptureEventRef& eventRef) } } +void CapturePort::QueueCaptureEvent(CaptureEventRef& eventRef) +{ + m_captureEvents.push_back(eventRef); +} + +void CapturePort::ClearEventQueue() +{ + m_captureEvents.clear(); +} + +void CapturePort::ReportEventBacklog(AudioTapeRef& audioTape) +{ + std::list::iterator it; + + for(it = m_captureEvents.begin(); it != m_captureEvents.end(); it++) + { + CaptureEventRef eventRef = *it; + + if(eventRef->m_type == CaptureEvent::EtOrkUid) + { + CStdString newOrkUid; + CaptureEventRef eventRef2(new CaptureEvent()); + + m_segmentNumber += 1; + newOrkUid.Format("%s_%d", eventRef->m_value, m_segmentNumber); + + eventRef2->m_type = CaptureEvent::EtOrkUid; + eventRef2->m_value = newOrkUid; + + AddCaptureEvent(eventRef2); + } + else + { + AddCaptureEvent(eventRef); + } + } +} + void CapturePort::AddAudioChunk(AudioChunkRef chunkRef) { FilterAudioChunk(chunkRef); @@ -114,8 +153,10 @@ void CapturePort::AddAudioChunk(AudioChunkRef chunkRef) // signal new tape start event eventRef.reset(new CaptureEvent); eventRef->m_type = CaptureEvent::EtStart; + eventRef->m_value = m_id; eventRef->m_timestamp = now; AddCaptureEvent(eventRef); + ReportEventBacklog(m_audioTapeRef); } } else @@ -127,7 +168,9 @@ void CapturePort::AddAudioChunk(AudioChunkRef chunkRef) CaptureEventRef eventRef(new CaptureEvent); eventRef->m_type = CaptureEvent::EtStart; eventRef->m_timestamp = now; + eventRef->m_value = m_id; AddCaptureEvent(eventRef); + ReportEventBacklog(m_audioTapeRef); } } else if (CONFIG.m_vad) diff --git a/orkbasecxx/CapturePort.h b/orkbasecxx/CapturePort.h index 20bbfe8..3b72f6f 100644 --- a/orkbasecxx/CapturePort.h +++ b/orkbasecxx/CapturePort.h @@ -41,11 +41,14 @@ public: void AddCaptureEvent(CaptureEventRef eventRef); bool IsExpired(time_t now); void Finalize(); + void QueueCaptureEvent(CaptureEventRef& eventRef); + void ClearEventQueue(); private: void LoadFilters(); void FilterAudioChunk(AudioChunkRef& chunkRef); void FilterCaptureEvent(CaptureEventRef& eventRef); + void ReportEventBacklog(AudioTapeRef& audioTape); CStdString m_id; AudioTapeRef m_audioTapeRef; @@ -55,7 +58,9 @@ private: bool m_vadUp; time_t m_lastUpdated; std::list m_filters; + std::list m_captureEvents; bool m_needSendStop; + int m_segmentNumber; }; typedef boost::shared_ptr CapturePortRef; -- cgit v1.2.3