Rework of plugin system. Now works better with static linking. Plugin makers are now expected to pass back a fully implemented version of IAudioPlugin for cAudio to use. Create your plugin class with new, cAudio will call drop() on it on unload of your dll.
The MP3Decoder plugin has been updated for the above changes. Removed the shim that used to exist between dll plugins and the manager.
This commit is contained in:
parent
f69d925b4f
commit
b096f1536b
|
@ -43,7 +43,7 @@ int main(int argc, char* argv[])
|
|||
manager->initialize(manager->getAvailableDeviceName(deviceSelection));
|
||||
|
||||
//Create a IAudio object and load a sound from a file
|
||||
cAudio::IAudioSource* mysound = manager->create("bling","../../media/cAudioTheme1.ogg",true);
|
||||
cAudio::IAudioSource* mysound = manager->create("bling","../../media/Years_of_Work.mp3",true);
|
||||
|
||||
if(mysound)
|
||||
{
|
||||
|
|
|
@ -15,11 +15,10 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
//Some fancy text
|
||||
cout << "cAudio 2.0.0 Tutorial 3: Memory Playback. \n \n"
|
||||
cout << "cAudio 2.0.0 Tutorial 3: Memory Playback. \n \n";
|
||||
|
||||
//Create an uninitialized Audio Manager
|
||||
cAudio::IAudioManager* manager = cAudio::createAudioManager(false);
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
#ifndef CAUDIOPLUGIN_H_INCLUDED
|
||||
#define CAUDIOPLUGIN_H_INCLUDED
|
||||
|
||||
#include "../include/IAudioPlugin.h"
|
||||
#include "../include/ILogger.h"
|
||||
|
||||
namespace cAudio
|
||||
{
|
||||
typedef bool (*pluginInstallFunc)(ILogger* logger, const char* version);
|
||||
typedef const char* (*pluginNameFunc)();
|
||||
typedef void (*pluginUninstallFunc)();
|
||||
|
||||
typedef void (*pluginOnCreateAudioManager)(IAudioManager*);
|
||||
typedef void (*pluginOnCreateAudioCapture)(IAudioCapture*);
|
||||
|
||||
typedef void (*pluginOnDestroyAudioManager)(IAudioManager*);
|
||||
typedef void (*pluginOnDestroyAudioCapture)(IAudioCapture*);
|
||||
|
||||
//Simply acts as a shim between dll functions and IAudioPlugin
|
||||
class cAudioPlugin : public IAudioPlugin
|
||||
{
|
||||
public:
|
||||
cAudioPlugin()
|
||||
{
|
||||
initFunc = 0x0;
|
||||
nameFunc = 0x0;
|
||||
uninstalledFunc = 0x0;
|
||||
createAudioManagerFunc = 0x0;
|
||||
createAudioCaptureFunc = 0x0;
|
||||
destroyAudioManagerFunc = 0x0;
|
||||
destroyAudioCaptureFunc = 0x0;
|
||||
}
|
||||
~cAudioPlugin() { }
|
||||
|
||||
virtual bool installPlugin(ILogger* logger, const char* version);
|
||||
virtual const char* getPluginName();
|
||||
virtual void uninstallPlugin();
|
||||
|
||||
virtual void onCreateAudioManager(IAudioManager* manager);
|
||||
virtual void onCreateAudioCapture(IAudioCapture* capture);
|
||||
|
||||
virtual void onDestroyAudioManager(IAudioManager* manager);
|
||||
virtual void onDestoryAudioCapture(IAudioCapture* capture);
|
||||
|
||||
pluginInstallFunc initFunc;
|
||||
pluginNameFunc nameFunc;
|
||||
pluginUninstallFunc uninstalledFunc;
|
||||
|
||||
pluginOnCreateAudioManager createAudioManagerFunc;
|
||||
pluginOnCreateAudioCapture createAudioCaptureFunc;
|
||||
|
||||
pluginOnDestroyAudioManager destroyAudioManagerFunc;
|
||||
pluginOnDestroyAudioCapture destroyAudioCaptureFunc;
|
||||
};
|
||||
};
|
||||
|
||||
#endif //! CAUDIOPLUGIN_H_INCLUDED
|
|
@ -1,52 +0,0 @@
|
|||
#include "../Headers/cAudioPlugin.h"
|
||||
|
||||
namespace cAudio
|
||||
{
|
||||
|
||||
bool cAudioPlugin::installPlugin(ILogger* logger, const char* version)
|
||||
{
|
||||
if(initFunc)
|
||||
return initFunc(logger, version);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* cAudioPlugin::getPluginName()
|
||||
{
|
||||
if(nameFunc)
|
||||
return nameFunc();
|
||||
|
||||
return 0x0;
|
||||
}
|
||||
|
||||
void cAudioPlugin::uninstallPlugin()
|
||||
{
|
||||
if(uninstalledFunc)
|
||||
uninstalledFunc();
|
||||
}
|
||||
|
||||
void cAudioPlugin::onCreateAudioManager(IAudioManager* manager)
|
||||
{
|
||||
if(createAudioManagerFunc)
|
||||
createAudioManagerFunc(manager);
|
||||
}
|
||||
|
||||
void cAudioPlugin::onCreateAudioCapture(IAudioCapture* capture)
|
||||
{
|
||||
if(createAudioCaptureFunc)
|
||||
createAudioCaptureFunc(capture);
|
||||
}
|
||||
|
||||
void cAudioPlugin::onDestroyAudioManager(IAudioManager* manager)
|
||||
{
|
||||
if(destroyAudioManagerFunc)
|
||||
destroyAudioManagerFunc(manager);
|
||||
}
|
||||
|
||||
void cAudioPlugin::onDestoryAudioCapture(IAudioCapture* capture)
|
||||
{
|
||||
if(destroyAudioCaptureFunc)
|
||||
destroyAudioCaptureFunc(capture);
|
||||
}
|
||||
|
||||
};
|
|
@ -1,12 +1,14 @@
|
|||
#include "../Headers/cPluginManager.h"
|
||||
#include "../Headers/cUtils.h"
|
||||
#include "../include/cAudioPlatform.h"
|
||||
#include "../Headers/cAudioPlugin.h"
|
||||
#include "../include/cAudioDefines.h"
|
||||
#include "../include/ILogger.h"
|
||||
|
||||
namespace cAudio
|
||||
{
|
||||
|
||||
typedef IAudioPlugin* (*GetPluginModule)(const char* version);
|
||||
|
||||
cPluginManager::cPluginManager()
|
||||
{
|
||||
autoLoadPlugins();
|
||||
|
@ -18,11 +20,11 @@ cPluginManager::~cPluginManager()
|
|||
for(it = DynamicallyLoadedPlugins.begin(); it != DynamicallyLoadedPlugins.end(); it++)
|
||||
{
|
||||
//Found a plugin we loaded from the filesystem, unload it and delete the plugin
|
||||
it->first->drop();
|
||||
if(DYNLIB_UNLOAD(it->second))
|
||||
{
|
||||
//Could be an error, not reporting it for now
|
||||
}
|
||||
delete it->first;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,7 +36,7 @@ bool cPluginManager::installPlugin(IAudioPlugin* plugin, const char* name)
|
|||
if(theName.empty())
|
||||
theName = plugin->getPluginName();
|
||||
|
||||
if(plugin->installPlugin(getLogger(), CAUDIO_VERSION))
|
||||
if(plugin->installPlugin(getLogger()))
|
||||
{
|
||||
RegisteredPlugins[theName] = plugin;
|
||||
return true;
|
||||
|
@ -48,18 +50,13 @@ bool cPluginManager::installPlugin(const char* filename, const char* name)
|
|||
DYNLIB_HANDLE m_hInst = DYNLIB_LOAD(filename);
|
||||
if(m_hInst)
|
||||
{
|
||||
cAudioPlugin* plugin = new cAudioPlugin();
|
||||
if(plugin)
|
||||
{
|
||||
plugin->initFunc = (pluginInstallFunc)DYNLIB_GETSYM(m_hInst, "InstallPlugin");
|
||||
plugin->nameFunc = (pluginNameFunc)DYNLIB_GETSYM(m_hInst, "GetPluginName");
|
||||
plugin->uninstalledFunc = (pluginUninstallFunc)DYNLIB_GETSYM(m_hInst, "UninstallPlugin");
|
||||
plugin->createAudioManagerFunc = (pluginOnCreateAudioManager)DYNLIB_GETSYM(m_hInst, "OnCreateAudioManager");
|
||||
plugin->createAudioCaptureFunc = (pluginOnCreateAudioCapture)DYNLIB_GETSYM(m_hInst, "OnCreateAudioCapture");
|
||||
plugin->destroyAudioManagerFunc = (pluginOnDestroyAudioManager)DYNLIB_GETSYM(m_hInst, "OnDestroyAudioManager");
|
||||
plugin->destroyAudioCaptureFunc = (pluginOnDestroyAudioCapture)DYNLIB_GETSYM(m_hInst, "OnDestroyAudioCapture");
|
||||
GetPluginModule moduleFunc = (GetPluginModule)DYNLIB_GETSYM(m_hInst, "GetPluginModule");
|
||||
|
||||
if(plugin->initFunc && plugin->nameFunc && plugin->uninstalledFunc)
|
||||
if(moduleFunc)
|
||||
{
|
||||
IAudioPlugin* plugin = moduleFunc(CAUDIO_VERSION);
|
||||
|
||||
if(plugin)
|
||||
{
|
||||
DynamicallyLoadedPlugins[plugin] = m_hInst;
|
||||
|
||||
|
|
|
@ -191,10 +191,6 @@
|
|||
RelativePath=".\Headers\cAudioManager.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Headers\cAudioPlugin.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Headers\cAudioSource.h"
|
||||
>
|
||||
|
@ -295,10 +291,6 @@
|
|||
RelativePath=".\Source\cAudioManager.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Source\cAudioPlugin.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Source\cAudioSleep.cpp"
|
||||
>
|
||||
|
|
|
@ -1,54 +1,28 @@
|
|||
#ifndef IAUDIOPLUGIN_H_INCLUDED
|
||||
#define IAUDIOPLUGIN_H_INCLUDED
|
||||
|
||||
#include "IRefCounted.h"
|
||||
#include "IAudioManager.h"
|
||||
#include "IAudioCapture.h"
|
||||
#include "ILogger.h"
|
||||
|
||||
namespace cAudio
|
||||
{
|
||||
class IAudioManager;
|
||||
class IAudioCapture;
|
||||
class ILogger;
|
||||
|
||||
//Class that abstracts a particular plugin implementation
|
||||
//Plugins must have the following functions:
|
||||
/*
|
||||
//Will be called on initial install of the plugin, use this for any first time initialization. A reference to the logger is passed in for convenience.
|
||||
bool installPlugin(ILogger* logger);
|
||||
|
||||
//Must return a unique name that identifies this plugin.
|
||||
const char* getPluginName();
|
||||
|
||||
//Will be called on when cAudio uninstalls this plugin, use this for any final cleanup.
|
||||
void uninstallPlugin();
|
||||
|
||||
//Optional Functions, implement one if you want to support that feature of the library
|
||||
|
||||
//Will be called when an Audio Manager is created. Use the passed in pointer to register any decoders or event handlers.
|
||||
void onCreateAudioManager(IAudioManager* manager);
|
||||
|
||||
//Will be called when an Audio Capture Device is created. Use the passed in pointer to register any event handlers.
|
||||
void onCreateAudioCapture(IAudioCapture* capture);
|
||||
|
||||
//Will be called when an Audio Manager is destroyed. Use the passed in pointer to remove any decoders or event handlers.
|
||||
void onDestroyAudioManager(IAudioManager* manager);
|
||||
|
||||
//Will be called when an Audio Capture Device is destroyed. Use the passed in pointer to remove any event handlers.
|
||||
void onDestroyAudioCapture(IAudioCapture* capture);
|
||||
|
||||
*/
|
||||
class IAudioPlugin
|
||||
class IAudioPlugin : public IRefCounted
|
||||
{
|
||||
public:
|
||||
IAudioPlugin() { }
|
||||
~IAudioPlugin() { }
|
||||
|
||||
virtual bool installPlugin(ILogger* logger, const char* version) = 0;
|
||||
virtual bool installPlugin(ILogger* logger) = 0;
|
||||
virtual const char* getPluginName() = 0;
|
||||
virtual void uninstallPlugin() = 0;
|
||||
|
||||
virtual void onCreateAudioManager(IAudioManager* manager) = 0;
|
||||
virtual void onCreateAudioCapture(IAudioCapture* capture) = 0;
|
||||
virtual void onCreateAudioManager(IAudioManager* manager) { }
|
||||
virtual void onCreateAudioCapture(IAudioCapture* capture) { }
|
||||
|
||||
virtual void onDestroyAudioManager(IAudioManager* manager) = 0;
|
||||
virtual void onDestoryAudioCapture(IAudioCapture* capture) = 0;
|
||||
virtual void onDestroyAudioManager(IAudioManager* manager) { }
|
||||
virtual void onDestoryAudioCapture(IAudioCapture* capture) { }
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -1,51 +1,13 @@
|
|||
#include "cMP3DecoderFactory.h"
|
||||
#include "IAudioPlugin.h"
|
||||
#include "cAudioDefines.h"
|
||||
#include "IAudioManager.h"
|
||||
#include "ILogger.h"
|
||||
#include "cMP3Plugin.h"
|
||||
|
||||
//Will be called on initial install of the plugin, use this for any first time initialization.
|
||||
extern "C" CAUDIO_API bool InstallPlugin(cAudio::ILogger* logger, const char* version)
|
||||
//Gives back the plugin class for cAudio to install and use.
|
||||
extern "C" CAUDIO_API IAudioPlugin* GetPluginModule(const char* version)
|
||||
{
|
||||
//This plugin has no first time initialization to do, so this is an easy function
|
||||
//First, double check that this copy of cAudio matches what we were compiled against
|
||||
//Double-check the version to make sure we can be used
|
||||
if(strcmp(CAUDIO_VERSION, version) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//Must return a unique name that identifies this plugin.
|
||||
extern "C" CAUDIO_API const char* GetPluginName()
|
||||
{
|
||||
return "MP3Decoder";
|
||||
}
|
||||
|
||||
//Will be called on when cAudio uninstalls this plugin, use this for any final cleanup.
|
||||
extern "C" CAUDIO_API void UninstallPlugin()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//Will be called when an Audio Manager is created. Use the passed in pointer to register any decoders or event handlers.
|
||||
extern "C" CAUDIO_API void OnCreateAudioManager(cAudio::IAudioManager* manager)
|
||||
{
|
||||
cMP3DecoderFactory* factory = new cMP3DecoderFactory();
|
||||
|
||||
if(factory)
|
||||
{
|
||||
manager->registerAudioDecoder(factory, "mp3");
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" CAUDIO_API void OnDestroyAudioManager(cAudio::IAudioManager* manager)
|
||||
{
|
||||
cAudio::IAudioDecoderFactory* factory = manager->getAudioDecoderFactory("mp3");
|
||||
manager->unRegisterAudioDecoder("mp3");
|
||||
|
||||
if(factory)
|
||||
{
|
||||
delete factory;
|
||||
return new cMP3DecoderPlugin();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -189,6 +189,10 @@
|
|||
RelativePath=".\cMP3DecoderFactory.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\cMP3Plugin.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="mpaudec"
|
||||
|
|
Loading…
Reference in New Issue