mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-05 22:28:57 +02:00
Remove some naked new amd delete in: FFmpeg
This commit is contained in:
parent
942c62b6f6
commit
fd2e36e0c8
@ -40,44 +40,41 @@ wxString GetFFmpegVersion(wxWindow *parent)
|
||||
|
||||
/** This pointer to the shared object has global scope and is used to track the
|
||||
* singleton object which wraps the FFmpeg codecs */
|
||||
FFmpegLibs *FFmpegLibsInst = NULL;
|
||||
std::unique_ptr<FFmpegLibs> FFmpegLibsPtr{};
|
||||
FFmpegLibs *FFmpegLibsInst()
|
||||
{
|
||||
return FFmpegLibsPtr.get();
|
||||
}
|
||||
|
||||
FFmpegLibs *PickFFmpegLibs()
|
||||
{
|
||||
if (FFmpegLibsInst != NULL)
|
||||
{
|
||||
FFmpegLibsInst->refcount++;
|
||||
return FFmpegLibsInst;
|
||||
}
|
||||
if (FFmpegLibsPtr)
|
||||
FFmpegLibsPtr->refcount++;
|
||||
else
|
||||
{
|
||||
FFmpegLibsInst = new FFmpegLibs();
|
||||
return FFmpegLibsInst;
|
||||
}
|
||||
FFmpegLibsPtr = std::make_unique<FFmpegLibs>();
|
||||
|
||||
return FFmpegLibsPtr.get();
|
||||
}
|
||||
|
||||
void DropFFmpegLibs()
|
||||
{
|
||||
if (FFmpegLibsInst != NULL)
|
||||
if (FFmpegLibsPtr)
|
||||
{
|
||||
FFmpegLibsInst->refcount--;
|
||||
if (FFmpegLibsInst->refcount == 0)
|
||||
{
|
||||
delete FFmpegLibsInst;
|
||||
FFmpegLibsInst = NULL;
|
||||
}
|
||||
FFmpegLibsPtr->refcount--;
|
||||
if (FFmpegLibsPtr->refcount == 0)
|
||||
FFmpegLibsPtr.reset();
|
||||
}
|
||||
}
|
||||
|
||||
bool LoadFFmpeg(bool showerror)
|
||||
{
|
||||
PickFFmpegLibs();
|
||||
if (FFmpegLibsInst->ValidLibsLoaded())
|
||||
if (FFmpegLibsInst()->ValidLibsLoaded())
|
||||
{
|
||||
DropFFmpegLibs();
|
||||
return true;
|
||||
}
|
||||
if (!FFmpegLibsInst->LoadLibs(NULL,showerror))
|
||||
if (!FFmpegLibsInst()->LoadLibs(NULL, showerror))
|
||||
{
|
||||
DropFFmpegLibs();
|
||||
gPrefs->Write(wxT("/FFmpeg/Enabled"), false);
|
||||
@ -116,8 +113,8 @@ wxString GetFFmpegVersion(wxWindow * WXUNUSED(parent))
|
||||
|
||||
wxString versionString = _("FFmpeg library not found");
|
||||
|
||||
if (FFmpegLibsInst->ValidLibsLoaded()) {
|
||||
versionString = FFmpegLibsInst->GetLibraryVersion();
|
||||
if (FFmpegLibsInst()->ValidLibsLoaded()) {
|
||||
versionString = FFmpegLibsInst()->GetLibraryVersion();
|
||||
}
|
||||
|
||||
DropFFmpegLibs();
|
||||
@ -295,7 +292,7 @@ fail:
|
||||
|
||||
FFmpegContext::~FFmpegContext()
|
||||
{
|
||||
if (FFmpegLibsInst->ValidLibsLoaded())
|
||||
if (FFmpegLibsInst()->ValidLibsLoaded())
|
||||
{
|
||||
if (ic_ptr)
|
||||
avformat_close_input(&ic_ptr);
|
||||
@ -304,7 +301,7 @@ FFmpegContext::~FFmpegContext()
|
||||
|
||||
if (pb) {
|
||||
ufile_close(pb);
|
||||
if (FFmpegLibsInst->ValidLibsLoaded())
|
||||
if (FFmpegLibsInst()->ValidLibsLoaded())
|
||||
{
|
||||
av_free(pb->buffer);
|
||||
av_free(pb);
|
||||
@ -581,7 +578,6 @@ FFmpegLibs::FFmpegLibs()
|
||||
{
|
||||
mLibsLoaded = false;
|
||||
refcount = 1;
|
||||
avformat = avcodec = avutil = NULL;
|
||||
if (gPrefs) {
|
||||
mLibAVFormatPath = gPrefs->Read(wxT("/FFmpeg/FFmpegLibPath"), wxT(""));
|
||||
}
|
||||
@ -780,7 +776,7 @@ bool FFmpegLibs::InitLibs(const wxString &libpath_format, bool WXUNUSED(showerr)
|
||||
bool gotError = false;
|
||||
|
||||
// Check for a monolithic avformat
|
||||
avformat = new wxDynamicLibrary();
|
||||
avformat = std::make_unique<wxDynamicLibrary>();
|
||||
wxLogMessage(wxT("Checking for monolithic avformat from '%s'."), nameFull.c_str());
|
||||
gotError = !avformat->Load(nameFull, wxDL_LAZY);
|
||||
|
||||
@ -790,8 +786,8 @@ bool FFmpegLibs::InitLibs(const wxString &libpath_format, bool WXUNUSED(showerr)
|
||||
avcodec_filename = FileNames::PathFromAddr(avformat->GetSymbol(wxT("avcodec_version")));
|
||||
if (avutil_filename.GetFullPath().IsSameAs(nameFull)) {
|
||||
if (avcodec_filename.GetFullPath().IsSameAs(nameFull)) {
|
||||
util = avformat;
|
||||
codec = avformat;
|
||||
util = avformat.get();
|
||||
codec = avformat.get();
|
||||
}
|
||||
}
|
||||
if (!avcodec_filename.FileExists()) {
|
||||
@ -817,13 +813,13 @@ bool FFmpegLibs::InitLibs(const wxString &libpath_format, bool WXUNUSED(showerr)
|
||||
const wxString avutil_filename_full{ avutil_filename.GetFullPath() };
|
||||
|
||||
if (!util) {
|
||||
avutil = util = new wxDynamicLibrary();
|
||||
util = (avutil = std::make_unique<wxDynamicLibrary>()).get();
|
||||
wxLogMessage(wxT("Loading avutil from '%s'."), avutil_filename_full.c_str());
|
||||
util->Load(avutil_filename_full, wxDL_LAZY);
|
||||
}
|
||||
|
||||
if (!codec) {
|
||||
avcodec = codec = new wxDynamicLibrary();
|
||||
codec = (avcodec = std::make_unique<wxDynamicLibrary>()).get();
|
||||
wxLogMessage(wxT("Loading avcodec from '%s'."), avcodec_filename_full.c_str());
|
||||
codec->Load(avcodec_filename_full, wxDL_LAZY);
|
||||
}
|
||||
@ -967,23 +963,10 @@ bool FFmpegLibs::InitLibs(const wxString &libpath_format, bool WXUNUSED(showerr)
|
||||
|
||||
void FFmpegLibs::FreeLibs()
|
||||
{
|
||||
if (avformat != NULL) {
|
||||
delete avformat;
|
||||
avformat = NULL;
|
||||
}
|
||||
|
||||
if (avcodec != NULL) {
|
||||
delete avcodec;
|
||||
avcodec = NULL;
|
||||
}
|
||||
|
||||
if (avutil != NULL) {
|
||||
delete avutil;
|
||||
avutil = NULL;
|
||||
}
|
||||
|
||||
avformat.reset();
|
||||
avcodec.reset();
|
||||
avutil.reset();
|
||||
mLibsLoaded = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -376,9 +376,7 @@ private:
|
||||
wxString mAVUtilVersion;
|
||||
|
||||
///! wx interfaces for dynamic libraries
|
||||
wxDynamicLibrary *avformat;
|
||||
wxDynamicLibrary *avcodec;
|
||||
wxDynamicLibrary *avutil;
|
||||
std::unique_ptr<wxDynamicLibrary> avformat, avcodec, avutil;
|
||||
|
||||
///! true if libraries are loaded, false otherwise
|
||||
bool mLibsLoaded;
|
||||
|
@ -53,13 +53,13 @@ function.
|
||||
|
||||
#if defined(USE_FFMPEG)
|
||||
|
||||
extern FFmpegLibs *FFmpegLibsInst;
|
||||
extern FFmpegLibs *FFmpegLibsInst();
|
||||
|
||||
static bool CheckFFmpegPresence(bool quiet = false)
|
||||
{
|
||||
bool result = true;
|
||||
PickFFmpegLibs();
|
||||
if (!FFmpegLibsInst->ValidLibsLoaded())
|
||||
if (!FFmpegLibsInst()->ValidLibsLoaded())
|
||||
{
|
||||
if (!quiet)
|
||||
{
|
||||
@ -185,14 +185,14 @@ ExportFFmpeg::ExportFFmpeg()
|
||||
mSupportsUTF8 = true;
|
||||
|
||||
PickFFmpegLibs(); // DropFFmpegLibs() call is in ExportFFmpeg destructor
|
||||
int avfver = FFmpegLibsInst->ValidLibsLoaded() ? avformat_version() : 0;
|
||||
int avfver = FFmpegLibsInst()->ValidLibsLoaded() ? avformat_version() : 0;
|
||||
int newfmt;
|
||||
// Adds export types from the export type list
|
||||
for (newfmt = 0; newfmt < FMT_LAST; newfmt++)
|
||||
{
|
||||
wxString shortname(ExportFFmpegOptions::fmts[newfmt].shortname);
|
||||
//Don't hide export types when there's no av-libs, and don't hide FMT_OTHER
|
||||
if (newfmt < FMT_OTHER && FFmpegLibsInst->ValidLibsLoaded())
|
||||
if (newfmt < FMT_OTHER && FFmpegLibsInst()->ValidLibsLoaded())
|
||||
{
|
||||
// Format/Codec support is compiled in?
|
||||
AVOutputFormat *avoformat = av_guess_format(shortname.mb_str(), NULL, NULL);
|
||||
@ -249,8 +249,8 @@ bool ExportFFmpeg::CheckFileName(wxFileName & WXUNUSED(filename), int WXUNUSED(f
|
||||
// Show "Locate FFmpeg" dialog
|
||||
if (!CheckFFmpegPresence(true))
|
||||
{
|
||||
FFmpegLibsInst->FindLibs(NULL);
|
||||
FFmpegLibsInst->FreeLibs();
|
||||
FFmpegLibsInst()->FindLibs(NULL);
|
||||
FFmpegLibsInst()->FreeLibs();
|
||||
return LoadFFmpeg(true);
|
||||
}
|
||||
|
||||
@ -267,9 +267,9 @@ bool ExportFFmpeg::Init(const char *shortname, AudacityProject *project, const T
|
||||
std::unique_ptr<ExportFFmpeg, decltype(deleter)> cleanup{ this, deleter };
|
||||
|
||||
int err;
|
||||
//FFmpegLibsInst->LoadLibs(NULL,true); //Loaded at startup or from Prefs now
|
||||
//FFmpegLibsInst()->LoadLibs(NULL,true); //Loaded at startup or from Prefs now
|
||||
|
||||
if (!FFmpegLibsInst->ValidLibsLoaded())
|
||||
if (!FFmpegLibsInst()->ValidLibsLoaded())
|
||||
return false;
|
||||
|
||||
av_log_set_callback(av_log_wx_callback);
|
||||
|
@ -65,7 +65,7 @@
|
||||
|
||||
#if defined(USE_FFMPEG)
|
||||
|
||||
extern FFmpegLibs *FFmpegLibsInst;
|
||||
extern FFmpegLibs *FFmpegLibsInst();
|
||||
|
||||
/// This construction defines a enumeration of UI element IDs, and a static
|
||||
/// array of their string representations (this way they're always synchronized).
|
||||
@ -455,10 +455,10 @@ void ExportFFmpegCustomOptions::OnOpen(wxCommandEvent & WXUNUSED(evt))
|
||||
{
|
||||
// Show "Locate FFmpeg" dialog
|
||||
PickFFmpegLibs();
|
||||
if (!FFmpegLibsInst->ValidLibsLoaded())
|
||||
if (!FFmpegLibsInst()->ValidLibsLoaded())
|
||||
{
|
||||
FFmpegLibsInst->FindLibs(NULL);
|
||||
FFmpegLibsInst->FreeLibs();
|
||||
FFmpegLibsInst()->FindLibs(NULL);
|
||||
FFmpegLibsInst()->FreeLibs();
|
||||
if (!LoadFFmpeg(true))
|
||||
{
|
||||
return;
|
||||
@ -1309,12 +1309,12 @@ ExportFFmpegOptions::ExportFFmpegOptions(wxWindow *parent)
|
||||
SetName(GetTitle());
|
||||
ShuttleGui S(this, eIsCreatingFromPrefs);
|
||||
PickFFmpegLibs();
|
||||
//FFmpegLibsInst->LoadLibs(NULL,true); //Loaded at startup or from Prefs now
|
||||
//FFmpegLibsInst()->LoadLibs(NULL,true); //Loaded at startup or from Prefs now
|
||||
|
||||
mPresets = new FFmpegPresets();
|
||||
mPresetNames = mPresets->GetPresetList();
|
||||
|
||||
if (FFmpegLibsInst->ValidLibsLoaded())
|
||||
if (FFmpegLibsInst()->ValidLibsLoaded())
|
||||
{
|
||||
FetchFormatList();
|
||||
FetchCodecList();
|
||||
|
@ -162,7 +162,7 @@ static const wxChar *exts[] =
|
||||
#include "../ondemand/ODDecodeFFmpegTask.h"
|
||||
#endif
|
||||
|
||||
extern FFmpegLibs *FFmpegLibsInst;
|
||||
extern FFmpegLibs *FFmpegLibsInst();
|
||||
|
||||
class FFmpegImportFileHandle;
|
||||
|
||||
@ -309,7 +309,7 @@ std::unique_ptr<ImportFileHandle> FFmpegImportPlugin::Open(const wxString &filen
|
||||
//insdead of usual wxMessageBox()
|
||||
bool newsession = false;
|
||||
gPrefs->Read(wxT("/NewImportingSession"), &newsession);
|
||||
if (!FFmpegLibsInst->ValidLibsLoaded())
|
||||
if (!FFmpegLibsInst()->ValidLibsLoaded())
|
||||
{
|
||||
int dontShowDlg;
|
||||
gPrefs->Read(wxT("/FFmpeg/NotFoundDontShow"),&dontShowDlg,0);
|
||||
@ -321,7 +321,7 @@ std::unique_ptr<ImportFileHandle> FFmpegImportPlugin::Open(const wxString &filen
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!FFmpegLibsInst->ValidLibsLoaded())
|
||||
if (!FFmpegLibsInst()->ValidLibsLoaded())
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
@ -352,9 +352,10 @@ FFmpegImportFileHandle::FFmpegImportFileHandle(const wxString & name)
|
||||
|
||||
bool FFmpegImportFileHandle::Init()
|
||||
{
|
||||
//FFmpegLibsInst->LoadLibs(NULL,false); //Loaded at startup or from Prefs now
|
||||
//FFmpegLibsInst()->LoadLibs(NULL,false); //Loaded at startup or from Prefs now
|
||||
|
||||
if (!FFmpegLibsInst->ValidLibsLoaded()) return false;
|
||||
if (!FFmpegLibsInst()->ValidLibsLoaded())
|
||||
return false;
|
||||
|
||||
av_log_set_callback(av_log_wx_callback);
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include "../import/ImportFFmpeg.h"
|
||||
|
||||
|
||||
extern FFmpegLibs *FFmpegLibsInst;
|
||||
extern FFmpegLibs *FFmpegLibsInst();
|
||||
#include "ODDecodeFFmpegTask.h"
|
||||
|
||||
|
||||
|
@ -192,7 +192,7 @@ void LibraryPrefs::SetFFmpegVersionText()
|
||||
void LibraryPrefs::OnFFmpegFindButton(wxCommandEvent & WXUNUSED(event))
|
||||
{
|
||||
#ifdef USE_FFMPEG
|
||||
FFmpegLibs* FFmpegLibsInst = PickFFmpegLibs();
|
||||
FFmpegLibs* FFmpegLibsPtr = PickFFmpegLibs();
|
||||
bool showerrs =
|
||||
#if defined(__WXDEBUG__)
|
||||
true;
|
||||
@ -200,7 +200,7 @@ void LibraryPrefs::OnFFmpegFindButton(wxCommandEvent & WXUNUSED(event))
|
||||
false;
|
||||
#endif
|
||||
|
||||
FFmpegLibsInst->FreeLibs();
|
||||
FFmpegLibsPtr->FreeLibs();
|
||||
// Load the libs ('true' means that all errors will be shown)
|
||||
bool locate = !LoadFFmpeg(showerrs);
|
||||
|
||||
@ -216,8 +216,8 @@ void LibraryPrefs::OnFFmpegFindButton(wxCommandEvent & WXUNUSED(event))
|
||||
|
||||
if (locate) {
|
||||
// Show "Locate FFmpeg" dialog
|
||||
FFmpegLibsInst->FindLibs(this);
|
||||
FFmpegLibsInst->FreeLibs();
|
||||
FFmpegLibsPtr->FindLibs(this);
|
||||
FFmpegLibsPtr->FreeLibs();
|
||||
LoadFFmpeg(showerrs);
|
||||
}
|
||||
SetFFmpegVersionText();
|
||||
|
Loading…
x
Reference in New Issue
Block a user