VideoCodec/Modules/ModuleRegistry.cpp
#include <string>
#include "ModuleRegistry.h"
namespace VideoCodec
{
ModuleRegistry::ModuleRegistry()
{
this->modules = new map<std::string, Module*>();
}
ModuleRegistry::~ModuleRegistry()
{
// Clean up the individual modules.
for (map<std::string, Module*>::iterator i = this->modules->begin(); i != this->modules->end(); i++)
delete i->second;
delete this->modules;
}
// Gets a module without passing in any configuration information.
Module* ModuleRegistry::GetModule(std::string* name)
{
return this->GetModule(name, NULL);
}
map<std::string, Module*>* ModuleRegistry::GetModules()
{
return this->modules;
}
// Gets a module passing in the specified configuration information.
Module* ModuleRegistry::GetModule(std::string* name, Configuration* configuration)
{
ConfigurationElement* moduleConfiguration = NULL;
if (configuration == NULL || (moduleConfiguration = configuration->GetConfigurationElement(name)) != NULL)
{
Module* module = NULL;
// Returned the stored module if there is one.
if ((*this->modules)[*name] == NULL)
{
// Instantiate the appropriate module.
if (strcmp(name->c_str(), FRAME_INPUT_MODULE_ID) == 0)
module = new FrameInputModule();
else if (strcmp(name->c_str(), STREAM_INPUT_MODULE_ID) == 0)
module = new StreamInputModule();
else if (strcmp(name->c_str(), FRAME_OUTPUT_MODULE_ID) == 0)
module = new FrameOutputModule();
else if (strcmp(name->c_str(), STREAM_OUTPUT_MODULE_ID) == 0)
module = new StreamOutputModule();
else if (strcmp(name->c_str(), PIPELINE_MODULE_ID) == 0)
module = new Pipeline();
else if (strcmp(name->c_str(), COLOUR_SPACE_CONVERTER_MODULE_ID) == 0)
module = new ColourSpaceConverter();
else if (strcmp(name->c_str(), MACROBLOCK_HANDLER_MODULE_ID) == 0)
module = new MacroblockHandler();
else if (strcmp(name->c_str(), DCT_MODULE_ID) == 0)
module = new DCT();
else if (strcmp(name->c_str(), AAN_DCT_MODULE_ID) == 0)
module = new AANDCT();
else if (strcmp(name->c_str(), DCT_COEFFICIENT_QUANTIZER_MODULE_ID) == 0)
module = new DCTCoefficientQuantizer();
else if (strcmp(name->c_str(), HUFFMAN_ENTROPY_ENCODER_MODULE_ID) == 0)
module = new HuffmanEntropyEncoder();
else if (strcmp(name->c_str(), HUFFMAN_ENTROPY_DECODER_MODULE_ID) == 0)
module = new HuffmanEntropyDecoder();
else if (strcmp(name->c_str(), STREAM_FORMATTER_MODULE_ID) == 0)
module = new StreamFormatter();
else if (strcmp(name->c_str(), STREAM_PARSER_MODULE_ID) == 0)
module = new StreamParser();
else if (strcmp(name->c_str(), FRAME_DIFFERENCE_MODULE_ID) == 0)
module = new FrameDifference();
else if (strcmp(name->c_str(), MOTION_ESTIMATION_MODULE_ID) == 0)
module = new MotionEstimation();
else if (strcmp(name->c_str(), GOP_MANAGER_MODULE_ID) == 0)
module = new GOPManager();
else if (strcmp(name->c_str(), PROGRESS_INFORMATION_MODULE_ID) == 0)
module = new ProgressInformation();
else if (strcmp(name->c_str(), EXTERNAL_MODULE_ID) == 0)
module = new External();
else if (strcmp(name->c_str(), RATE_CONTROL_MODULE_ID) == 0)
module = new RateControl();
if (module == NULL)
return NULL;
// The module is non-NULL, so store it ready for clean up.
(*this->modules)[*name] = module;
}
else
module = (*this->modules)[*name];
// Configure the selected module.
ConfigurationStatus status = module->Configure(moduleConfiguration);
switch (status)
{
case MODULE_CONFIGURATION_ERROR:
{
Logger::LogMessage(("Errors encountered instantiating module " + *name + ".").c_str());
return NULL;
}
case MODULE_CONFIGURATION_WARNING:
{
Logger::LogMessage(("Warnings encountered instantiating module " + *name + ".").c_str());
break;
}
}
return module;
}
return NULL;
}
}