2007-12-14 20:09:44 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 by Dominik Wenger
|
2008-06-30 22:09:45 +00:00
|
|
|
* $Id$
|
2007-12-14 20:09:44 +00:00
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "encoders.h"
|
|
|
|
|
2008-01-29 21:54:43 +00:00
|
|
|
#ifndef CONSOLE
|
|
|
|
#include "encodersgui.h"
|
2008-02-10 18:25:49 +00:00
|
|
|
#include "browsedirtree.h"
|
2008-02-09 18:58:14 +00:00
|
|
|
#else
|
|
|
|
#include "encodersguicli.h"
|
2008-01-29 21:54:43 +00:00
|
|
|
#endif
|
2007-12-14 20:09:44 +00:00
|
|
|
|
2008-02-13 18:11:09 +00:00
|
|
|
|
|
|
|
QMap<QString,QString> EncBase::encoderList;
|
|
|
|
QMap<QString,EncBase*> EncBase::encoderCache;
|
2008-02-06 21:51:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
// initialize list of encoders
|
2008-02-13 18:11:09 +00:00
|
|
|
void EncBase::initEncodernamesList()
|
2007-12-14 20:09:44 +00:00
|
|
|
{
|
|
|
|
encoderList["rbspeex"] = "Rockbox Speex Encoder";
|
|
|
|
encoderList["lame"] = "Lame Mp3 Encoder";
|
|
|
|
}
|
|
|
|
|
2008-02-06 21:51:35 +00:00
|
|
|
|
|
|
|
// get nice name for a specific encoder
|
2008-02-13 18:11:09 +00:00
|
|
|
QString EncBase::getEncoderName(QString encoder)
|
2008-02-06 21:51:35 +00:00
|
|
|
{
|
|
|
|
if(encoderList.isEmpty())
|
|
|
|
initEncodernamesList();
|
|
|
|
return encoderList.value(encoder);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// get a specific encoder object
|
2008-02-13 18:11:09 +00:00
|
|
|
EncBase* EncBase::getEncoder(QString encoder)
|
2007-12-14 20:09:44 +00:00
|
|
|
{
|
|
|
|
// check cache
|
|
|
|
if(encoderCache.contains(encoder))
|
|
|
|
return encoderCache.value(encoder);
|
2008-02-06 21:51:35 +00:00
|
|
|
|
|
|
|
EncBase* enc;
|
2008-02-09 18:58:14 +00:00
|
|
|
if(encoder == "lame")
|
2007-12-14 20:09:44 +00:00
|
|
|
{
|
2008-02-09 18:58:14 +00:00
|
|
|
enc = new EncExes(encoder);
|
2008-02-06 21:51:35 +00:00
|
|
|
encoderCache[encoder] = enc;
|
2007-12-14 20:09:44 +00:00
|
|
|
return enc;
|
|
|
|
}
|
2008-02-09 18:58:14 +00:00
|
|
|
else // rbspeex is default
|
2007-12-14 20:09:44 +00:00
|
|
|
{
|
2008-02-09 18:58:14 +00:00
|
|
|
enc = new EncRbSpeex();
|
2008-02-06 21:51:35 +00:00
|
|
|
encoderCache[encoder] = enc;
|
2007-12-14 20:09:44 +00:00
|
|
|
return enc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-06 21:51:35 +00:00
|
|
|
|
2008-02-13 18:11:09 +00:00
|
|
|
QStringList EncBase::getEncoderList()
|
2007-12-14 20:09:44 +00:00
|
|
|
{
|
2008-02-06 21:51:35 +00:00
|
|
|
if(encoderList.isEmpty())
|
|
|
|
initEncodernamesList();
|
|
|
|
return encoderList.keys();
|
2007-12-14 20:09:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Encoder Base
|
|
|
|
**********************************************************************/
|
2008-02-09 18:58:14 +00:00
|
|
|
EncBase::EncBase(QObject *parent): QObject(parent)
|
2007-12-14 20:09:44 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* GEneral Exe Encoder
|
|
|
|
**********************************************************************/
|
2008-02-09 18:58:14 +00:00
|
|
|
EncExes::EncExes(QString name,QObject *parent) : EncBase(parent)
|
2007-12-14 20:09:44 +00:00
|
|
|
{
|
|
|
|
m_name = name;
|
|
|
|
|
|
|
|
m_TemplateMap["lame"] = "\"%exe\" %options \"%input\" \"%output\"";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EncExes::start()
|
|
|
|
{
|
2008-01-25 00:12:25 +00:00
|
|
|
m_EncExec = settings->encoderPath(m_name);
|
|
|
|
m_EncOpts = settings->encoderOptions(m_name);
|
2007-12-14 20:09:44 +00:00
|
|
|
|
|
|
|
m_EncTemplate = m_TemplateMap.value(m_name);
|
|
|
|
|
|
|
|
QFileInfo enc(m_EncExec);
|
|
|
|
if(enc.exists())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EncExes::encode(QString input,QString output)
|
|
|
|
{
|
|
|
|
//qDebug() << "encoding..";
|
|
|
|
QString execstring = m_EncTemplate;
|
|
|
|
|
|
|
|
execstring.replace("%exe",m_EncExec);
|
|
|
|
execstring.replace("%options",m_EncOpts);
|
|
|
|
execstring.replace("%input",input);
|
|
|
|
execstring.replace("%output",output);
|
|
|
|
qDebug() << execstring;
|
|
|
|
QProcess::execute(execstring);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-01-29 21:54:43 +00:00
|
|
|
void EncExes::showCfg()
|
2007-12-14 20:09:44 +00:00
|
|
|
{
|
2008-02-09 18:58:14 +00:00
|
|
|
#ifndef CONSOLE
|
2008-01-29 21:54:43 +00:00
|
|
|
EncExesGui gui;
|
2008-02-09 18:58:14 +00:00
|
|
|
#else
|
|
|
|
EncExesGuiCli gui;
|
|
|
|
#endif
|
2008-01-29 21:54:43 +00:00
|
|
|
gui.setCfg(settings);
|
|
|
|
gui.showCfg(m_name);
|
2007-12-14 20:09:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool EncExes::configOk()
|
|
|
|
{
|
2008-01-25 00:12:25 +00:00
|
|
|
QString path = settings->encoderPath(m_name);
|
2007-12-14 20:09:44 +00:00
|
|
|
|
|
|
|
if (QFileInfo(path).exists())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* RB SPEEX ENCODER
|
|
|
|
**********************************************************************/
|
2008-02-09 18:58:14 +00:00
|
|
|
EncRbSpeex::EncRbSpeex(QObject *parent) : EncBase(parent)
|
2007-12-14 20:09:44 +00:00
|
|
|
{
|
2008-01-29 21:54:43 +00:00
|
|
|
|
2007-12-14 20:09:44 +00:00
|
|
|
defaultQuality = 8.f;
|
|
|
|
defaultVolume = 1.f;
|
2007-12-15 09:47:34 +00:00
|
|
|
defaultComplexity = 10;
|
2007-12-14 20:09:44 +00:00
|
|
|
defaultBand = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool EncRbSpeex::start()
|
|
|
|
{
|
2008-01-25 00:12:25 +00:00
|
|
|
|
2007-12-14 20:09:44 +00:00
|
|
|
// try to get config from settings
|
2008-01-25 00:12:25 +00:00
|
|
|
quality = settings->encoderQuality("rbspeex");
|
|
|
|
complexity = settings->encoderComplexity("rbspeex");
|
|
|
|
volume = settings->encoderVolume("rbspeex");
|
|
|
|
narrowband = settings->encoderNarrowband("rbspeex");
|
2007-12-14 20:09:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EncRbSpeex::encode(QString input,QString output)
|
|
|
|
{
|
2008-05-27 20:02:25 +00:00
|
|
|
qDebug() << "encoding " << input << " to "<< output;
|
2007-12-14 20:09:44 +00:00
|
|
|
char errstr[512];
|
|
|
|
|
|
|
|
FILE *fin,*fout;
|
2008-02-25 22:02:55 +00:00
|
|
|
if ((fin = fopen(input.toLocal8Bit(), "rb")) == NULL) {
|
2007-12-14 20:09:44 +00:00
|
|
|
qDebug() << "Error: could not open input file\n";
|
|
|
|
return false;
|
|
|
|
}
|
2008-02-25 22:02:55 +00:00
|
|
|
if ((fout = fopen(output.toLocal8Bit(), "wb")) == NULL) {
|
2007-12-14 20:09:44 +00:00
|
|
|
qDebug() << "Error: could not open output file\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ret = encode_file(fin, fout, quality, complexity, narrowband, volume,
|
|
|
|
errstr, sizeof(errstr));
|
|
|
|
fclose(fout);
|
|
|
|
fclose(fin);
|
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
/* Attempt to delete unfinished output */
|
|
|
|
qDebug() << "Error:" << errstr;
|
|
|
|
QFile(output).remove();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EncRbSpeex::showCfg()
|
|
|
|
{
|
2008-02-09 18:58:14 +00:00
|
|
|
#ifndef CONSOLE
|
2008-01-29 21:54:43 +00:00
|
|
|
EncRbSpeexGui gui;
|
2008-02-09 18:58:14 +00:00
|
|
|
#else
|
|
|
|
EncRbSpeexGuiCli gui;
|
|
|
|
#endif
|
2008-01-29 21:54:43 +00:00
|
|
|
gui.setCfg(settings);
|
|
|
|
gui.showCfg(defaultQuality,defaultVolume,defaultComplexity,defaultBand);
|
2007-12-14 20:09:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool EncRbSpeex::configOk()
|
|
|
|
{
|
|
|
|
bool result=true;
|
|
|
|
// check config
|
|
|
|
|
2008-01-25 00:12:25 +00:00
|
|
|
if(settings->encoderVolume("rbspeex") <= 0)
|
2007-12-14 20:09:44 +00:00
|
|
|
result =false;
|
|
|
|
|
2008-01-25 00:12:25 +00:00
|
|
|
if(settings->encoderQuality("rbspeex") <= 0)
|
2007-12-14 20:09:44 +00:00
|
|
|
result =false;
|
|
|
|
|
2008-01-25 00:12:25 +00:00
|
|
|
if(settings->encoderComplexity("rbspeex") <= 0)
|
2007-12-14 20:09:44 +00:00
|
|
|
result =false;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|