1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2007 by Dominik Wenger
10 * $Id: encoders.cpp 15212 2007-10-19 21:49:07Z domonoky $
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
23 #include "encodersgui.h"
24 #include "browsedirtree.h"
26 #include "encodersguicli.h"
30 QMap
<QString
,QString
> EncBase::encoderList
;
31 QMap
<QString
,EncBase
*> EncBase::encoderCache
;
34 // initialize list of encoders
35 void EncBase::initEncodernamesList()
37 encoderList
["rbspeex"] = "Rockbox Speex Encoder";
38 encoderList
["lame"] = "Lame Mp3 Encoder";
42 // get nice name for a specific encoder
43 QString
EncBase::getEncoderName(QString encoder
)
45 if(encoderList
.isEmpty())
46 initEncodernamesList();
47 return encoderList
.value(encoder
);
51 // get a specific encoder object
52 EncBase
* EncBase::getEncoder(QString encoder
)
55 if(encoderCache
.contains(encoder
))
56 return encoderCache
.value(encoder
);
61 enc
= new EncExes(encoder
);
62 encoderCache
[encoder
] = enc
;
65 else // rbspeex is default
67 enc
= new EncRbSpeex();
68 encoderCache
[encoder
] = enc
;
74 QStringList
EncBase::getEncoderList()
76 if(encoderList
.isEmpty())
77 initEncodernamesList();
78 return encoderList
.keys();
82 /*********************************************************************
84 **********************************************************************/
85 EncBase::EncBase(QObject
*parent
): QObject(parent
)
90 /*********************************************************************
92 **********************************************************************/
93 EncExes::EncExes(QString name
,QObject
*parent
) : EncBase(parent
)
97 m_TemplateMap
["lame"] = "\"%exe\" %options \"%input\" \"%output\"";
100 bool EncExes::start()
102 m_EncExec
= settings
->encoderPath(m_name
);
103 m_EncOpts
= settings
->encoderOptions(m_name
);
105 m_EncTemplate
= m_TemplateMap
.value(m_name
);
107 QFileInfo
enc(m_EncExec
);
118 bool EncExes::encode(QString input
,QString output
)
120 //qDebug() << "encoding..";
121 QString execstring
= m_EncTemplate
;
123 execstring
.replace("%exe",m_EncExec
);
124 execstring
.replace("%options",m_EncOpts
);
125 execstring
.replace("%input",input
);
126 execstring
.replace("%output",output
);
127 qDebug() << execstring
;
128 QProcess::execute(execstring
);
134 void EncExes::showCfg()
141 gui
.setCfg(settings
);
145 bool EncExes::configOk()
147 QString path
= settings
->encoderPath(m_name
);
149 if (QFileInfo(path
).exists())
157 /*********************************************************************
159 **********************************************************************/
160 EncRbSpeex::EncRbSpeex(QObject
*parent
) : EncBase(parent
)
163 defaultQuality
= 8.f
;
165 defaultComplexity
= 10;
170 bool EncRbSpeex::start()
173 // try to get config from settings
174 quality
= settings
->encoderQuality("rbspeex");
175 complexity
= settings
->encoderComplexity("rbspeex");
176 volume
= settings
->encoderVolume("rbspeex");
177 narrowband
= settings
->encoderNarrowband("rbspeex");
183 bool EncRbSpeex::encode(QString input
,QString output
)
185 qDebug() << "encoding " << input
<< " to "<< output
;
189 if ((fin
= fopen(input
.toLocal8Bit(), "rb")) == NULL
) {
190 qDebug() << "Error: could not open input file\n";
193 if ((fout
= fopen(output
.toLocal8Bit(), "wb")) == NULL
) {
194 qDebug() << "Error: could not open output file\n";
199 int ret
= encode_file(fin
, fout
, quality
, complexity
, narrowband
, volume
,
200 errstr
, sizeof(errstr
));
205 /* Attempt to delete unfinished output */
206 qDebug() << "Error:" << errstr
;
207 QFile(output
).remove();
214 void EncRbSpeex::showCfg()
219 EncRbSpeexGuiCli gui
;
221 gui
.setCfg(settings
);
222 gui
.showCfg(defaultQuality
,defaultVolume
,defaultComplexity
,defaultBand
);
225 bool EncRbSpeex::configOk()
230 if(settings
->encoderVolume("rbspeex") <= 0)
233 if(settings
->encoderQuality("rbspeex") <= 0)
236 if(settings
->encoderComplexity("rbspeex") <= 0)