Don't try to encode from source files that aren't supported by the encoder. No real support for upstream decoders yet.

This commit is contained in:
LoRd_MuldeR 2010-11-25 18:09:31 +01:00
parent 9947e9c839
commit a29780ef2a
6 changed files with 69 additions and 3 deletions

View File

@ -25,7 +25,7 @@
#define VER_LAMEXP_MAJOR 4
#define VER_LAMEXP_MINOR_HI 0
#define VER_LAMEXP_MINOR_LO 0
#define VER_LAMEXP_BUILD 78
#define VER_LAMEXP_BUILD 79
#define VER_LAMEXP_SUFFIX TechPreview
/*

View File

@ -264,13 +264,13 @@ void ProcessingDialog::doneEncoding(void)
if(m_userAborted)
{
label_progress->setText("Process was aborted by the user!");
label_progress->setText(QString("Process was aborted by the user after %1 files!").arg(QString::number(m_succeededFiles)));
}
else
{
if(m_failedFiles)
{
label_progress->setText(QString("Error: %1 of %2 files failed. See the log for details!").arg(QString::number(m_failedFiles), QString::number(m_failedFiles + m_succeededFiles)));
label_progress->setText(QString("Error: %1 of %2 files failed. Double-click failed items for detailed information!").arg(QString::number(m_failedFiles), QString::number(m_failedFiles + m_succeededFiles)));
}
else
{
@ -282,6 +282,7 @@ void ProcessingDialog::doneEncoding(void)
button_closeDialog->setEnabled(true);
button_AbortProcess->setEnabled(false);
view_log->scrollToBottom();
m_progressIndicator->stop();
progressBar->setValue(100);
}

View File

@ -37,12 +37,16 @@ public:
AbstractEncoder(void);
~AbstractEncoder(void);
//Internal encoder API
virtual bool encode(const AudioFileModel &sourceFile, const QString &outputFile, volatile bool *abortFlag) = 0;
virtual bool isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) = 0;
virtual QString extension(void) = 0;
//Common setter methods
void setBitrate(int bitrate);
void setRCMode(int mode);
//Auxiliary functions
bool startProcess(QProcess &process, const QString &program, const QStringList &args);
static QString commandline2string(const QString &program, const QStringList &arguments);

View File

@ -147,3 +147,29 @@ QString MP3Encoder::extension(void)
{
return "mp3";
}
bool MP3Encoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
{
if(containerType.compare("Wave", Qt::CaseInsensitive) == 0)
{
if(formatType.compare("PCM", Qt::CaseInsensitive) == 0)
{
return true;
}
}
else if(containerType.compare("MPEG Audio", Qt::CaseInsensitive) == 0)
{
if(formatType.compare("MPEG Audio", Qt::CaseInsensitive) == 0)
{
if(formatProfile.compare("Layer 3", Qt::CaseInsensitive) == 0 || formatProfile.compare("Layer 2", Qt::CaseInsensitive) == 0)
{
if(formatVersion.compare("Version 1", Qt::CaseInsensitive) == 0 || formatVersion.compare("Version 2", Qt::CaseInsensitive) == 0)
{
return true;
}
}
}
}
return false;
}

View File

@ -34,6 +34,7 @@ public:
~MP3Encoder(void);
virtual bool encode(const AudioFileModel &sourceFile, const QString &outputFile, volatile bool *abortFlag);
virtual bool isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion);
virtual QString extension(void);
private:

View File

@ -76,6 +76,15 @@ void ProcessThread::run()
if(outFileName.isEmpty())
{
emit processStateChanged(m_jobId, "Not found!", ProgressModel::JobFailed);
emit processStateFinished(m_jobId, outFileName, false);
return;
}
if(!m_encoder->isFormatSupported(m_audioFile.formatContainerType(), m_audioFile.formatContainerProfile(), m_audioFile.formatAudioType(), m_audioFile.formatAudioProfile(), m_audioFile.formatAudioVersion()))
{
handleMessage(QString("The format of this file is NOT supported:\n%1\n\nContainer Format:\t%2\nAudio Format:\t%3").arg(m_audioFile.filePath(), m_audioFile.formatContainerInfo(), m_audioFile.formatAudioCompressInfo()));
emit processStateChanged(m_jobId, "Unsupported!", ProgressModel::JobFailed);
emit processStateFinished(m_jobId, outFileName, false);
return;
}
@ -120,9 +129,21 @@ QString ProcessThread::generateOutFileName(void)
QFileInfo sourceFile(m_audioFile.filePath());
if(!sourceFile.exists() || !sourceFile.isFile())
{
handleMessage(QString("The source audio file could not be found:\n%1").arg(sourceFile.absoluteFilePath()));
return QString();
}
QFile readTest(sourceFile.canonicalFilePath());
if(!readTest.open(QIODevice::ReadOnly))
{
handleMessage(QString("The source audio file could not be opened for reading:\n%1").arg(readTest.fileName()));
return QString();
}
else
{
readTest.close();
}
QString baseName = sourceFile.completeBaseName();
QDir targetDir(m_outputDirectory.isEmpty() ? sourceFile.canonicalPath() : m_outputDirectory);
@ -131,10 +152,23 @@ QString ProcessThread::generateOutFileName(void)
targetDir.mkpath(".");
if(!targetDir.exists())
{
handleMessage(QString("The target output directory doesn't exist and could NOT be created:\n%1").arg(targetDir.absolutePath()));
return QString();
}
}
QFile writeTest(QString("%1/%2").arg(targetDir.canonicalPath(), QUuid::createUuid().toString()));
if(!writeTest.open(QIODevice::ReadWrite))
{
handleMessage(QString("The target output directory is NOT writable:\n%1").arg(targetDir.absolutePath()));
return QString();
}
else
{
writeTest.close();
writeTest.remove();
}
QString outFileName = QString("%1/%2.%3").arg(targetDir.canonicalPath(), baseName, "mp3");
while(QFileInfo(outFileName).exists())
{