1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-05 23:19:06 +02:00

Use built-in LAME (Windows only)

This commit is contained in:
James Crook 2019-03-26 17:47:41 +00:00
parent 5e0efd1a25
commit a2ee30240c
3 changed files with 93 additions and 0 deletions

View File

@ -818,6 +818,8 @@ public:
/* initialize the library interface */
bool InitLibrary(wxString libpath);
bool InitLibraryInternal();
bool InitLibraryExternal(wxString libpath);
void FreeLibrary();
/* get library info */
@ -847,6 +849,7 @@ public:
bool PutInfoTag(wxFFile & f, wxFileOffset off);
private:
bool mLibIsExternal;
#ifndef DISABLE_DYNAMIC_LOADING_LAME
wxString mLibPath;
@ -912,6 +915,17 @@ private:
MP3Exporter::MP3Exporter()
{
// We could use #defines rather than this variable.
// The idea of the variable is that if we wanted, we could allow
// a dynamic override of the library, e.g. with a newer faster version,
// or to fix CVEs in the underlying librray.
// for now though the 'variable' is a constant.
#ifdef MP3_EXPORT_BUILT_IN
mLibIsExternal = false;
#else
mLibIsExternal = true;
#endif
#ifndef DISABLE_DYNAMIC_LOADING_LAME
mLibraryLoaded = false;
#endif // DISABLE_DYNAMIC_LOADING_LAME
@ -975,6 +989,7 @@ bool MP3Exporter::FindLibrary(wxWindow *parent)
bool MP3Exporter::LoadLibrary(wxWindow *parent, AskUser askuser)
{
if (ValidLibraryLoaded()) {
FreeLibrary();
mLibraryLoaded = false;
@ -984,6 +999,11 @@ bool MP3Exporter::LoadLibrary(wxWindow *parent, AskUser askuser)
mBladeVersion.Empty();
#endif
if( !mLibIsExternal ){
mLibraryLoaded = InitLibraryInternal();
return mLibraryLoaded;
}
// First try loading it from a previously located path
if (!mLibPath.empty()) {
wxLogMessage(wxT("Attempting to load LAME from previously defined path"));
@ -1059,6 +1079,64 @@ void MP3Exporter::SetChannel(int mode)
}
bool MP3Exporter::InitLibrary(wxString libpath)
{
return mLibIsExternal ? InitLibraryExternal(libpath) : InitLibraryInternal();
}
bool MP3Exporter::InitLibraryInternal()
{
wxLogMessage(wxT("Using internal LAME"));
// The global ::lame_something symbols only exist if LAME is built in.
// So we don't reference them unless they are.
#ifdef MP3_EXPORT_BUILT_IN
lame_init = ::lame_init;
get_lame_version = ::get_lame_version;
lame_init_params = ::lame_init_params;
lame_encode_buffer = ::lame_encode_buffer;
lame_encode_buffer_interleaved = ::lame_encode_buffer_interleaved;
lame_encode_flush = ::lame_encode_flush;
lame_close = ::lame_close;
lame_set_in_samplerate = ::lame_set_in_samplerate;
lame_set_out_samplerate = ::lame_set_out_samplerate;
lame_set_num_channels = ::lame_set_num_channels;
lame_set_quality = ::lame_set_quality;
lame_set_brate = ::lame_set_brate;
lame_set_VBR = ::lame_set_VBR;
lame_set_VBR_q = ::lame_set_VBR_q;
lame_set_VBR_min_bitrate_kbps = ::lame_set_VBR_min_bitrate_kbps;
lame_set_mode = ::lame_set_mode;
lame_set_preset = ::lame_set_preset;
lame_set_error_protection = ::lame_set_error_protection;
lame_set_disable_reservoir = ::lame_set_disable_reservoir;
lame_set_padding_type = ::lame_set_padding_type;
lame_set_bWriteVbrTag = ::lame_set_bWriteVbrTag;
// These are optional
//lame_get_lametag_frame = ::lame_get_lametag_frame;
lame_get_lametag_frame = NULL;
lame_mp3_tags_fid = ::lame_mp3_tags_fid;
#if defined(__WXMSW__)
//beWriteInfoTag = ::beWriteInfoTag;
//beVersion = ::beVersion;
beWriteInfoTag = NULL;
beVersion = NULL;
#endif
mGF = lame_init();
if (mGF == NULL) {
return false;
}
#endif
return true;
}
bool MP3Exporter::InitLibraryExternal(wxString libpath)
{
wxLogMessage(wxT("Loading LAME from %s"), libpath);
@ -2179,6 +2257,11 @@ wxString GetMP3Version(wxWindow *parent, bool prompt)
if (exporter.LoadLibrary(parent, prompt ? MP3Exporter::Yes : MP3Exporter::No)) {
#endif // DISABLE_DYNAMIC_LOADING_LAME
versionString = exporter.GetLibraryVersion();
#ifdef MP3_EXPORT_BUILT_IN
versionString += " ";
versionString += _("(Built In)");
#endif
#ifndef DISABLE_DYNAMIC_LOADING_LAME
}
#endif // DISABLE_DYNAMIC_LOADING_LAME

View File

@ -20,6 +20,10 @@
#define MODE_ABR 2
#define MODE_CBR 3
#if defined(__WXMSW__)
#define MP3_EXPORT_BUILT_IN 1
#endif
class ExportPlugin;
class wxString;
class wxWindow;

View File

@ -93,6 +93,9 @@ void LibraryPrefs::PopulateOrExchange(ShuttleGui & S)
mMP3Version = S.AddVariableText(wxT("9.99"),
true,
wxALL | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL);
// Old buttons, not needed now that the lib is built-in.
#ifndef MP3_EXPORT_BUILT_IN
S.AddVariableText(_("MP3 Library:"),
true,
wxALL | wxALIGN_RIGHT | wxALIGN_CENTRE_VERTICAL);
@ -103,6 +106,7 @@ void LibraryPrefs::PopulateOrExchange(ShuttleGui & S)
wxALL | wxALIGN_RIGHT | wxALIGN_CENTRE_VERTICAL);
wxButton *download_button = S.Id(ID_MP3_DOWN_BUTTON).AddButton(_("&Download"),
wxALL | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL);
#ifdef DISABLE_DYNAMIC_LOADING_LAME
locate_button->Enable(FALSE);
download_button->Enable(FALSE);
@ -110,6 +114,8 @@ void LibraryPrefs::PopulateOrExchange(ShuttleGui & S)
(void)locate_button;
(void)download_button;
#endif // DISABLE_DYNAMIC_LOADING_LAME
#endif
}
S.EndTwoColumn();
}