From a29780ef2aeb5e5f05b2ae0e0397bdb0c5a39ae7 Mon Sep 17 00:00:00 2001 From: lordmulder Date: Thu, 25 Nov 2010 18:09:31 +0100 Subject: [PATCH] Don't try to encode from source files that aren't supported by the encoder. No real support for upstream decoders yet. --- src/Config.h | 2 +- src/Dialog_Processing.cpp | 5 +++-- src/Encoder_Abstract.h | 4 ++++ src/Encoder_MP3.cpp | 26 ++++++++++++++++++++++++++ src/Encoder_MP3.h | 1 + src/Thread_Process.cpp | 34 ++++++++++++++++++++++++++++++++++ 6 files changed, 69 insertions(+), 3 deletions(-) diff --git a/src/Config.h b/src/Config.h index 82cbc6ef..30ee4c76 100644 --- a/src/Config.h +++ b/src/Config.h @@ -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 /* diff --git a/src/Dialog_Processing.cpp b/src/Dialog_Processing.cpp index 03ea6354..4942449a 100644 --- a/src/Dialog_Processing.cpp +++ b/src/Dialog_Processing.cpp @@ -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); } diff --git a/src/Encoder_Abstract.h b/src/Encoder_Abstract.h index ff0507a8..ec9fcfe9 100644 --- a/src/Encoder_Abstract.h +++ b/src/Encoder_Abstract.h @@ -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); diff --git a/src/Encoder_MP3.cpp b/src/Encoder_MP3.cpp index 962adb43..e00cd395 100644 --- a/src/Encoder_MP3.cpp +++ b/src/Encoder_MP3.cpp @@ -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; +} diff --git a/src/Encoder_MP3.h b/src/Encoder_MP3.h index 7c99cce6..bed3a6e8 100644 --- a/src/Encoder_MP3.h +++ b/src/Encoder_MP3.h @@ -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: diff --git a/src/Thread_Process.cpp b/src/Thread_Process.cpp index 9c903979..ba02d74a 100644 --- a/src/Thread_Process.cpp +++ b/src/Thread_Process.cpp @@ -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()) {