summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2020-08-20 18:41:17 +0200
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2020-11-06 21:13:32 +0100
commit07604d62ab375e5c4f42bd05704ace608600c478 (patch)
tree2564d760c71b6036cef730097fabf205508bc4ba /rbutil/rbutilqt
parentbb7aa6f3115c83d47851688b3482f3fa1c2ab32f (diff)
downloadrockbox-07604d62ab375e5c4f42bd05704ace608600c478.tar.gz
rockbox-07604d62ab375e5c4f42bd05704ace608600c478.zip
rbutil: Command line fallback on libmp3lame failure.
When loading libmp3lame fails fall back to using the command line lame. Avoids an unresolvable error when trying to create voice / talk files for Archos. Modernize code a bit. Change-Id: I2e8fd5786fda972cb24adbcb9ced531e08093b4f
Diffstat (limited to 'rbutil/rbutilqt')
-rw-r--r--rbutil/rbutilqt/base/encoderbase.cpp12
-rw-r--r--rbutil/rbutilqt/base/encoderlame.cpp16
-rw-r--r--rbutil/rbutilqt/base/encoderlame.h4
3 files changed, 22 insertions, 10 deletions
diff --git a/rbutil/rbutilqt/base/encoderbase.cpp b/rbutil/rbutilqt/base/encoderbase.cpp
index 05ccae3011..90d7292b3a 100644
--- a/rbutil/rbutilqt/base/encoderbase.cpp
+++ b/rbutil/rbutilqt/base/encoderbase.cpp
@@ -23,6 +23,8 @@
23#include "encoderlame.h" 23#include "encoderlame.h"
24#include "encoderexe.h" 24#include "encoderexe.h"
25 25
26#include "Logger.h"
27
26/********************************************************************* 28/*********************************************************************
27* Encoder Base 29* Encoder Base
28**********************************************************************/ 30**********************************************************************/
@@ -58,9 +60,17 @@ EncoderBase* EncoderBase::getEncoder(QObject* parent,QString encoder)
58 { 60 {
59#if defined(Q_OS_MACX) 61#if defined(Q_OS_MACX)
60 /* currently not on OS X */ 62 /* currently not on OS X */
61 enc = new EncoderExe(encoder,parent); 63 enc = new EncoderExe(encoder, parent);
62#else 64#else
63 enc = new EncoderLame(parent); 65 enc = new EncoderLame(parent);
66 if (!enc->configOk())
67 {
68 LOG_WARNING() << "Could not load lame dll, falling back to command "
69 "line lame. This is notably slower.";
70 delete enc;
71 enc = new EncoderExe(encoder, parent);
72
73 }
64#endif 74#endif
65 return enc; 75 return enc;
66 } 76 }
diff --git a/rbutil/rbutilqt/base/encoderlame.cpp b/rbutil/rbutilqt/base/encoderlame.cpp
index ad283ccf9e..1658a7092d 100644
--- a/rbutil/rbutilqt/base/encoderlame.cpp
+++ b/rbutil/rbutilqt/base/encoderlame.cpp
@@ -25,15 +25,19 @@
25/** Resolve a symbol from loaded library. 25/** Resolve a symbol from loaded library.
26 */ 26 */
27#define SYMBOLRESOLVE(symbol, type) \ 27#define SYMBOLRESOLVE(symbol, type) \
28 do { m_##symbol = (type)lib->resolve(#symbol); \ 28 do { m_##symbol = (type)lib.resolve(#symbol); \
29 if(!m_##symbol) return; \ 29 if(!m_##symbol) return; \
30 LOG_INFO() << "Resolved symbol " #symbol; } \ 30 LOG_INFO() << "Resolved symbol " #symbol; } \
31 while(0) 31 while(0)
32 32
33EncoderLame::EncoderLame(QObject *parent) : EncoderBase(parent) 33EncoderLame::EncoderLame(QObject *parent) : EncoderBase(parent),
34 lib("libmp3lame", this), m_symbolsResolved(false)
34{ 35{
35 m_symbolsResolved = false; 36 lib.load();
36 lib = new QLibrary("libmp3lame", this); 37 if (!lib.isLoaded()) {
38 LOG_WARNING() << "Loading mp3lame lib failed:" << lib.errorString();
39 return;
40 }
37 41
38 SYMBOLRESOLVE(get_lame_short_version, const char* (*)()); 42 SYMBOLRESOLVE(get_lame_short_version, const char* (*)());
39 SYMBOLRESOLVE(lame_set_out_samplerate, int (*)(lame_global_flags*, int)); 43 SYMBOLRESOLVE(lame_set_out_samplerate, int (*)(lame_global_flags*, int));
@@ -51,8 +55,6 @@ EncoderLame::EncoderLame(QObject *parent) : EncoderBase(parent)
51 SYMBOLRESOLVE(lame_encode_flush, int (*)(lame_global_flags*, unsigned char*, int)); 55 SYMBOLRESOLVE(lame_encode_flush, int (*)(lame_global_flags*, unsigned char*, int));
52 SYMBOLRESOLVE(lame_close, int (*)(lame_global_flags*)); 56 SYMBOLRESOLVE(lame_close, int (*)(lame_global_flags*));
53 57
54 LOG_INFO() << "libmp3lame loaded:" << lib->isLoaded();
55
56 m_encoderVolume = RbSettings::subValue("lame", RbSettings::EncoderVolume).toDouble(); 58 m_encoderVolume = RbSettings::subValue("lame", RbSettings::EncoderVolume).toDouble();
57 m_encoderQuality = RbSettings::subValue("lame", RbSettings::EncoderQuality).toDouble(); 59 m_encoderQuality = RbSettings::subValue("lame", RbSettings::EncoderQuality).toDouble();
58 m_symbolsResolved = true; 60 m_symbolsResolved = true;
@@ -305,6 +307,6 @@ bool EncoderLame::encode(QString input,QString output)
305 */ 307 */
306bool EncoderLame::configOk() 308bool EncoderLame::configOk()
307{ 309{
308 return (lib->isLoaded() && m_symbolsResolved); 310 return m_symbolsResolved;
309} 311}
310 312
diff --git a/rbutil/rbutilqt/base/encoderlame.h b/rbutil/rbutilqt/base/encoderlame.h
index a8651f0cda..a5f1b2d3f4 100644
--- a/rbutil/rbutilqt/base/encoderlame.h
+++ b/rbutil/rbutilqt/base/encoderlame.h
@@ -34,7 +34,7 @@ class EncoderLame : public EncoderBase
34 34
35 Q_OBJECT 35 Q_OBJECT
36 public: 36 public:
37 EncoderLame(QObject *parent = NULL); 37 EncoderLame(QObject *parent = nullptr);
38 bool encode(QString input,QString output); 38 bool encode(QString input,QString output);
39 bool start(); 39 bool start();
40 bool stop() {return true;} 40 bool stop() {return true;}
@@ -45,7 +45,7 @@ class EncoderLame : public EncoderBase
45 void saveSettings(); 45 void saveSettings();
46 46
47 private: 47 private:
48 QLibrary *lib; 48 QLibrary lib;
49 const char*(*m_get_lame_short_version)(void); 49 const char*(*m_get_lame_short_version)(void);
50 int (*m_lame_set_out_samplerate)(lame_global_flags*, int); 50 int (*m_lame_set_out_samplerate)(lame_global_flags*, int);
51 int (*m_lame_set_in_samplerate)(lame_global_flags*, int); 51 int (*m_lame_set_in_samplerate)(lame_global_flags*, int);