diff options
author | Henri Herscher <henri@oreka.org> | 2007-07-30 14:32:19 +0000 |
---|---|---|
committer | Henri Herscher <henri@oreka.org> | 2007-07-30 14:32:19 +0000 |
commit | 72fda6ebe7d6245b57178441c6355eb9d2402747 (patch) | |
tree | d5683a93b1e4d0efee26995caeeccd55faae0d8c /orkbasecxx/CapturePluginProxy.cpp | |
parent | 483b0c94e1754d01c934dc3421527fc6eefa3ebd (diff) |
Added non-lookback recording mode.
git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@458 09dcff7a-b715-0410-9601-b79a96267cd0
Diffstat (limited to 'orkbasecxx/CapturePluginProxy.cpp')
-rw-r--r-- | orkbasecxx/CapturePluginProxy.cpp | 230 |
1 files changed, 230 insertions, 0 deletions
diff --git a/orkbasecxx/CapturePluginProxy.cpp b/orkbasecxx/CapturePluginProxy.cpp new file mode 100644 index 0000000..fbfc3da --- /dev/null +++ b/orkbasecxx/CapturePluginProxy.cpp @@ -0,0 +1,230 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "CapturePluginProxy.h" +#include "ace/OS_NS_dirent.h" +#include "ace/OS_NS_string.h" +#include "ace/Thread_Manager.h" +#include "ConfigManager.h" +#include "CapturePort.h" + +CapturePluginProxy* CapturePluginProxy::m_singleton; + +CapturePluginProxy::CapturePluginProxy() +{ + m_configureFunction = NULL; + m_registerCallBacksFunction = NULL; + m_initializeFunction = NULL; + m_runFunction = NULL; + m_startCaptureFunction = NULL; + m_stopCaptureFunction = NULL; + + m_loaded = false; +} + +CapturePluginProxy* CapturePluginProxy::Singleton() +{ + return m_singleton; +} + +bool CapturePluginProxy::Initialize() +{ + m_singleton = new CapturePluginProxy(); + return m_singleton->Init(); +} + +bool CapturePluginProxy::Init() +{ + // Get the desired capture plugin from the config file, or else, use the first dll encountered. + CStdString pluginDirectory = CONFIG.m_capturePluginPath + "/"; + CStdString pluginPath; + if (!CONFIG.m_capturePlugin.IsEmpty()) + { + // A specific plugin was specified in the config file + pluginPath = pluginDirectory + CONFIG.m_capturePlugin; + } + else + { + // No plugin specified, find the first one in the plugin directory + ACE_DIR* dir = ACE_OS::opendir((PCSTR)pluginDirectory); + if (!dir) + { + LOG4CXX_ERROR(LOG.rootLog, CStdString("Capture plugin directory could not be found:" + pluginDirectory)); + } + else + { + dirent* dirEntry = NULL; + bool found = false; + bool done = false; + while(!found && !done) + { + dirEntry = ACE_OS::readdir(dir); + if(dirEntry) + { + if (ACE_OS::strstr(dirEntry->d_name, ".dll")) + { + found = true; + done = true; + pluginPath = pluginDirectory + dirEntry->d_name; + } + } + else + { + done = true; + } + } + ACE_OS::closedir(dir); + } + } + if (!pluginPath.IsEmpty()) + { + m_dll.open((PCSTR)pluginPath); + ACE_TCHAR* error = m_dll.error(); + if(error) + { + LOG4CXX_ERROR(LOG.rootLog, CStdString("Failed to load the following plugin: ") + pluginPath); + } + else + { + // Ok, the dll has been successfully loaded + LOG4CXX_INFO(LOG.rootLog, CStdString("Loaded plugin: ") + pluginPath); + + RegisterCallBacksFunction registerCallBacks; + registerCallBacks = (RegisterCallBacksFunction)m_dll.symbol("RegisterCallBacks"); + registerCallBacks(AudioChunkCallBack, CaptureEventCallBack, OrkLogManager::Instance()); + + m_configureFunction = (ConfigureFunction)m_dll.symbol("Configure"); + if (m_configureFunction) + { + ConfigManager::Instance()->AddConfigureFunction(m_configureFunction); + + m_initializeFunction = (InitializeFunction)m_dll.symbol("Initialize"); + if (m_initializeFunction) + { + m_initializeFunction(); + + m_runFunction = (RunFunction)m_dll.symbol("Run"); + if (m_runFunction) + { + m_startCaptureFunction = (StartCaptureFunction)m_dll.symbol("StartCapture"); + if (m_startCaptureFunction) + { + m_stopCaptureFunction = (StopCaptureFunction)m_dll.symbol("StopCapture"); + if (m_stopCaptureFunction) + { + m_loaded = true; + } + else + { + LOG4CXX_ERROR(LOG.rootLog, CStdString("Could not find StopCapture function in ") + pluginPath); + } + } + else + { + LOG4CXX_ERROR(LOG.rootLog, CStdString("Could not find StartCapture function in ") + pluginPath); + } + } + else + { + LOG4CXX_ERROR(LOG.rootLog, CStdString("Could not find Run function in ") + pluginPath); + } + } + else + { + LOG4CXX_ERROR(LOG.rootLog, CStdString("Could not find Initialize function in ") + pluginPath); + } + } + else + { + LOG4CXX_ERROR(LOG.rootLog, CStdString("Could not find Configure function in ") + pluginPath); + } + } + } + else + { + LOG4CXX_ERROR(LOG.rootLog, CStdString("Failed to find any capture plugin in: ") + pluginDirectory); + } + + return m_loaded; +} + +void CapturePluginProxy::Run() +{ + if (!ACE_Thread_Manager::instance()->spawn(ACE_THR_FUNC(m_runFunction))) + { + LOG4CXX_INFO(LOG.rootLog, CStdString("Failed to create capture thread")); + } +} + +void CapturePluginProxy::Shutdown() +{ + ShutdownFunction shutdownFunction = (ShutdownFunction)m_dll.symbol("Shutdown"); + if (shutdownFunction) + { + LOG4CXX_INFO(LOG.rootLog, CStdString("Shutting down")); + shutdownFunction(); + } + else + { + LOG4CXX_INFO(LOG.rootLog, CStdString("Could not find DLL Shutdown function")); + } +} + +void CapturePluginProxy::StartCapture(CStdString& party) +{ + if(m_loaded) + { + m_startCaptureFunction(party); + } + else + { + throw(CStdString("StartCapture: Capture plugin not yet loaded")); + } +} + +void CapturePluginProxy::StopCapture(CStdString& party) +{ + if(m_loaded) + { + m_stopCaptureFunction(party); + } + else + { + throw(CStdString("StopCapture: Capture plugin not yet loaded")); + } +} + +void __CDECL__ CapturePluginProxy::AudioChunkCallBack(AudioChunkRef chunkRef, CStdString& capturePort) +{ + // find the right port and give it the audio chunk + CapturePortRef portRef = CapturePortsSingleton::instance()->AddAndReturnPort(capturePort); + portRef->AddAudioChunk(chunkRef); +} + +void __CDECL__ CapturePluginProxy::CaptureEventCallBack(CaptureEventRef eventRef, CStdString& capturePort) +{ + if(CONFIG.m_vad || CONFIG.m_audioSegmentation) + { + 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"); + } + } + else + { + // find the right port and give it the event + CapturePortRef portRef = CapturePortsSingleton::instance()->AddAndReturnPort(capturePort); + portRef->AddCaptureEvent(eventRef); + } +} + |