19# include <wx/buffer.h>
20# include <wx/msw/registry.h>
22# define WIN32_LEAN_AND_MEAN
42 std::vector<HMODULE> handles(256);
46 if (!EnumProcessModules(
47 GetCurrentProcess(), handles.data(),
sizeof(HMODULE) * handles.size(),
53 const int modulesCount = neededMemory /
sizeof(HMODULE);
55 if (modulesCount > handles.size())
57 handles.resize(modulesCount);
59 if (!EnumProcessModules(
60 GetCurrentProcess(), handles.data(),
61 sizeof(HMODULE) * handles.size(), &neededMemory))
67 for (HMODULE handle : handles)
69 void* addr = GetProcAddress(handle,
name);
77 return dlsym(RTLD_DEFAULT,
name);
115#if defined(__WXMSW__)
118#elif defined(__WXMAC__)
129#if defined(__WXMSW__)
130 wxString::Format(
"avformat-%d.dll", version),
131#elif defined(__WXMAC__)
132 wxString::Format(
"libavformat.%d.dylib", version),
133 wxString::Format(
"ffmpeg.%d.64bit.dylib", version),
135 wxString::Format(
"libavformat.so.%d", version)
152 std::shared_ptr<wxDynamicLibrary>
LibraryWithSymbol(
const char* symbol,
bool fromUserPathOnly)
const
167 return LoadLibrary(wxFileNameFromPath(path), fromUserPathOnly);
211 wxLogInfo(
"FFmpeg libraries loaded successfully from: %s",
226 std::shared_ptr<wxDynamicLibrary>
LoadLibrary(
const wxString& libraryName,
bool fromUserPathOnly)
const
228#if defined(__WXMAC__)
233 const wxString fullName = wxFileName(path, libraryName).GetFullPath();
235 if (!wxFileExists(fullName))
238 auto library = std::make_shared<wxDynamicLibrary>(fullName);
240 if (library->IsLoaded())
244 auto library = std::make_shared<wxDynamicLibrary> (libraryName);
246 if (library->IsLoaded())
264 static std::weak_ptr<FFmpegFunctions> weakFunctions;
266 auto functions = weakFunctions.lock();
271 std::shared_ptr<FFmpegFunctions> ffmpeg =
272 std::make_shared<FFmpegFunctions>();
274 const auto supportedVersions =
277#if !defined(__WXMAC__)
281 for (
int version : supportedVersions)
285 if (ffmpeg->mPrivate->Load(*ffmpeg, path, fromUserPathOnly))
287 weakFunctions = ffmpeg;
300 std::vector<wxString> paths;
304 if (!userAVFormatFullPath.empty())
309 if (wxDirExists(userAVFormatFullPath))
310 paths.emplace_back(userAVFormatFullPath);
312 paths.emplace_back(wxPathOnly(userAVFormatFullPath));
315 if (fromUserPathOnly)
318#if defined(__WXMSW__)
319 wxRegKey
reg(
wxT(
"HKEY_LOCAL_MACHINE\\Software\\FFmpeg for Audacity"));
323 reg.QueryValue(
wxT(
"InstallPath"), path);
326 paths.emplace_back(path);
328#elif defined(__WXMAC__)
329 paths.emplace_back(
wxT(
"/Library/Application Support/audacity/libs"));
330 paths.emplace_back(
wxT(
"/usr/local/lib/audacity"));
332 paths.emplace_back(
wxT(
"/usr/local/lib"));
334 paths.emplace_back(
wxT(
"/opt/homebrew/lib"));
342 return mPrivate->FormatFactories.CreateAVIOContextWrapper(*
this);
345std::unique_ptr<AVFormatContextWrapper>
348 return mPrivate->FormatFactories.CreateAVFormatContextWrapper(*
this);
351std::unique_ptr<AVStreamWrapper>
354 return mPrivate->FormatFactories.CreateAVStreamWrapper(*
this, stream, forEncoding);
359 return mPrivate->CodecFactories.CreateAVPacketWrapper(*
this);
364 return mPrivate->UtilFactories.CreateAVFrameWrapper(*
this);
367std::unique_ptr<AVInputFormatWrapper>
371 return mPrivate->FormatFactories.CreateAVInputFormatWrapper(inputFormat);
375 const char* short_name,
const char* filename,
const char* mime_type)
380 return mPrivate->FormatFactories.CreateAVOutputFormatWrapper(outputFormat);
383std::unique_ptr<AVOutputFormatWrapper>
387 return mPrivate->FormatFactories.CreateAVOutputFormatWrapper(outputFormat);
390std::unique_ptr<AVCodecWrapper>
395 if (codec ==
nullptr)
398 return mPrivate->CodecFactories.CreateAVCodecWrapper(codec);
401std::unique_ptr<AVCodecWrapper>
406 if (codec ==
nullptr)
409 return mPrivate->CodecFactories.CreateAVCodecWrapper(codec);
412std::unique_ptr<AVCodecWrapper>
417 if (codec ==
nullptr)
420 return mPrivate->CodecFactories.CreateAVCodecWrapper(codec);
423std::unique_ptr<AVCodecContextWrapper>
426 return mPrivate->CodecFactories.CreateAVCodecContextWrapper(
430std::unique_ptr<AVCodecContextWrapper>
432 std::unique_ptr<AVCodecWrapper> codec)
const
434 if (codec ==
nullptr)
437 return mPrivate->CodecFactories.CreateAVCodecContextWrapperFromCodec(
438 *
this, std::move(codec));
441const std::vector<const AVOutputFormatWrapper*>&
458std::unique_ptr<AVFifoBufferWrapper>
461 return std::make_unique<AVFifoBufferWrapper>(*
this,
size);
471 const AVCodec* currentCodec =
nullptr;
477 mPrivate->CodecFactories.CreateAVCodecWrapper(currentCodec));
482 AVCodec* currentCodec =
nullptr;
484 while ((currentCodec =
av_codec_next(currentCodec)) !=
nullptr)
487 mPrivate->CodecFactories.CreateAVCodecWrapper(currentCodec));
493 for (
const auto& codec :
mCodecs)
510 mPrivate->FormatFactories.CreateAVOutputFormatWrapper(
521 mPrivate->FormatFactories.CreateAVOutputFormatWrapper(currentFormat));
bool LoadAVCodecFunctions(const wxDynamicLibrary &lib, AVCodecFunctions &functions)
bool LoadAVUtilFunctions(const wxDynamicLibrary &lib, AVUtilFunctions &functions)
const TranslatableString name
StringSetting AVFormatPath
void * GetSymbolFromProcess(const char *name)
std::vector< wxString > BuildAVFormatPaths(int version)
std::vector< int > GetSuportedAVFormatVersions() const
static FFmpegAPIResolver & Get()
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined */
Specialization of Setting for strings.
FILES_API FilePath PathFromAddr(void *addr)
BuiltinCommandsModule::Registration< CompareAudioCommand > reg
AVCodec *(* avcodec_find_encoder_by_name)(const char *name)
FFMPegVersion AVCodecVersion
const AVCodec *(* av_codec_iterate)(void **opaque)
AVCodec *(* av_codec_next)(const AVCodec *c)
void(* avcodec_register_all)(void)
AVCodec *(* avcodec_find_encoder)(AVCodecIDFwd id)
AVCodec *(* avcodec_find_decoder)(AVCodecIDFwd id)
AudacityAVCodecID(* GetAudacityCodecID)(AVCodecIDFwd)
AVCodecIDFwd(* GetAVCodecID)(AudacityAVCodecID)
std::unique_ptr< FFmpegLog >(* CreateLogCallbackSetter)(const FFmpegFunctions &)
FFMPegVersion AVUtilVersion
EnvSetter(bool fromUserPathOnly)
static const wxString Separator
static const wxString VariableName
std::shared_ptr< wxDynamicLibrary > LibraryWithSymbol(const char *symbol, bool fromUserPathOnly) const
AVCodecFactories CodecFactories
AVFormatFactories FormatFactories
bool Load(FFmpegFunctions &functions, const wxString &path, bool fromUserPathOnly)
AVUtilFactories UtilFactories
std::shared_ptr< wxDynamicLibrary > AVFormatLibrary
std::shared_ptr< wxDynamicLibrary > AVCodecLibrary
std::unique_ptr< FFmpegLog > FFmpegLogCallbackSetter
std::shared_ptr< wxDynamicLibrary > AVUtilLibrary
std::shared_ptr< wxDynamicLibrary > LoadLibrary(const wxString &libraryName, bool fromUserPathOnly) const
const std::vector< const AVOutputFormatWrapper * > & GetOutputFormats() const
std::unique_ptr< AVInputFormatWrapper > CreateAVInputFormatWrapper(AVInputFormat *inputFormat) const
AudacityAVCodecID(* GetAudacityCodecID)(AVCodecIDFwd)
std::unique_ptr< AVFormatContextWrapper > CreateAVFormatContext() const
std::unique_ptr< AVCodecContextWrapper > CreateAVCodecContextWrapperFromCodec(std::unique_ptr< AVCodecWrapper > codec) const
std::vector< const AVOutputFormatWrapper * > mOutputFormatPointers
static std::vector< wxString > GetSearchPaths(bool fromUserPathOnly)
std::unique_ptr< AVFrameWrapper > CreateAVFrameWrapper() const
std::unique_ptr< AVOutputFormatWrapper > GuessOutputFormat(const char *short_name, const char *filename, const char *mime_type)
std::unique_ptr< AVCodecWrapper > CreateEncoder(AVCodecIDFwd codecID) const
AVCodecIDFwd(* GetAVCodecID)(AudacityAVCodecID)
std::unique_ptr< AVIOContextWrapper > CreateAVIOContext() const
std::vector< const AVCodecWrapper * > mCodecPointers
std::vector< std::unique_ptr< AVCodecWrapper > > mCodecs
void FillOuptutFormatsList()
const std::vector< const AVCodecWrapper * > & GetCodecs() const
std::vector< std::unique_ptr< AVOutputFormatWrapper > > mOutputFormats
std::unique_ptr< AVStreamWrapper > CreateAVStreamWrapper(AVStream *stream, bool forEncoding) const
std::unique_ptr< AVPacketWrapper > CreateAVPacketWrapper() const
std::unique_ptr< AVOutputFormatWrapper > CreateAVOutputFormatWrapper(const AVOutputFormat *outputFormat) const
static std::shared_ptr< FFmpegFunctions > Load(bool fromUserPathOnly=false)
std::unique_ptr< AVCodecContextWrapper > CreateAVCodecContextWrapper(AVCodecContext *context) const
std::unique_ptr< Private > mPrivate
std::unique_ptr< AVCodecWrapper > CreateDecoder(AVCodecIDFwd codecID) const
std::unique_ptr< AVFifoBufferWrapper > CreateFifoBuffer(int size) const