PluginManager: Move reference counting in the MediaPlugin

* Ideally we should support this feature by default to allow
future improvements to the plugins management.
* Fixes the major memory corruption that lead to various
crashes on exit in MediaPlayer.
This commit is contained in:
Dario Casalinuovo 2016-10-31 23:34:48 +01:00
parent 42a3f9477d
commit 8023d6bafd
5 changed files with 15 additions and 9 deletions

View File

@ -13,6 +13,12 @@ class MediaPlugin {
public:
MediaPlugin();
virtual ~MediaPlugin();
private:
// needed for plug-in reference count management
friend class PluginManager;
int32 fRefCount;
};
class Decoder;

View File

@ -27,10 +27,8 @@ private:
virtual void _ReservedStreamer5();
MediaPlugin* fMediaPlugin;
int32 fRefCount;
uint32 fReserved[5];
// needed for plug-in reference count management
friend class PluginManager;
};

View File

@ -8,6 +8,8 @@
MediaPlugin::MediaPlugin()
:
fRefCount(0)
{
}

View File

@ -635,7 +635,7 @@ PluginManager::CreateStreamer(Streamer** streamer, BUrl url, BDataIO** source)
}
(*streamer)->fMediaPlugin = plugin;
(*streamer)->fRefCount += 1;
plugin->fRefCount += 1;
BDataIO* streamSource = NULL;
if ((*streamer)->Sniff(url, &streamSource) == B_OK) {
@ -666,13 +666,14 @@ PluginManager::DestroyStreamer(Streamer* streamer)
// since otherwise we may actually unload the code for the
// destructor...
MediaPlugin* plugin = streamer->fMediaPlugin;
delete streamer;
// Delete the streamer only when every reference is released
if (streamer->fRefCount == 1) {
delete streamer;
// Delete the plugin only when every reference is released
if (plugin->fRefCount == 1) {
plugin->fRefCount = 0;
PutPlugin(plugin);
} else
streamer->fRefCount -= 1;
plugin->fRefCount -= 1;
}
}

View File

@ -8,8 +8,7 @@
Streamer::Streamer()
:
fMediaPlugin(NULL),
fRefCount(0)
fMediaPlugin(NULL)
{
}