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),
134#elif defined(__OpenBSD__)
135 wxString::Format(
"libavformat.so"),
137 wxString::Format(
"libavformat.so.%d", version),
154 std::shared_ptr<wxDynamicLibrary>
LibraryWithSymbol(
const char* symbol,
bool fromUserPathOnly)
const
169 return LoadLibrary(wxFileNameFromPath(path), fromUserPathOnly);
213 wxLogInfo(
"FFmpeg libraries loaded successfully from: %s",
228 std::shared_ptr<wxDynamicLibrary>
LoadLibrary(
const wxString& libraryName,
bool fromUserPathOnly)
const
230#if defined(__WXMAC__)
235 const wxString fullName = wxFileName(path, libraryName).GetFullPath();
237 if (!wxFileExists(fullName))
240 auto library = std::make_shared<wxDynamicLibrary>(fullName);
242 if (library->IsLoaded())
246 auto library = std::make_shared<wxDynamicLibrary> (libraryName);
248 if (library->IsLoaded())
266 static std::weak_ptr<FFmpegFunctions> weakFunctions;
268 auto functions = weakFunctions.lock();
273 std::shared_ptr<FFmpegFunctions> ffmpeg =
274 std::make_shared<FFmpegFunctions>();
276 const auto supportedVersions =
279#if !defined(__WXMAC__)
283 for (
int version : supportedVersions)
287 if (ffmpeg->mPrivate->Load(*ffmpeg, path, fromUserPathOnly))
289 weakFunctions = ffmpeg;
302 std::vector<wxString> paths;
306 if (!userAVFormatFullPath.empty())
311 if (wxDirExists(userAVFormatFullPath))
312 paths.emplace_back(userAVFormatFullPath);
314 paths.emplace_back(wxPathOnly(userAVFormatFullPath));
317 if (fromUserPathOnly)
320#if defined(__WXMSW__)
321 wxRegKey
reg(
wxT(
"HKEY_LOCAL_MACHINE\\Software\\FFmpeg for Audacity"));
325 reg.QueryValue(
wxT(
"InstallPath"), path);
328 paths.emplace_back(path);
330#elif defined(__WXMAC__)
331 paths.emplace_back(
wxT(
"/Library/Application Support/audacity/libs"));
332 paths.emplace_back(
wxT(
"/usr/local/lib/audacity"));
334 paths.emplace_back(
wxT(
"/usr/local/lib"));
336 paths.emplace_back(
wxT(
"/opt/homebrew/lib"));
344 return mPrivate->FormatFactories.CreateAVIOContextWrapper(*
this);
347std::unique_ptr<AVFormatContextWrapper>
350 return mPrivate->FormatFactories.CreateAVFormatContextWrapper(*
this);
353std::unique_ptr<AVStreamWrapper>
356 return mPrivate->FormatFactories.CreateAVStreamWrapper(*
this, stream, forEncoding);
361 return mPrivate->CodecFactories.CreateAVPacketWrapper(*
this);
366 return mPrivate->UtilFactories.CreateAVFrameWrapper(*
this);
369std::unique_ptr<AVInputFormatWrapper>
373 return mPrivate->FormatFactories.CreateAVInputFormatWrapper(inputFormat);
377 const char* short_name,
const char* filename,
const char* mime_type)
382 return mPrivate->FormatFactories.CreateAVOutputFormatWrapper(outputFormat);
385std::unique_ptr<AVChannelLayoutWrapper>
388 return mPrivate->UtilFactories.CreateDefaultChannelLayout(
389 *
this, channelsCount);
392std::unique_ptr<AVChannelLayoutWrapper>
394 uint64_t layout,
int channelsCount)
const
396 return mPrivate->UtilFactories.CreateLegacyChannelLayout(
397 *
this, layout, channelsCount);
400std::unique_ptr<AVChannelLayoutWrapper>
403 return mPrivate->UtilFactories.CreateAVChannelLayout(*
this, layout);
406std::unique_ptr<AVOutputFormatWrapper>
410 return mPrivate->FormatFactories.CreateAVOutputFormatWrapper(outputFormat);
413std::unique_ptr<AVCodecWrapper>
418 if (codec ==
nullptr)
421 return mPrivate->CodecFactories.CreateAVCodecWrapper(codec);
424std::unique_ptr<AVCodecWrapper>
429 if (codec ==
nullptr)
432 return mPrivate->CodecFactories.CreateAVCodecWrapper(codec);
435std::unique_ptr<AVCodecWrapper>
440 if (codec ==
nullptr)
443 return mPrivate->CodecFactories.CreateAVCodecWrapper(codec);
446std::unique_ptr<AVCodecContextWrapper>
449 return mPrivate->CodecFactories.CreateAVCodecContextWrapper(
453std::unique_ptr<AVCodecContextWrapper>
455 std::unique_ptr<AVCodecWrapper> codec)
const
457 if (codec ==
nullptr)
460 return mPrivate->CodecFactories.CreateAVCodecContextWrapperFromCodec(
461 *
this, std::move(codec));
464const std::vector<const AVOutputFormatWrapper*>&
488 const AVCodec* currentCodec =
nullptr;
494 mPrivate->CodecFactories.CreateAVCodecWrapper(currentCodec));
499 AVCodec* currentCodec =
nullptr;
501 while ((currentCodec =
av_codec_next(currentCodec)) !=
nullptr)
504 mPrivate->CodecFactories.CreateAVCodecWrapper(currentCodec));
510 for (
const auto& codec :
mCodecs)
527 mPrivate->FormatFactories.CreateAVOutputFormatWrapper(
538 mPrivate->FormatFactories.CreateAVOutputFormatWrapper(currentFormat));
bool LoadAVCodecFunctions(const wxDynamicLibrary &lib, AVCodecFunctions &functions)
bool LoadAVUtilFunctions(const wxDynamicLibrary &lib, AVUtilFunctions &functions)
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< AVChannelLayoutWrapper > CreateLegacyChannelLayout(uint64_t layout, int channelsCount) const
std::unique_ptr< AVFrameWrapper > CreateAVFrameWrapper() const
std::unique_ptr< AVChannelLayoutWrapper > CreateDefaultChannelLayout(int channelsCount) 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< AVChannelLayoutWrapper > CreateAVChannelLayout(const AVChannelLayout *layout) const
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