summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/base/encoderlame.cpp
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2013-11-03 11:08:18 +0100
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2013-11-04 23:32:52 +0100
commit4d2ce949b3b41f8bf0af446fa20205ddd229e579 (patch)
tree01fa19471d9831b296bea5d7049f765e38b30bbb /rbutil/rbutilqt/base/encoderlame.cpp
parent335ec75d60bba82f23fc47b20f9390e0cba9c9c5 (diff)
downloadrockbox-4d2ce949b3b41f8bf0af446fa20205ddd229e579.tar.gz
rockbox-4d2ce949b3b41f8bf0af446fa20205ddd229e579.zip
Use cutelogger for Rockbox Utility internal trace.
Change tracing from qDebug() to use cutelogger, which is available under the LGPL2.1. This allows to automatically add filename and line number to the log, and also provides multiple log levels. Change-Id: I5dbdaf902ba54ea99f07ae10a07467c52fdac910
Diffstat (limited to 'rbutil/rbutilqt/base/encoderlame.cpp')
-rw-r--r--rbutil/rbutilqt/base/encoderlame.cpp45
1 files changed, 23 insertions, 22 deletions
diff --git a/rbutil/rbutilqt/base/encoderlame.cpp b/rbutil/rbutilqt/base/encoderlame.cpp
index c8554194c4..ad283ccf9e 100644
--- a/rbutil/rbutilqt/base/encoderlame.cpp
+++ b/rbutil/rbutilqt/base/encoderlame.cpp
@@ -20,13 +20,14 @@
20#include "encoderlame.h" 20#include "encoderlame.h"
21#include "rbsettings.h" 21#include "rbsettings.h"
22#include "lame/lame.h" 22#include "lame/lame.h"
23#include "Logger.h"
23 24
24/** Resolve a symbol from loaded library. 25/** Resolve a symbol from loaded library.
25 */ 26 */
26#define SYMBOLRESOLVE(symbol, type) \ 27#define SYMBOLRESOLVE(symbol, type) \
27 do { m_##symbol = (type)lib->resolve(#symbol); \ 28 do { m_##symbol = (type)lib->resolve(#symbol); \
28 if(!m_##symbol) return; \ 29 if(!m_##symbol) return; \
29 qDebug() << "[EncoderLame] Resolved symbol " #symbol; } \ 30 LOG_INFO() << "Resolved symbol " #symbol; } \
30 while(0) 31 while(0)
31 32
32EncoderLame::EncoderLame(QObject *parent) : EncoderBase(parent) 33EncoderLame::EncoderLame(QObject *parent) : EncoderBase(parent)
@@ -50,7 +51,7 @@ EncoderLame::EncoderLame(QObject *parent) : EncoderBase(parent)
50 SYMBOLRESOLVE(lame_encode_flush, int (*)(lame_global_flags*, unsigned char*, int)); 51 SYMBOLRESOLVE(lame_encode_flush, int (*)(lame_global_flags*, unsigned char*, int));
51 SYMBOLRESOLVE(lame_close, int (*)(lame_global_flags*)); 52 SYMBOLRESOLVE(lame_close, int (*)(lame_global_flags*));
52 53
53 qDebug() << "[EncoderLame] libmp3lame loaded:" << lib->isLoaded(); 54 LOG_INFO() << "libmp3lame loaded:" << lib->isLoaded();
54 55
55 m_encoderVolume = RbSettings::subValue("lame", RbSettings::EncoderVolume).toDouble(); 56 m_encoderVolume = RbSettings::subValue("lame", RbSettings::EncoderVolume).toDouble();
56 m_encoderQuality = RbSettings::subValue("lame", RbSettings::EncoderQuality).toDouble(); 57 m_encoderQuality = RbSettings::subValue("lame", RbSettings::EncoderQuality).toDouble();
@@ -108,9 +109,9 @@ bool EncoderLame::start()
108 109
109bool EncoderLame::encode(QString input,QString output) 110bool EncoderLame::encode(QString input,QString output)
110{ 111{
111 qDebug() << "[EncoderLame] Encoding" << QDir::cleanPath(input); 112 LOG_INFO() << "Encoding" << QDir::cleanPath(input);
112 if(!m_symbolsResolved) { 113 if(!m_symbolsResolved) {
113 qDebug() << "[EncoderLame] Symbols not successfully resolved, cannot run!"; 114 LOG_ERROR() << "Symbols not successfully resolved, cannot run!";
114 return false; 115 return false;
115 } 116 }
116 117
@@ -144,21 +145,21 @@ bool EncoderLame::encode(QString input,QString output)
144 m_lame_set_bWriteVbrTag(gfp, 0); // disable LAME tag. 145 m_lame_set_bWriteVbrTag(gfp, 0); // disable LAME tag.
145 146
146 if(!fin.open(QIODevice::ReadOnly)) { 147 if(!fin.open(QIODevice::ReadOnly)) {
147 qDebug() << "[EncoderLame] Could not open input file" << input; 148 LOG_ERROR() << "Could not open input file" << input;
148 return false; 149 return false;
149 } 150 }
150 151
151 // read RIFF header 152 // read RIFF header
152 fin.read((char*)header, 12); 153 fin.read((char*)header, 12);
153 if(memcmp("RIFF", header, 4) != 0) { 154 if(memcmp("RIFF", header, 4) != 0) {
154 qDebug() << "[EncoderLame] RIFF header not found!" 155 LOG_ERROR() << "RIFF header not found!"
155 << header[0] << header[1] << header[2] << header[3]; 156 << header[0] << header[1] << header[2] << header[3];
156 fin.close(); 157 fin.close();
157 return false; 158 return false;
158 } 159 }
159 if(memcmp("WAVE", &header[8], 4) != 0) { 160 if(memcmp("WAVE", &header[8], 4) != 0) {
160 qDebug() << "[EncoderLame] WAVE FOURCC not found!" 161 LOG_ERROR() << "WAVE FOURCC not found!"
161 << header[8] << header[9] << header[10] << header[11]; 162 << header[8] << header[9] << header[10] << header[11];
162 fin.close(); 163 fin.close();
163 return false; 164 return false;
164 } 165 }
@@ -178,7 +179,7 @@ bool EncoderLame::encode(QString input,QString output)
178 // input format used should be known. In case some TTS uses a 179 // input format used should be known. In case some TTS uses a
179 // different wave encoding some time this needs to get adjusted. 180 // different wave encoding some time this needs to get adjusted.
180 if(chunkdatalen < 16) { 181 if(chunkdatalen < 16) {
181 qDebug() << "[EncoderLame] fmt chunk too small!"; 182 LOG_ERROR() << "fmt chunk too small!";
182 } 183 }
183 else { 184 else {
184 unsigned char *buf = new unsigned char[chunkdatalen]; 185 unsigned char *buf = new unsigned char[chunkdatalen];
@@ -196,18 +197,18 @@ bool EncoderLame::encode(QString input,QString output)
196 } 197 }
197 else { 198 else {
198 // unknown chunk, just skip its data. 199 // unknown chunk, just skip its data.
199 qDebug() << "[EncoderLame] unknown chunk, skipping." 200 LOG_WARNING() << "unknown chunk, skipping."
200 << chunkheader[0] << chunkheader[1] 201 << chunkheader[0] << chunkheader[1]
201 << chunkheader[2] << chunkheader[3]; 202 << chunkheader[2] << chunkheader[3];
202 fin.seek(fin.pos() + chunkdatalen); 203 fin.seek(fin.pos() + chunkdatalen);
203 } 204 }
204 } while(!fin.atEnd()); 205 } while(!fin.atEnd());
205 206
206 // check format 207 // check format
207 if(channels == 0 || samplerate == 0 || samplesize == 0 || datalength == 0) { 208 if(channels == 0 || samplerate == 0 || samplesize == 0 || datalength == 0) {
208 qDebug() << "[EncoderLame] invalid format. Channels:" << channels 209 LOG_ERROR() << "invalid format. Channels:" << channels
209 << "Samplerate:" << samplerate << "Samplesize:" << samplesize 210 << "Samplerate:" << samplerate << "Samplesize:" << samplesize
210 << "Data chunk length:" << datalength; 211 << "Data chunk length:" << datalength;
211 fin.close(); 212 fin.close();
212 return false; 213 return false;
213 } 214 }
@@ -220,7 +221,7 @@ bool EncoderLame::encode(QString input,QString output)
220 // initialize encoder. 221 // initialize encoder.
221 ret = m_lame_init_params(gfp); 222 ret = m_lame_init_params(gfp);
222 if(ret != 0) { 223 if(ret != 0) {
223 qDebug() << "[EncoderLame] lame_init_params() failed with" << ret; 224 LOG_ERROR() << "lame_init_params() failed with" << ret;
224 fin.close(); 225 fin.close();
225 return false; 226 return false;
226 } 227 }
@@ -230,7 +231,7 @@ bool EncoderLame::encode(QString input,QString output)
230 // bytes the input file has. This wastes space but should be ok. 231 // bytes the input file has. This wastes space but should be ok.
231 // Put an upper limit of 8MiB. 232 // Put an upper limit of 8MiB.
232 if(datalength > 8*1024*1024) { 233 if(datalength > 8*1024*1024) {
233 qDebug() << "[EncoderLame] Input file too large:" << datalength; 234 LOG_ERROR() << "Input file too large:" << datalength;
234 fin.close(); 235 fin.close();
235 return false; 236 return false;
236 } 237 }
@@ -255,7 +256,7 @@ bool EncoderLame::encode(QString input,QString output)
255 } 256 }
256 } 257 }
257 else { 258 else {
258 qDebug() << "[EncoderLame] Unknown samplesize:" << samplesize; 259 LOG_ERROR() << "Unknown samplesize:" << samplesize;
259 fin.close(); 260 fin.close();
260 delete[] mp3buf; 261 delete[] mp3buf;
261 delete[] wavbuf; 262 delete[] wavbuf;
@@ -270,10 +271,10 @@ bool EncoderLame::encode(QString input,QString output)
270 fout.open(QIODevice::ReadWrite); 271 fout.open(QIODevice::ReadWrite);
271 ret = m_lame_encode_buffer(gfp, wavbuf, wavbuf, num_samples, mp3buf, mp3buflen); 272 ret = m_lame_encode_buffer(gfp, wavbuf, wavbuf, num_samples, mp3buf, mp3buflen);
272 if(ret < 0) { 273 if(ret < 0) {
273 qDebug() << "[EncoderLame] Error during encoding:" << ret; 274 LOG_ERROR() << "Error during encoding:" << ret;
274 } 275 }
275 if(fout.write((char*)mp3buf, ret) != (unsigned int)ret) { 276 if(fout.write((char*)mp3buf, ret) != (unsigned int)ret) {
276 qDebug() << "[EncoderLame] Writing mp3 data failed!" << ret; 277 LOG_ERROR() << "Writing mp3 data failed!" << ret;
277 fout.close(); 278 fout.close();
278 delete[] mp3buf; 279 delete[] mp3buf;
279 delete[] wavbuf; 280 delete[] wavbuf;
@@ -282,7 +283,7 @@ bool EncoderLame::encode(QString input,QString output)
282 // flush remaining data 283 // flush remaining data
283 ret = m_lame_encode_flush(gfp, mp3buf, mp3buflen); 284 ret = m_lame_encode_flush(gfp, mp3buf, mp3buflen);
284 if(fout.write((char*)mp3buf, ret) != (unsigned int)ret) { 285 if(fout.write((char*)mp3buf, ret) != (unsigned int)ret) {
285 qDebug() << "[EncoderLame] Writing final mp3 data failed!"; 286 LOG_ERROR() << "Writing final mp3 data failed!";
286 fout.close(); 287 fout.close();
287 delete[] mp3buf; 288 delete[] mp3buf;
288 delete[] wavbuf; 289 delete[] wavbuf;