Added EncoderFactory class.

This commit is contained in:
LoRd_MuldeR 2014-04-16 13:49:36 +02:00
parent ca2d532f8b
commit e67d61e8f6
8 changed files with 108 additions and 32 deletions

61
src/encoder_factory.cpp Normal file
View File

@ -0,0 +1,61 @@
///////////////////////////////////////////////////////////////////////////////
// Simple x264 Launcher
// Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// http://www.gnu.org/licenses/gpl-2.0.txt
///////////////////////////////////////////////////////////////////////////////
#include "encoder_factory.h"
#include "global.h"
#include "model_options.h"
#include "encoder_x264.h"
#include "encoder_x265.h"
AbstractEncoder *EncoderFactory::createEncoder(JobObject *jobObject, const OptionsModel *options, const SysinfoModel *const sysinfo, const PreferencesModel *const preferences, JobStatus &jobStatus, volatile bool *abort, volatile bool *pause, QSemaphore *semaphorePause, const QString &sourceFile, const QString &outputFile)
{
AbstractEncoder *encoder = NULL;
switch(options->encType())
{
case OptionsModel::EncType_X264:
encoder = new X264Encoder(jobObject, options, sysinfo, preferences, jobStatus, abort, pause, semaphorePause, sourceFile, outputFile);
break;
case OptionsModel::EncType_X265:
encoder = new X265Encoder(jobObject, options, sysinfo, preferences, jobStatus, abort, pause, semaphorePause, sourceFile, outputFile);
break;
default:
THROW("Unknown encoder type encountered!");
}
return encoder;
}
const AbstractEncoderInfo& EncoderFactory::getEncoderInfo(const int &encoderType)
{
switch(encoderType)
{
case OptionsModel::EncType_X264:
return X264Encoder::getEncoderInfo();
case OptionsModel::EncType_X265:
return X265Encoder::getEncoderInfo();
default:
THROW("Unknown encoder type encountered!");
}
return *((AbstractEncoderInfo*)NULL);
}

34
src/encoder_factory.h Normal file
View File

@ -0,0 +1,34 @@
///////////////////////////////////////////////////////////////////////////////
// Simple x264 Launcher
// Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// http://www.gnu.org/licenses/gpl-2.0.txt
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "encoder_abstract.h"
class EncoderFactory
{
public:
static AbstractEncoder *createEncoder(JobObject *jobObject, const OptionsModel *options, const SysinfoModel *const sysinfo, const PreferencesModel *const preferences, JobStatus &jobStatus, volatile bool *abort, volatile bool *pause, QSemaphore *semaphorePause, const QString &sourceFile, const QString &outputFile);
static const AbstractEncoderInfo& getEncoderInfo(const int &encoderType);
private:
EncoderFactory(void) {/*Disabled*/}
};

View File

@ -30,8 +30,7 @@
#include "binaries.h" #include "binaries.h"
//Encoders //Encoders
#include "encoder_x264.h" #include "encoder_factory.h"
#include "encoder_x265.h"
//Source //Source
#include "source_avisynth.h" #include "source_avisynth.h"
@ -142,17 +141,7 @@ EncodeThread::EncodeThread(const QString &sourceFileName, const QString &outputF
m_pause = false; m_pause = false;
//Create encoder object //Create encoder object
switch(options->encType()) m_encoder = EncoderFactory::createEncoder(m_jobObject, m_options, m_sysinfo, m_preferences, m_status, &m_abort, &m_pause, &m_semaphorePaused, m_sourceFileName, m_outputFileName);
{
case OptionsModel::EncType_X264:
m_encoder = new X264Encoder(m_jobObject, m_options, m_sysinfo, m_preferences, m_status, &m_abort, &m_pause, &m_semaphorePaused, m_sourceFileName, m_outputFileName);
break;
case OptionsModel::EncType_X265:
m_encoder = new X265Encoder(m_jobObject, m_options, m_sysinfo, m_preferences, m_status, &m_abort, &m_pause, &m_semaphorePaused, m_sourceFileName, m_outputFileName);
break;
default:
throw "Unknown encoder type encountered!";
}
//Create input handler object //Create input handler object
switch(getInputType(QFileInfo(m_sourceFileName).suffix())) switch(getInputType(QFileInfo(m_sourceFileName).suffix()))

View File

@ -26,7 +26,7 @@
#define VER_X264_MAJOR 2 #define VER_X264_MAJOR 2
#define VER_X264_MINOR 3 #define VER_X264_MINOR 3
#define VER_X264_PATCH 5 #define VER_X264_PATCH 5
#define VER_X264_BUILD 815 #define VER_X264_BUILD 816
#define VER_X264_PORTABLE_EDITION (0) #define VER_X264_PORTABLE_EDITION (0)

View File

@ -27,8 +27,7 @@
#include "model_preferences.h" #include "model_preferences.h"
#include "model_sysinfo.h" #include "model_sysinfo.h"
#include "model_recently.h" #include "model_recently.h"
#include "encoder_x264.h" #include "encoder_factory.h"
#include "encoder_x265.h"
#include "win_help.h" #include "win_help.h"
#include "win_editor.h" #include "win_editor.h"
@ -499,7 +498,7 @@ void AddJobDialog::accept(void)
} }
//Get encoder info //Get encoder info
const AbstractEncoderInfo &encoderInfo = getEncoderInfo(ui->cbxEncoderType->currentIndex()); const AbstractEncoderInfo &encoderInfo = EncoderFactory::getEncoderInfo(ui->cbxEncoderType->currentIndex());
//Is selected RC mode supported? //Is selected RC mode supported?
if(!encoderInfo.isRCModeSupported(ui->cbxRateControlMode->currentIndex())) if(!encoderInfo.isRCModeSupported(ui->cbxRateControlMode->currentIndex()))
@ -1153,17 +1152,3 @@ QString AddJobDialog::getInputFilterLst(void)
filters << QString("All files (*.*)"); filters << QString("All files (*.*)");
return filters.join(";;"); return filters.join(";;");
} }
const AbstractEncoderInfo& AddJobDialog::getEncoderInfo(const int &encoder)
{
switch(encoder)
{
case OptionsModel::EncType_X264:
return X264Encoder::getEncoderInfo();
case OptionsModel::EncType_X265:
return X265Encoder::getEncoderInfo();
break;
default:
THROW("Unsupported encoder type!");
}
}

