Change Option parsing implmentation

Clean structs and classes.
Hide implementation details
Remove redundant classes
This commit is contained in:
jfmcarreira committed 2016-05-02 23:31:41 +01:00
1 parent 816dcc345f
commit 67e6d49be1
17 files changed
+307 -333

No files matched your search

+60 -60
View File
@@ -60,9 +60,9 @@ Int PlaYUVerTools::openInputs()
/**
* Create input streams
*/
if( m_cCmdLineHandler.Opts().hasOpt( "input" ) )
if( Opts().hasOpt( "input" ) )
{
std::vector<String> inputFileNames = m_cCmdLineHandler.m_apcInputs;
std::vector<String> inputFileNames = m_apcInputs;
String resolutionString( "" );
String fmtString( "yuv420p" );
@@ -72,25 +72,25 @@ Int PlaYUVerTools::openInputs()
PlaYUVerStream* pcStream;
for( UInt i = 0; i < inputFileNames.size() && i < MAX_NUMBER_INPUTS; i++ )
{
if( m_cCmdLineHandler.Opts().hasOpt( "size" ) )
if( Opts().hasOpt( "size" ) )
{
resolutionString = GET_PARAM( m_cCmdLineHandler.m_strResolution, 0 );
resolutionString = GET_PARAM( m_strResolution, 0 );
}
if( m_cCmdLineHandler.Opts().hasOpt( "pel_fmt" ) )
if( Opts().hasOpt( "pel_fmt" ) )
{
fmtString = GET_PARAM( m_cCmdLineHandler.m_strPelFmt, i );
fmtString = GET_PARAM( m_strPelFmt, i );
}
if( m_cCmdLineHandler.Opts().hasOpt( "bits_pel" ) )
if( Opts().hasOpt( "bits_pel" ) )
{
uiBitPerPixel = GET_PARAM( m_cCmdLineHandler.m_uiBitsPerPixel, i );
uiBitPerPixel = GET_PARAM( m_uiBitsPerPixel, i );
}
if( m_cCmdLineHandler.Opts().hasOpt( "endianness" ) )
if( Opts().hasOpt( "endianness" ) )
{
if( GET_PARAM( m_cCmdLineHandler.m_strEndianness, i ) == "big" )
if( GET_PARAM( m_strEndianness, i ) == "big" )
{
uiEndianness = 0;
}
if( GET_PARAM( m_cCmdLineHandler.m_strEndianness, i ) == "little" )
if( GET_PARAM( m_strEndianness, i ) == "little" )
{
uiEndianness = 1;
}
@@ -98,25 +98,25 @@ Int PlaYUVerTools::openInputs()
pcStream = new PlaYUVerStream;
try
{
if( !pcStream->open( inputFileNames[i], resolutionString, fmtString, uiBitPerPixel, uiEndianness, 1 ) )
if( !pcStream->open( inputFileNames[i], resolutionString, fmtString, uiBitPerPixel, uiEndianness, 1, true ) )
{
m_cCmdLineHandler.log( LOG_ERROR, "Cannot open input stream %s! ", inputFileNames[i].c_str() );
log( LOG_ERROR, "Cannot open input stream %s! ", inputFileNames[i].c_str() );
return 2;
}
m_apcInputStreams.push_back( pcStream );
}
catch( const char *msg )
{
m_cCmdLineHandler.log( LOG_ERROR, "Cannot open input stream %s with the following error: \n%s\n", inputFileNames[i].c_str(), msg );
log( LOG_ERROR, "Cannot open input stream %s with the following error: \n%s\n", inputFileNames[i].c_str(), msg );
return 2;
}
}
}
m_uiNumberOfFrames = MAX_UINT;
if( m_cCmdLineHandler.Opts().hasOpt( "frames" ) )
if( Opts().hasOpt( "frames" ) )
{
m_uiNumberOfFrames = m_cCmdLineHandler.m_iFrames;
m_uiNumberOfFrames = m_iFrames;
}
m_uiNumberOfComponents = MAX_UINT;
@@ -135,7 +135,7 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] )
{
Int iRet = 0;
if( ( iRet = m_cCmdLineHandler.parseToolsArgs( argc, argv ) ) > 0 )
if( ( iRet = parseToolsArgs( argc, argv ) ) > 0 )
{
return iRet;
}
@@ -145,11 +145,11 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] )
return 2;
}
if( m_cCmdLineHandler.Opts().hasOpt( "save" ) )
if( Opts().hasOpt( "save" ) )
{
if( m_apcInputStreams.size() == 0 )
{
m_cCmdLineHandler.log( LOG_ERROR, "Invalid number of input streams! " );
log( LOG_ERROR, "Invalid number of input streams! " );
return 2;
}
Int64 currFrames = 0;
@@ -160,34 +160,34 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] )
if( currFrames < numberOfFrames )
numberOfFrames = currFrames;
}
m_iFrameNum = m_cCmdLineHandler.m_iFrames;
m_iFrameNum = m_iFrames;
if( !( m_iFrameNum >= 0 && m_iFrameNum < numberOfFrames ) )
{
m_cCmdLineHandler.log( LOG_ERROR, "Invalid frame number! Use --frame option " );
log( LOG_ERROR, "Invalid frame number! Use --frame option " );
return 2;
}
if( m_cCmdLineHandler.Opts().hasOpt( "output" ) )
m_pcOutputFileNames.push_back( m_cCmdLineHandler.m_strOutput );
if( Opts().hasOpt( "output" ) )
m_pcOutputFileNames.push_back( m_strOutput );
if( m_pcOutputFileNames.size() != m_apcInputStreams.size() )
{
m_cCmdLineHandler.log( LOG_ERROR, "Invalid number of outputs! Each input must have an output filename. " );
log( LOG_ERROR, "Invalid number of outputs! Each input must have an output filename. " );
return 2;
}
m_uiOperation = SAVE_OPERATION;
m_fpProcess = &PlaYUVerTools::SaveOperation;
m_cCmdLineHandler.log( LOG_INFO, "PlaYUVer Save Frame\n" );
log( LOG_INFO, "PlaYUVer Save Frame\n" );
}
/**
* Check Quality operation
*/
if( m_cCmdLineHandler.Opts().hasOpt( "quality" ) )
if( Opts().hasOpt( "quality" ) )
{
String qualityMetric = m_cCmdLineHandler.m_strQualityMetric;
String qualityMetric = m_strQualityMetric;
if( m_apcInputStreams.size() < 2 )
{
m_cCmdLineHandler.log( LOG_ERROR, "Invalid number of inputs! " );
log( LOG_ERROR, "Invalid number of inputs! " );
return 2;
}
for( UInt i = 0; i < PlaYUVerFrame::supportedQualityMetricsList().size(); i++ )
@@ -199,20 +199,20 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] )
}
if( m_uiQualityMetric == -1 )
{
m_cCmdLineHandler.log( LOG_ERROR, "Invalid quality metric! " );
log( LOG_ERROR, "Invalid quality metric! " );
return 2;
}
m_uiOperation = QUALITY_OPERATION;
m_fpProcess = &PlaYUVerTools::QualityOperation;
m_cCmdLineHandler.log( LOG_INFO, "PlaYUVer Quality\n" );
log( LOG_INFO, "PlaYUVer Quality\n" );
}
/**
* Check Module operation
*/
if( m_cCmdLineHandler.Opts().hasOpt( "module" ) )
if( Opts().hasOpt( "module" ) )
{
String moduleName = m_cCmdLineHandler.m_strModule;
String moduleName = m_strModule;
PlaYUVerModuleFactoryMap& PlaYUVerModuleFactoryMap = PlaYUVerModuleFactory::Get()->getMap();
PlaYUVerModuleFactoryMap::iterator it = PlaYUVerModuleFactoryMap.begin();
@@ -226,17 +226,17 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] )
}
if( !m_pcCurrModuleIf )
{
m_cCmdLineHandler.log( LOG_ERROR, "Invalid module! " );
log( LOG_ERROR, "Invalid module! " );
return 2;
}
if( m_apcInputStreams.size() != m_pcCurrModuleIf->m_uiNumberOfFrames )
{
m_cCmdLineHandler.log( LOG_ERROR, "Invalid number of inputs! " );
log( LOG_ERROR, "Invalid number of inputs! " );
return 2;
}
m_pcCurrModuleIf->m_cModuleOptions.scanArgv( argc, ( const Char** )argv );
m_pcCurrModuleIf->m_cModuleOptions.parse( argc, argv );
// Create Module
Bool moduleCreated = false;
@@ -256,7 +256,7 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] )
}
if( !moduleCreated )
{
m_cCmdLineHandler.log( LOG_ERROR, "Module is not supported with the selected inputs! " );
log( LOG_ERROR, "Module is not supported with the selected inputs! " );
return 2;
}
@@ -264,8 +264,8 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] )
{
// Check outputs
std::vector<String> outputFileNames;
if( m_cCmdLineHandler.Opts().hasOpt( "output" ) )
outputFileNames.push_back( m_cCmdLineHandler.m_strOutput );
if( Opts().hasOpt( "output" ) )
outputFileNames.push_back( m_strOutput );
if( outputFileNames.size() == 1 )
{
@@ -279,7 +279,7 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] )
pcModFrame = applyFrameModule();
}
PlaYUVerStream* pcModStream = new PlaYUVerStream;
if( !pcModStream->open( outputFileNames[0], pcModFrame->getWidth(), pcModFrame->getHeight(), pcModFrame->getPelFormat(), pcModFrame->getBitsPel(), 1, false ) )
if( !pcModStream->open( outputFileNames[0], pcModFrame->getWidth(), pcModFrame->getHeight(), pcModFrame->getPelFormat(), pcModFrame->getBitsPel(), pcModFrame->getEndianness(), 1, false ) )
{
delete pcModStream;
pcModStream = NULL;
@@ -289,19 +289,19 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] )
}
else
{
m_cCmdLineHandler.log( LOG_ERROR, "One output is required! " );
log( LOG_ERROR, "One output is required! " );
return 2;
}
}
m_uiOperation = MODULE_OPERATION;
m_fpProcess = &PlaYUVerTools::ModuleOperation;
m_cCmdLineHandler.log( LOG_INFO, "PlaYUVer Module\n" );
log( LOG_INFO, "PlaYUVer Module\n" );
}
if( m_uiOperation == INVALID_OPERATION )
{
m_cCmdLineHandler.log( LOG_ERROR, "No operation was selected! " );
log( LOG_ERROR, "No operation was selected! " );
return 2;
}
return iRet;
@@ -361,19 +361,19 @@ Int PlaYUVerTools::QualityOperation()
}
metric_fmt += " ";
m_cCmdLineHandler.log( LOG_INFO, " Measuring Quality using %s ... \n", pchQualityMetricName );
m_cCmdLineHandler.log( LOG_INFO, "# Frame ", pchQualityMetricName );
log( LOG_INFO, " Measuring Quality using %s ... \n", pchQualityMetricName );
log( LOG_INFO, "# Frame ", pchQualityMetricName );
for( UInt s = 1; s < m_apcInputStreams.size(); s++ )
{
for( UInt c = 0; c < m_uiNumberOfComponents; c++ )
{
m_cCmdLineHandler.log( LOG_INFO, "%s_%d_%d ", pchQualityMetricName, s, c );
log( LOG_INFO, "%s_%d_%d ", pchQualityMetricName, s, c );
}
m_cCmdLineHandler.log( LOG_INFO, " " );
log( LOG_INFO, " " );
}
m_cCmdLineHandler.log( LOG_INFO, "\n" );
log( LOG_INFO, "\n" );
for( UInt s = 0; s < m_apcInputStreams.size(); s++ )
{
@@ -385,22 +385,22 @@ Int PlaYUVerTools::QualityOperation()
}
for( UInt frame = 0; frame < m_uiNumberOfFrames; frame++ )
{
m_cCmdLineHandler.log( LOG_INFO, " %3d ", frame );
log( LOG_INFO, " %3d ", frame );
for( UInt s = 0; s < m_apcInputStreams.size(); s++ )
apcCurrFrame[s] = m_apcInputStreams[s]->getCurrFrame();
for( UInt s = 1; s < m_apcInputStreams.size(); s++ )
{
m_cCmdLineHandler.log( LOG_RESULT, " " );
log( LOG_RESULT, " " );
for( UInt c = 0; c < m_uiNumberOfComponents; c++ )
{
dQuality = apcCurrFrame[s]->getQuality( m_uiQualityMetric, apcCurrFrame[0], c );
adAverageQuality[s - 1][c] = ( adAverageQuality[s - 1][c] * Double( frame ) + dQuality ) / Double( frame + 1 );
m_cCmdLineHandler.log( LOG_RESULT, metric_fmt.c_str(), dQuality );
log( LOG_RESULT, metric_fmt.c_str(), dQuality );
}
m_cCmdLineHandler.log( LOG_RESULT, " " );
log( LOG_RESULT, " " );
}
m_cCmdLineHandler.log( LOG_RESULT, "\n" );
log( LOG_RESULT, "\n" );
for( UInt s = 0; s < m_apcInputStreams.size(); s++ )
{
abEOF[s] = m_apcInputStreams[s]->setNextFrame();
@@ -410,16 +410,16 @@ Int PlaYUVerTools::QualityOperation()
}
}
}
m_cCmdLineHandler.log( LOG_INFO, "\n Mean Values: \n " );
log( LOG_INFO, "\n Mean Values: \n " );
for( UInt s = 0; s < m_apcInputStreams.size() - 1; s++ )
{
for( UInt c = 0; c < m_uiNumberOfComponents; c++ )
{
m_cCmdLineHandler.log( LOG_INFO, metric_fmt.c_str(), adAverageQuality[s][c] );
log( LOG_INFO, metric_fmt.c_str(), adAverageQuality[s][c] );
}
m_cCmdLineHandler.log( LOG_RESULT, " " );
log( LOG_RESULT, " " );
}
m_cCmdLineHandler.log( LOG_INFO, "\n" );
log( LOG_INFO, "\n" );
return 0;
}
@@ -436,7 +436,7 @@ PlaYUVerFrame* PlaYUVerTools::applyFrameModule()
Int PlaYUVerTools::ModuleOperation()
{
std::vector<PlaYUVerFrame*> apcFrameList;
m_cCmdLineHandler.log( LOG_INFO, " Applying Module %s/%s ...\n", m_pcCurrModuleIf->m_pchModuleCategory, m_pcCurrModuleIf->m_pchModuleName );
log( LOG_INFO, " Applying Module %s/%s ...\n", m_pcCurrModuleIf->m_pchModuleCategory, m_pcCurrModuleIf->m_pchModuleName );
PlaYUVerFrame* pcProcessedFrame = NULL;
Double dMeasurementResult = 0.0;
@@ -477,8 +477,8 @@ Int PlaYUVerTools::ModuleOperation()
{
dMeasurementResult = m_pcCurrModuleIf->measure( m_apcInputStreams[0]->getCurrFrame() );
}
m_cCmdLineHandler.log( LOG_INFO, " %3d", frame );
m_cCmdLineHandler.log( LOG_RESULT, " %8.3f \n", dMeasurementResult );
log( LOG_INFO, " %3d", frame );
log( LOG_RESULT, " %8.3f \n", dMeasurementResult );
dAveragedMeasurementResult = ( dAveragedMeasurementResult * Double( frame ) + dMeasurementResult ) / Double( frame + 1 );
}
@@ -494,7 +494,7 @@ Int PlaYUVerTools::ModuleOperation()
if( m_pcCurrModuleIf->m_iModuleType == FRAME_MEASUREMENT_MODULE )
{
m_cCmdLineHandler.log( LOG_INFO, "\n Mean Value: \n %8.3f\n", dAveragedMeasurementResult );
log( LOG_INFO, "\n Mean Value: \n %8.3f\n", dAveragedMeasurementResult );
}
return 0;