From 6644b3881600568eaac76c6467d85abc6b4e7b89 Mon Sep 17 00:00:00 2001 From: lordmulder Date: Wed, 15 Dec 2010 19:57:51 +0100 Subject: [PATCH] FLAC decoding support. --- LameXP.vcproj | 14 ++++- src/Config.h | 2 +- src/Decoder_FLAC.cpp | 127 +++++++++++++++++++++++++++++++++++++++ src/Decoder_FLAC.h | 37 ++++++++++++ src/Dialog_About.cpp | 6 +- src/Global.cpp | 11 ++-- src/Registry_Decoder.cpp | 2 + 7 files changed, 189 insertions(+), 10 deletions(-) create mode 100644 src/Decoder_FLAC.cpp create mode 100644 src/Decoder_FLAC.h diff --git a/LameXP.vcproj b/LameXP.vcproj index bd367952..a18e6110 100644 --- a/LameXP.vcproj +++ b/LameXP.vcproj @@ -298,6 +298,10 @@ RelativePath=".\src\Decoder_Abstract.cpp" > + + @@ -482,6 +486,10 @@ /> + + @@ -843,7 +851,7 @@ @@ -853,7 +861,7 @@ @@ -863,7 +871,7 @@ diff --git a/src/Config.h b/src/Config.h index 3024e0a6..cb5cf03e 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 155 +#define VER_LAMEXP_BUILD 156 #define VER_LAMEXP_SUFFIX TechPreview /* diff --git a/src/Decoder_FLAC.cpp b/src/Decoder_FLAC.cpp new file mode 100644 index 00000000..c5297b72 --- /dev/null +++ b/src/Decoder_FLAC.cpp @@ -0,0 +1,127 @@ +/////////////////////////////////////////////////////////////////////////////// +// LameXP - Audio Encoder Front-End +// Copyright (C) 2004-2010 LoRd_MuldeR +// +// 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 "Decoder_FLAC.h" + +#include "Global.h" + +#include +#include +#include + +FLACDecoder::FLACDecoder(void) +: + m_binary(lamexp_lookup_tool("flac.exe")) +{ + if(m_binary.isEmpty()) + { + throw "Error initializing Vorbis decoder. Tool 'flac.exe' is not registred!"; + } +} + +FLACDecoder::~FLACDecoder(void) +{ +} + +bool FLACDecoder::decode(const QString &sourceFile, const QString &outputFile, volatile bool *abortFlag) +{ + QProcess process; + QStringList args; + + args << "-d" << "-F" << "-f"; + args << "-o" << QDir::toNativeSeparators(outputFile); + args << QDir::toNativeSeparators(sourceFile); + + if(!startProcess(process, m_binary, args)) + { + return false; + } + + bool bTimeout = false; + bool bAborted = false; + + QRegExp regExp("\\s(\\d+)% complete"); + + while(process.state() != QProcess::NotRunning) + { + if(*abortFlag) + { + process.kill(); + bAborted = true; + emit messageLogged("\nABORTED BY USER !!!"); + break; + } + process.waitForReadyRead(); + if(!process.bytesAvailable() && process.state() == QProcess::Running) + { + process.kill(); + qWarning("FLAC process timed out <-- killing!"); + bTimeout = true; + break; + } + while(process.bytesAvailable() > 0) + { + QByteArray line = process.readLine(); + QString text = QString::fromUtf8(line.constData()).simplified(); + if(regExp.lastIndexIn(text) >= 0) + { + bool ok = false; + int progress = regExp.cap(1).toInt(&ok); + if(ok) emit statusUpdated(progress); + } + else if(!text.isEmpty()) + { + emit messageLogged(text); + } + } + } + + process.waitForFinished(); + if(process.state() != QProcess::NotRunning) + { + process.kill(); + process.waitForFinished(-1); + } + + emit statusUpdated(100); + emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode())); + + if(bTimeout || bAborted || process.exitStatus() != QProcess::NormalExit || QFileInfo(outputFile).size() == 0) + { + return false; + } + + return true; +} + +bool FLACDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) +{ + if(containerType.compare("FLAC", Qt::CaseInsensitive) == 0) + { + if(formatType.compare("FLAC", Qt::CaseInsensitive) == 0) + { + return true; + } + } + + return false; +} + diff --git a/src/Decoder_FLAC.h b/src/Decoder_FLAC.h new file mode 100644 index 00000000..ec111845 --- /dev/null +++ b/src/Decoder_FLAC.h @@ -0,0 +1,37 @@ +/////////////////////////////////////////////////////////////////////////////// +// LameXP - Audio Encoder Front-End +// Copyright (C) 2004-2010 LoRd_MuldeR +// +// 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 "Decoder_Abstract.h" + +class FLACDecoder : public AbstractDecoder +{ +public: + FLACDecoder(void); + ~FLACDecoder(void); + + virtual bool decode(const QString &sourceFile, const QString &outputFile, volatile bool *abortFlag); + static bool isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion); + +private: + const QString m_binary; +}; diff --git a/src/Dialog_About.cpp b/src/Dialog_About.cpp index d338ab46..bea5d8cb 100644 --- a/src/Dialog_About.cpp +++ b/src/Dialog_About.cpp @@ -225,9 +225,13 @@ void AboutDialog::showMoreAbout(void) moreAboutText += "
"; moreAboutText += "
  • Nero AAC reference MPEG-4 Encoder
    "; moreAboutText += "Freeware state-of-the-art HE-AAC encoder with 2-Pass support.
    "; - moreAboutText += "(Available from vendor web-site as free download)
    "; + moreAboutText += "Available from vendor web-site as free download:
    "; moreAboutText += LINK(neroAacUrl); moreAboutText += "
    "; + moreAboutText += "
  • FLAC - Free Lossless Audio Codec"; + moreAboutText += "
    Open and patent-free lossless audio compression.
    "; + moreAboutText += LINK("http://flac.sourceforge.net/"); + moreAboutText += "
    "; moreAboutText += "
  • MediaInfo - Media File Analysis Tool
    "; moreAboutText += "Released under the terms of the GNU Leser General Public License.
    "; moreAboutText += LINK("http://mediainfo.sourceforge.net/"); diff --git a/src/Global.cpp b/src/Global.cpp index a75d33fc..fad493ff 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -831,14 +831,15 @@ QString lamexp_known_folder(lamexp_known_folder_t folder_id) static const GUID GUID_LOCAL_APPDATA_LOW = {0xA520A1A4,0x1780,0x4FF6,{0xBD,0x18,0x16,0x73,0x43,0xC5,0xAF,0x16}}; static const GUID GUID_PROGRAM_FILES = {0x905e63b6,0xc1bf,0x494e,{0xb2,0x9c,0x65,0xb7,0x32,0xd3,0xd2,0x1a}}; + static QLibrary *Kernel32Lib = NULL; static SHGetKnownFolderPathFun SHGetKnownFolderPathPtr = NULL; static SHGetFolderPathFun SHGetFolderPathPtr = NULL; if((!SHGetKnownFolderPathPtr) && (!SHGetFolderPathPtr)) { - QLibrary Kernel32Lib("shell32.dll"); - SHGetKnownFolderPathPtr = (SHGetKnownFolderPathFun) Kernel32Lib.resolve("SHGetKnownFolderPath"); - SHGetFolderPathPtr = (SHGetFolderPathFun) Kernel32Lib.resolve("SHGetFolderPathW"); + if(!Kernel32Lib) Kernel32Lib = new QLibrary("shell32.dll"); + SHGetKnownFolderPathPtr = (SHGetKnownFolderPathFun) Kernel32Lib->resolve("SHGetKnownFolderPath"); + SHGetFolderPathPtr = (SHGetFolderPathFun) Kernel32Lib->resolve("SHGetFolderPathW"); } int folderCSIDL = -1; @@ -866,7 +867,7 @@ QString lamexp_known_folder(lamexp_known_folder_t folder_id) WCHAR *path = NULL; if(SHGetKnownFolderPathPtr(folderGUID, 0x00008000, NULL, &path) == S_OK) { - MessageBoxW(0, path, L"SHGetKnownFolderPathPtr", MB_TOPMOST); + //MessageBoxW(0, path, L"SHGetKnownFolderPath", MB_TOPMOST); QDir folderTemp = QDir(QDir::fromNativeSeparators(QString::fromUtf16(reinterpret_cast(path)))); if(!folderTemp.exists()) { @@ -884,7 +885,7 @@ QString lamexp_known_folder(lamexp_known_folder_t folder_id) WCHAR *path = new WCHAR[4096]; if(SHGetFolderPathPtr(NULL, folderCSIDL, NULL, NULL, path) == S_OK) { - MessageBoxW(0, path, L"SHGetFolderPathPtr", MB_TOPMOST); + //MessageBoxW(0, path, L"SHGetFolderPathW", MB_TOPMOST); QDir folderTemp = QDir(QDir::fromNativeSeparators(QString::fromUtf16(reinterpret_cast(path)))); if(!folderTemp.exists()) { diff --git a/src/Registry_Decoder.cpp b/src/Registry_Decoder.cpp index c815cbda..9b99568e 100644 --- a/src/Registry_Decoder.cpp +++ b/src/Registry_Decoder.cpp @@ -24,6 +24,7 @@ #include "Decoder_AAC.h" #include "Decoder_MP3.h" #include "Decoder_Vorbis.h" +#include "Decoder_FLAC.h" #include "Decoder_WMA.h" #include @@ -35,6 +36,7 @@ AbstractDecoder *DecoderRegistry::lookup(const QString &containerType, const QSt PROBE_DECODER(MP3Decoder); PROBE_DECODER(VorbisDecoder); PROBE_DECODER(AACDecoder); + PROBE_DECODER(FLACDecoder); PROBE_DECODER(WMADecoder); return NULL; }