1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-21 14:02:57 +02:00

Remove some naked new amd delete in: FFmpeg

This commit is contained in:
Paul Licameli
2016-08-01 11:44:49 -04:00
parent 942c62b6f6
commit fd2e36e0c8
7 changed files with 54 additions and 72 deletions

View File

@@ -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;
}