View File

@ -60,7 +60,6 @@ public:
static QString AddJobDialog::getFilterStr(const int filterIndex); static QString AddJobDialog::getFilterStr(const int filterIndex);
static QString getFilterLst(void); static QString getFilterLst(void);
static QString getInputFilterLst(void); static QString getInputFilterLst(void);
const AbstractEncoderInfo& getEncoderInfo(const int &encoder);
protected: protected:
OptionsModel *const m_options; OptionsModel *const m_options;

View File

@ -314,6 +314,7 @@ copy /Y "$(QTDIR)\plugins\imageformats\qgif4.dll" "$(TargetDir)\imageformats"
<ClInclude Include="src\checksum.h" /> <ClInclude Include="src\checksum.h" />
<ClInclude Include="src\cli.h" /> <ClInclude Include="src\cli.h" />
<ClInclude Include="src\encoder_abstract.h" /> <ClInclude Include="src\encoder_abstract.h" />
<ClInclude Include="src\encoder_factory.h" />
<ClInclude Include="src\encoder_x264.h" /> <ClInclude Include="src\encoder_x264.h" />
<ClInclude Include="src\encoder_x265.h" /> <ClInclude Include="src\encoder_x265.h" />
<ClInclude Include="src\global.h" /> <ClInclude Include="src\global.h" />
@ -401,6 +402,7 @@ copy /Y "$(QTDIR)\plugins\imageformats\qgif4.dll" "$(TargetDir)\imageformats"
<ClCompile Include="src\checksum.cpp" /> <ClCompile Include="src\checksum.cpp" />
<ClCompile Include="src\cli.cpp" /> <ClCompile Include="src\cli.cpp" />
<ClCompile Include="src\encoder_abstract.cpp" /> <ClCompile Include="src\encoder_abstract.cpp" />
<ClCompile Include="src\encoder_factory.cpp" />
<ClCompile Include="src\encoder_x264.cpp" /> <ClCompile Include="src\encoder_x264.cpp" />
<ClCompile Include="src\encoder_x265.cpp" /> <ClCompile Include="src\encoder_x265.cpp" />
<ClCompile Include="src\ipc.cpp" /> <ClCompile Include="src\ipc.cpp" />

View File

@ -102,6 +102,9 @@
<ClInclude Include="src\source_vapoursynth.h"> <ClInclude Include="src\source_vapoursynth.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="src\encoder_factory.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="src\main.cpp"> <ClCompile Include="src\main.cpp">
@ -251,6 +254,9 @@
<ClCompile Include="tmp\moc\moc_win_about.cpp"> <ClCompile Include="tmp\moc\moc_win_about.cpp">
<Filter>Generated Files</Filter> <Filter>Generated Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\encoder_factory.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<CustomBuild Include="src\win_main.h"> <CustomBuild Include="src\win_main.h">