VideoCodec/Codec.cpp
#include "Codec.h"
namespace VideoCodec
{
Codec::Codec(Configuration* configuration)
{
this->moduleRegistry = new ModuleRegistry();
configurationPairs* pairs = configuration->GetRoot()->GetPairs();
for (configurationPairs::iterator i = pairs->begin(); i != pairs->end(); i++)
{
Module* thisModule = this->moduleRegistry->GetModule(i->first, configuration);
if (thisModule == NULL)
{
Logger::LogMessage(("Configuration settings ignored for " + *i->first + ": could not instantiate.").c_str());
continue;
}
// Save the pipeline module, which controls the encoding process.
if (strcmp(thisModule->GetModuleName(), PIPELINE_MODULE_ID) == 0)
this->pipeline = (Pipeline*)thisModule;
}
}
Codec::~Codec()
{
delete this->moduleRegistry;
}
void Codec::Run()
{
Logger::InitializeLogging();
if (this->pipeline == NULL)
{
Logger::LogMessage("Please configure a pipeline.");
return;
}
// Start the coding process.
this->pipeline->Run(this);
Logger::FinishLogging();
}
Module* Codec::GetModule(std::string moduleID)
{
Module* module = (*this->moduleRegistry->GetModules())[moduleID];
if (module == NULL)
// Try to instantiate the module without any configuration.
return this->moduleRegistry->GetModule(&moduleID, NULL);
else
// This module was configured by the user.
return module;
}
}